Create a utility method to make my life easier

This commit is contained in:
Alex_hawks 2013-12-30 20:52:40 +08:00
parent 22eb0f6404
commit 5b3002cc3f
2 changed files with 18 additions and 13 deletions

View file

@ -8,7 +8,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.IRedstonePart; import codechicken.multipart.IRedstonePart;
import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart; import codechicken.multipart.TMultiPart;
@ -58,12 +57,7 @@ public class PartFlatSwitchWire extends PartFlatWire
if (!w.isRemote) if (!w.isRemote)
{ {
PartFlatWire wire = (PartFlatWire) MultiPartRegistry.createPart("resonant_induction_flat_wire", false); PartFlatWire wire = (PartFlatWire) MultiPartRegistry.createPart("resonant_induction_flat_wire", false);
wire.isInsulated = this.isInsulated; wire.copyFrom(this);
wire.color = this.color;
wire.connections = this.connections;
wire.material = this.material;
wire.side = this.side;
wire.connMap = this.connMap;
if (tile.canReplacePart(this, wire)) if (tile.canReplacePart(this, wire))
{ {

View file

@ -288,12 +288,7 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
if (!w.isRemote) if (!w.isRemote)
{ {
PartFlatSwitchWire wire = (PartFlatSwitchWire) MultiPartRegistry.createPart("resonant_induction_flat_switch_wire", false); PartFlatSwitchWire wire = (PartFlatSwitchWire) MultiPartRegistry.createPart("resonant_induction_flat_switch_wire", false);
wire.isInsulated = this.isInsulated; wire.copyFrom(this);
wire.color = this.color;
wire.connections = this.connections;
wire.material = this.material;
wire.side = this.side;
wire.connMap = this.connMap;
if (tile.canReplacePart(this, wire)) if (tile.canReplacePart(this, wire))
{ {
@ -899,4 +894,20 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
CCRenderState.reset(); CCRenderState.reset();
RenderFlatWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this); RenderFlatWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this);
} }
/**
* Utility method to aid in initializing this or subclasses, usually when you need to change the wire to another type
* @param otherCable the wire to copy from
*/
public void copyFrom(PartFlatWire otherCable)
{
this.isInsulated = otherCable.isInsulated;
this.color = otherCable.color;
this.connections = otherCable.connections;
this.material = otherCable.material;
this.side = otherCable.side;
this.connMap = otherCable.connMap;
this.setNetwork(otherCable.getNetwork());
this.getNetwork().setBufferFor(this, otherCable.getNetwork().getBufferOf(otherCable));
}
} }