Removed part wire

This commit is contained in:
Calclavia 2013-12-22 13:24:41 +08:00
parent a53a40470c
commit b5e4fa9fc0
4 changed files with 23 additions and 650 deletions

View file

@ -17,8 +17,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
{
private IEnergyNetwork network;
public byte currentWireConnections = 0x00;
public byte currentAcceptorConnections = 0x00;
protected Object[] cachedConnections = new Object[6];
/**
* Universal Electricity conductor functions.
@ -40,10 +39,10 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
{
if (this.network == null && tile() instanceof IConductor)
{
setNetwork(EnergyNetworkLoader.getNewNetwork((IConductor) tile()));
setNetwork(EnergyNetworkLoader.getNewNetwork(this));
}
return network;
return this.network;
}
@Override
@ -52,38 +51,12 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
this.network = network;
}
public byte getAllCurrentConnections()
{
return (byte) (currentWireConnections | currentAcceptorConnections);
}
public static boolean connectionMapContainsSide(byte connections, ForgeDirection side)
{
byte tester = (byte) (1 << side.ordinal());
return ((connections & tester) > 0);
}
@Override
public void bind(TileMultipart t)
{
if (tile() != null && network != null)
{
getNetwork().getConnectors().remove(tile());
super.bind(t);
getNetwork().getConnectors().add((IConductor) tile());
}
else
{
super.bind(t);
}
}
@Override
public void preRemove()
{
if (!world().isRemote && tile() instanceof IConductor)
if (!world().isRemote)
{
getNetwork().split((IConductor) tile());
this.getNetwork().split(this);
}
super.preRemove();
@ -95,132 +68,10 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
return false;
}
public boolean canConnectBothSides(TileEntity tile, ForgeDirection side)
{
boolean notPrevented = !isConnectionPrevented(tile, side);
if (tile instanceof IConductor)
{
notPrevented &= ((IConductor) tile).canConnect(side.getOpposite());
}
return notPrevented;
}
/**
* Override if there are ways of preventing a connection
*
* @param tile The TileEntity on the given side
* @param side The side we're checking
* @return Whether we're preventing connections on given side or to given tileEntity
*/
public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side)
{
return false;
}
public byte getPossibleWireConnections()
{
byte connections = 0x00;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if (tileEntity instanceof IConductor && canConnectBothSides(tileEntity, side))
{
connections |= 1 << side.ordinal();
}
}
return connections;
}
public byte getPossibleAcceptorConnections()
{
byte connections = 0x00;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if (CompatibilityModule.canConnect(tileEntity, side.getOpposite()) && canConnectBothSides(tileEntity, side))
{
connections |= 1 << side.ordinal();
}
}
return connections;
}
public void refresh()
{
if (!world().isRemote)
{
byte possibleWireConnections = getPossibleWireConnections();
byte possibleAcceptorConnections = getPossibleAcceptorConnections();
if (possibleWireConnections != this.currentWireConnections)
{
byte or = (byte) (possibleWireConnections | this.currentWireConnections);
// Connections have been removed
if (or != possibleWireConnections)
{
this.getNetwork().split((IConductor) tile());
this.setNetwork(null);
}
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (connectionMapContainsSide(possibleWireConnections, side))
{
TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side);
if (tileEntity instanceof IConductor)
{
this.getNetwork().merge(((IConductor) tileEntity).getNetwork());
}
}
}
this.currentWireConnections = possibleWireConnections;
}
this.currentAcceptorConnections = possibleAcceptorConnections;
this.getNetwork().reconstruct();
// this.sendDescUpdate();
}
tile().markRender();
}
/**
* Should include connections that are in the current connection maps even if those connections
* aren't allowed any more. This is so that networks split correctly.
*/
@Override
public TileEntity[] getConnections()
public Object[] getConnections()
{
TileEntity[] cachedConnections = new TileEntity[6];
for (byte i = 0; i < 6; i++)
{
ForgeDirection side = ForgeDirection.getOrientation(i);
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if (isCurrentlyConnected(side))
{
cachedConnections[i] = tileEntity;
}
}
return cachedConnections;
}
public boolean isCurrentlyConnected(ForgeDirection side)
{
return connectionMapContainsSide(getAllCurrentConnections(), side);
return this.cachedConnections;
}
/**
@ -231,33 +82,15 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
{
Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction);
TileEntity connectTile = connectPos.getTileEntity(world());
return !isConnectionPrevented(connectTile, direction);
if (connectTile instanceof IConductor)
{
return canConnect((IConductor) connectTile);
}
return false;
}
@Override
public void onAdded()
{
super.onAdded();
refresh();
}
public abstract boolean canConnect(IConductor conductor);
@Override
public void onMoved()
{
this.refresh();
}
@Override
public void onChunkLoad()
{
super.onChunkLoad();
refresh();
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
refresh();
}
}

View file

@ -1,254 +0,0 @@
package resonantinduction.wire.part;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.IBlockableConnection;
import resonantinduction.wire.render.RenderPartWire;
import universalelectricity.api.energy.IConductor;
import codechicken.lib.lighting.LazyLightMatrix;
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.RenderUtils;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Translation;
import codechicken.microblock.IHollowConnect;
import codechicken.multipart.IconHitEffects;
import codechicken.multipart.JIconHitEffects;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TSlottedPart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartWire extends PartWireBase implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects
{
/** Client Side Connection Check */
private ForgeDirection testingSide;
public static IndexedCuboid6[] sides = new IndexedCuboid6[7];
public static IndexedCuboid6[] insulatedSides = new IndexedCuboid6[7];
public PartWire()
{
super();
}
public PartWire(int typeID)
{
this(EnumWireMaterial.values()[typeID]);
}
public PartWire(EnumWireMaterial type)
{
super();
material = type;
}
static
{
sides[0] = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64));
sides[1] = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64));
sides[2] = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36));
sides[3] = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000));
sides[4] = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64));
sides[5] = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64));
sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64));
insulatedSides[0] = new IndexedCuboid6(0, new Cuboid6(0.3, 0.0, 0.3, 0.7, 0.3, 0.7));
insulatedSides[1] = new IndexedCuboid6(1, new Cuboid6(0.3, 0.7, 0.3, 0.7, 1.0, 0.7));
insulatedSides[2] = new IndexedCuboid6(2, new Cuboid6(0.3, 0.3, 0.0, 0.7, 0.7, 0.3));
insulatedSides[3] = new IndexedCuboid6(3, new Cuboid6(0.3, 0.3, 0.7, 0.7, 0.7, 1.0));
insulatedSides[4] = new IndexedCuboid6(4, new Cuboid6(0.0, 0.3, 0.3, 0.3, 0.7, 0.7));
insulatedSides[5] = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7));
insulatedSides[6] = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7));
}
@Override
public boolean canConnect(ForgeDirection direction)
{
if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return false;
}
return super.canConnect(direction);
}
@Override
public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side)
{
return (tile instanceof IConductor ? this.canConnectToType((IConductor) tile) : false) || (isBlockedOnSide(side) || tile instanceof IBlockableConnection && ((IBlockableConnection) tile).isBlockedOnSide(side.getOpposite()));
}
@Override
public byte getPossibleWireConnections()
{
if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return 0x00;
}
return super.getPossibleWireConnections();
}
@Override
public byte getPossibleAcceptorConnections()
{
if (world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return 0x00;
}
return super.getPossibleAcceptorConnections();
}
@Override
public String getType()
{
return "resonant_induction_wire";
}
@Override
public boolean occlusionTest(TMultiPart other)
{
return NormalOcclusionTest.apply(this, other);
}
@Override
public Iterable<IndexedCuboid6> getSubParts()
{
Set<IndexedCuboid6> subParts = new HashSet<IndexedCuboid6>();
IndexedCuboid6[] currentSides = isInsulated() ? insulatedSides : sides;
if (tile() != null)
{
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
int ord = side.ordinal();
if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == testingSide)
subParts.add(currentSides[ord]);
}
}
subParts.add(currentSides[6]);
return subParts;
}
@Override
public Iterable<Cuboid6> getCollisionBoxes()
{
Set<Cuboid6> collisionBoxes = new HashSet<Cuboid6>();
collisionBoxes.addAll((Collection<? extends Cuboid6>) getSubParts());
return collisionBoxes;
}
@Override
public float getStrength(MovingObjectPosition hit, EntityPlayer player)
{
return 10F;
}
@Override
@SideOnly(Side.CLIENT)
public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass)
{
if (pass == 0)
{
RenderPartWire.INSTANCE.renderStatic(this);
}
}
@Override
@SideOnly(Side.CLIENT)
public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass)
{
if (getMaterial() == EnumWireMaterial.SILVER)
{
RenderPartWire.INSTANCE.renderShine(this, pos.x, pos.y, pos.z, frame);
}
}
@Override
public void drawBreaking(RenderBlocks renderBlocks)
{
CCRenderState.reset();
RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(renderBlocks.overrideBlockTexture), null);
}
@Override
public Iterable<Cuboid6> getOcclusionBoxes()
{
return getCollisionBoxes();
}
@Override
public int getSlotMask()
{
return PartMap.CENTER.mask;
}
@Override
public int getHollowSize()
{
return isInsulated ? 8 : 6;
}
@Override
public Cuboid6 getBounds()
{
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625);
}
@Override
public Icon getBreakingIcon(Object subPart, int side)
{
return RenderPartWire.breakIcon;
}
@Override
public Icon getBrokenIcon(int side)
{
return RenderPartWire.breakIcon;
}
@Override
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer)
{
IconHitEffects.addHitEffects(this, hit, effectRenderer);
}
@Override
public void addDestroyEffects(EffectRenderer effectRenderer)
{
IconHitEffects.addDestroyEffects(this, effectRenderer, false);
}
@Override
public void onPartChanged(TMultiPart part)
{
refresh();
}
@Override
public boolean isBlockedOnSide(ForgeDirection side)
{
TMultiPart blocker = tile().partMap(side.ordinal());
testingSide = side;
boolean expandable = NormalOcclusionTest.apply(this, blocker);
testingSide = null;
return !expandable;
}
}

