Got side-placing working

This commit is contained in:
Calclavia 2013-12-22 00:14:01 +08:00
parent 635ed87a6e
commit c9831d33db
3 changed files with 30 additions and 29 deletions

View file

@ -9,16 +9,18 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import resonantinduction.TabRI;
import resonantinduction.Utility;
import resonantinduction.wire.part.PartFlatWire;
import resonantinduction.wire.part.PartWire;
import resonantinduction.wire.render.RenderPartWire;
import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.JItemMultiPart;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -37,14 +39,23 @@ public class ItemPartWire extends JItemMultiPart
}
@Override
public TMultiPart newPart(ItemStack arg0, EntityPlayer player, World arg2, BlockCoord arg3, int arg4, Vector3 arg5)
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
{
/*if (player.isSneaking())
{
return new PartWire(getDamage(arg0));
}*/
BlockCoord onPos = pos.copy().offset(side ^ 1);
return new PartFlatWire(getDamage(arg0));
if (!Utility.canPlaceWireOnSide(world, onPos.x, onPos.y, onPos.z, ForgeDirection.getOrientation(side), false))
{
return null;
}
PartFlatWire wire = (PartFlatWire) MultiPartRegistry.createPart("resonant_induction_flat_wire", false);
if (wire != null)
{
wire.preparePlacement(side, itemStack.getItemDamage());
}
return wire;
}
@Override

View file

@ -2,15 +2,14 @@ package resonantinduction.wire.part;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import resonantinduction.base.PartAdvanced;
import resonantinduction.wire.IAdvancedConductor;
import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.energy.EnergyNetworkLoader;
import universalelectricity.api.energy.IConductor;
import universalelectricity.api.energy.IEnergyNetwork;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorHelper;
import calclavia.lib.tile.EnergyStorage;
import codechicken.multipart.TileMultipart;
//@UniversalClass
@ -40,7 +39,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
@Override
public IEnergyNetwork getNetwork()
{
if (this.network == null && tile() instanceof IAdvancedConductor)
if (this.network == null && tile() instanceof IConductor)
{
setNetwork(EnergyNetworkLoader.getNewNetwork((IConductor) tile()));
}
@ -78,7 +77,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
{
getNetwork().getConnectors().remove(tile());
super.bind(t);
getNetwork().getConnectors().add((IAdvancedConductor) tile());
getNetwork().getConnectors().add((IConductor) tile());
}
else
{
@ -89,9 +88,9 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
@Override
public void preRemove()
{
if (!world().isRemote && tile() instanceof IAdvancedConductor)
if (!world().isRemote && tile() instanceof IConductor)
{
getNetwork().split((IAdvancedConductor) tile());
getNetwork().split((IConductor) tile());
}
super.preRemove();
@ -107,9 +106,9 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
{
boolean notPrevented = !isConnectionPrevented(tile, side);
if (tile instanceof IAdvancedConductor)
if (tile instanceof IConductor)
{
notPrevented &= ((IAdvancedConductor) tile).canConnect(side.getOpposite());
notPrevented &= ((IConductor) tile).canConnect(side.getOpposite());
}
return notPrevented;
@ -134,9 +133,8 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
System.out.println("WORK" + tileEntity + " : " + (tileEntity instanceof IAdvancedConductor));
if (tileEntity instanceof IAdvancedConductor && canConnectBothSides(tileEntity, side))
if (tileEntity instanceof IConductor && canConnectBothSides(tileEntity, side))
{
connections |= 1 << side.ordinal();
}
@ -153,7 +151,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side);
if (isValidAcceptor(tileEntity) && canConnectBothSides(tileEntity, side))
if (CompatibilityModule.canConnect(tileEntity, side.getOpposite()) && canConnectBothSides(tileEntity, side))
{
connections |= 1 << side.ordinal();
}
@ -162,14 +160,6 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
return connections;
}
/**
* Override if there are different kinds of acceptor possible
*/
public boolean isValidAcceptor(TileEntity tile)
{
return tile instanceof IAdvancedConductor;
}
public void refresh()
{
if (!world().isRemote)
@ -178,7 +168,6 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
byte possibleWireConnections = getPossibleWireConnections();
byte possibleAcceptorConnections = getPossibleAcceptorConnections();
System.out.println(possibleWireConnections);
if (possibleWireConnections != this.currentWireConnections)
{
@ -196,9 +185,9 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon
{
TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side);
if (tileEntity instanceof IAdvancedConductor)
if (tileEntity instanceof IConductor)
{
getNetwork().merge(((IAdvancedConductor) tileEntity).getNetwork());
getNetwork().merge(((IConductor) tileEntity).getNetwork());
}
}
}

View file

@ -101,6 +101,7 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl
public void preparePlacement(int side, int meta)
{
this.side = (byte) (side ^ 1);
this.material = EnumWireMaterial.values()[meta];
}
/**