View file

@ -30,24 +30,19 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
public EnumWireMaterial material = EnumWireMaterial.COPPER;
public boolean isInsulated = false;
public boolean canConnectToType(Object wire)
public boolean canConnect(IConductor conductor)
{
if (wire instanceof IAdvancedConductor)
if (conductor instanceof IAdvancedConductor)
{
IAdvancedConductor wireTile = (IAdvancedConductor) wire;
IAdvancedConductor wire = (IAdvancedConductor) conductor;
if (wireTile.getMaterial() != getMaterial())
if (wire.getMaterial() == getMaterial())
{
return true;
}
}
if (this.isInsulated() && wire.isInsulated())
{
return this.getInsulationColor() == wire.getInsulationColor();
}
if (isInsulated() && wire instanceof IAdvancedConductor)
{
IAdvancedConductor insulatedTile = (IAdvancedConductor) wire;
if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != getInsulationColor() && getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR))
{
return true;
}
}
@ -102,7 +97,6 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
public void setInsulationColor(int dye)
{
dyeID = dye;
refresh();
tile().notifyPartChange(this);
}
@ -111,7 +105,6 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
{
isInsulated = insulated;
dyeID = DEFAULT_COLOR;
refresh();
tile().notifyPartChange(this);
}
@ -119,7 +112,6 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
{
isInsulated = true;
dyeID = dyeColour;
refresh();
tile().notifyPartChange(this);
}
@ -131,7 +123,6 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
public void setDye(int dye)
{
dyeID = dye;
refresh();
tile().notifyPartChange(this);
}
@ -208,8 +199,6 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
this.setMaterialFromID(packet.readByte());
this.dyeID = packet.readByte();
this.isInsulated = packet.readBoolean();
this.currentWireConnections = packet.readByte();
this.currentAcceptorConnections = packet.readByte();
}
@Override
@ -218,8 +207,6 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo
packet.writeByte((byte) this.getMaterialID());
packet.writeByte((byte) this.dyeID);
packet.writeBoolean(this.isInsulated);
packet.writeByte(this.currentWireConnections);
packet.writeByte(this.currentAcceptorConnections);
}
@Override

View file

@ -1,193 +0,0 @@
package resonantinduction.wire.render;
import java.nio.FloatBuffer;
import java.util.Map;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import resonantinduction.ResonantInduction;
import resonantinduction.render.InvertX;
import resonantinduction.wire.part.PartConductor;
import resonantinduction.wire.part.PartWire;
import universalelectricity.api.vector.Vector3;
import codechicken.lib.colour.Colour;
import codechicken.lib.colour.ColourRGBA;
import codechicken.lib.lighting.LightModel;
import codechicken.lib.render.CCModel;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.ColourMultiplier;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.TextureUtils;
import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Translation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
*
* @author unpairedbracket
*
*/
@SideOnly(Side.CLIENT)
public class RenderPartWire
{
private static final ResourceLocation WIRE_SHINE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "white.png");
public static final Map<String, CCModel> models;
public static final Map<String, CCModel> shinyModels;
public static Icon wireIcon;
public static Icon lainWireIcon;
public static Icon insulationIcon;
public static Icon breakIcon;
public static FloatBuffer location = BufferUtils.createFloatBuffer(4);
public static FloatBuffer specular = BufferUtils.createFloatBuffer(4);
public static FloatBuffer zero = BufferUtils.createFloatBuffer(4);
public static FloatBuffer defaultAmbient = BufferUtils.createFloatBuffer(4);
public static final RenderPartWire INSTANCE = new RenderPartWire();
static
{
models = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wire.obj"), 7, new InvertX());
for (CCModel c : models.values())
{
c.apply(new Translation(.5, 0, .5));
c.computeLighting(LightModel.standardLightModel);
c.shrinkUVs(0.0005);
}
shinyModels = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wireShine.obj"), 7, new InvertX());
for (CCModel c : shinyModels.values())
{
c.apply(new Translation(.5, 0, .5));
c.computeLighting(LightModel.standardLightModel);
c.shrinkUVs(0.0005);
}
loadBuffer(location, 0, 0, 0, 1);
loadBuffer(specular, 1, 1, 1, 1);
loadBuffer(zero, 0, 0, 0, 0);
loadBuffer(defaultAmbient, 0.4F, 0.4F, 0.4F, 1);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero);
GL11.glLight(GL11.GL_LIGHT3, GL11.GL_SPECULAR, specular);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, specular);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, zero);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, zero);
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 128f);
}
public static void loadBuffer(FloatBuffer buffer, float... src)
{
buffer.clear();
buffer.put(src);
buffer.flip();
}
public void renderShine(PartWire wire, double x, double y, double z, float f)
{
if (wire != null)
{
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_LIGHT3);
GL11.glLight(GL11.GL_LIGHT3, GL11.GL_POSITION, location);
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero);
CCRenderState.reset();
CCRenderState.useNormals(true);
CCRenderState.changeTexture(WIRE_SHINE);
CCRenderState.startDrawing(7);
renderSideShine(ForgeDirection.UNKNOWN, wire);
byte renderSides = wire.getAllCurrentConnections();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (PartConductor.connectionMapContainsSide(renderSides, side))
renderSideShine(side, wire);
}
CCRenderState.draw();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_LIGHT3);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, defaultAmbient);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glPopMatrix();
}
}
public static void registerIcons(IconRegister iconReg)
{
wireIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "models/wire");
lainWireIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "models/lainWire");
insulationIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "models/insulation" + (ResonantInduction.LO_FI_INSULATION ? "tiny" : ""));
breakIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "wire");
}
public void renderStatic(PartWire wire)
{
TextureUtils.bindAtlas(0);
CCRenderState.reset();
CCRenderState.useModelColours(true);
CCRenderState.setBrightness(wire.world(), wire.x(), wire.y(), wire.z());
renderSide(ForgeDirection.UNKNOWN, wire);
byte renderSides = wire.getAllCurrentConnections();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (PartConductor.connectionMapContainsSide(renderSides, side))
{
renderSide(side, wire);
}
}
}
public void renderSide(ForgeDirection side, PartWire wire)
{
String name = side.name().toLowerCase();
name = name.equals("unknown") ? "center" : name;
Colour colour = wire.getMaterial().color;
renderPart(wireIcon, models.get(name), wire.x(), wire.y(), wire.z(), colour);
if (wire.isInsulated())
{
Vector3 vecColour = ResonantInduction.DYE_COLORS[wire.dyeID];
Colour insulationColour = new ColourRGBA(vecColour.x, vecColour.y, vecColour.z, 1);
renderPart(insulationIcon, models.get(name + "Insulation"), wire.x(), wire.y(), wire.z(), insulationColour);
}
}
public void renderSideShine(ForgeDirection side, PartWire wire)
{
String name = side.name().toLowerCase();
name = name.equals("unknown") ? "center" : name;
renderPartShine(shinyModels.get(name));
}
public void renderPart(Icon icon, CCModel cc, double x, double y, double z, Colour colour)
{
cc.render(0, cc.verts.length, Rotation.sideOrientation(0, Rotation.rotationTo(0, 2)).at(codechicken.lib.vec.Vector3.center).with(new Translation(x, y, z)), new IconTransformation(icon), new ColourMultiplier(colour));
}
public void renderPartShine(CCModel cc)
{
cc.render(null, 0, 0);
}
}