Moar Lazor Relay fixez

This commit is contained in:
Ellpeck 2015-10-20 19:35:15 +02:00
parent e13eb9e7c0
commit f045134434
3 changed files with 27 additions and 19 deletions

View file

@ -148,6 +148,8 @@ public class ModelLaserRelay extends ModelBaseAA{
bottom.render(f); bottom.render(f);
laserPillar.render(f); laserPillar.render(f);
laserBase.render(f); laserBase.render(f);
energyBall.render(f);
top.render(f);
covering1.render(f); covering1.render(f);
covering2.render(f); covering2.render(f);
covering3.render(f); covering3.render(f);
@ -156,12 +158,10 @@ public class ModelLaserRelay extends ModelBaseAA{
covering6.render(f); covering6.render(f);
covering7.render(f); covering7.render(f);
covering8.render(f); covering8.render(f);
top.render(f);
covering9.render(f); covering9.render(f);
covering10.render(f); covering10.render(f);
covering11.render(f); covering11.render(f);
covering12.render(f); covering12.render(f);
energyBall.render(f);
} }
@Override @Override

View file

@ -26,6 +26,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ItemLaserWrench extends Item implements IActAddItemOrBlock{ public class ItemLaserWrench extends Item implements IActAddItemOrBlock{
@ -47,19 +48,28 @@ public class ItemLaserWrench extends Item implements IActAddItemOrBlock{
WorldPos savedPos = ItemPhantomConnector.getStoredPosition(stack); WorldPos savedPos = ItemPhantomConnector.getStoredPosition(stack);
if(savedPos.getTileEntity() instanceof TileEntityLaserRelay){ if(savedPos.getTileEntity() instanceof TileEntityLaserRelay){
WorldPos otherPos = new WorldPos(world, x, y, z); WorldPos otherPos = new WorldPos(world, x, y, z);
if(!savedPos.isEqual(otherPos) && savedPos.getWorld() == otherPos.getWorld()){ int distance = (int)Vec3.createVectorHelper(otherPos.getX(), otherPos.getY(), otherPos.getZ()).distanceTo(Vec3.createVectorHelper(savedPos.getX(), savedPos.getY(), savedPos.getZ()));
if(LaserRelayConnectionHandler.getInstance().addConnection(savedPos, otherPos)){ if(distance <= 15){
player.addChatComponentMessage(new ChatComponentText("Connected!")); if(!savedPos.isEqual(otherPos) && savedPos.getWorld() == otherPos.getWorld()){
ItemPhantomConnector.clearStorage(stack); if(LaserRelayConnectionHandler.getInstance().addConnection(savedPos, otherPos)){
player.addChatComponentMessage(new ChatComponentText("Connected!"));
ItemPhantomConnector.clearStorage(stack);
}
else{
player.addChatComponentMessage(new ChatComponentText("Couldn't connect!"));
}
} }
else{ else{
player.addChatComponentMessage(new ChatComponentText("Couldn't connect!")); player.addChatComponentMessage(new ChatComponentText("Can't connect a Laser Relay to itself!"));
} }
} }
else{
player.addChatComponentMessage(new ChatComponentText("Too far away! Distance is "+distance+ "blocks!"));
}
} }
else{ else{
player.addChatComponentMessage(new ChatComponentText("The Laser Relay you were trying to connect to doesn't exist!"));
ItemPhantomConnector.clearStorage(stack); ItemPhantomConnector.clearStorage(stack);
player.addChatComponentMessage(new ChatComponentText("The Laser Relay you were trying to connect to doesn't exist anymore!"));
} }
} }
} }

View file

@ -72,6 +72,7 @@ public class LaserRelayConnectionHandler{
//Both relays have networks //Both relays have networks
else if(firstNetwork != null && secondNetwork != null){ else if(firstNetwork != null && secondNetwork != null){
this.mergeNetworks(firstNetwork, secondNetwork); this.mergeNetworks(firstNetwork, secondNetwork);
firstNetwork.add(new ConnectionPair(firstRelay, secondRelay));
} }
//Only first network exists //Only first network exists
else if(firstNetwork != null){ else if(firstNetwork != null){
@ -82,8 +83,8 @@ public class LaserRelayConnectionHandler{
secondNetwork.add(new ConnectionPair(firstRelay, secondRelay)); secondNetwork.add(new ConnectionPair(firstRelay, secondRelay));
} }
WorldData.makeDirty(); WorldData.makeDirty();
System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString()); //System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString());
System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString()); //System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString());
return true; return true;
} }
@ -99,7 +100,7 @@ public class LaserRelayConnectionHandler{
ConnectionPair next = iterator.next(); ConnectionPair next = iterator.next();
if(next.contains(relay)){ if(next.contains(relay)){
iterator.remove(); iterator.remove();
System.out.println("Removed "+relay.toString()+" from Network "+network.toString()); //System.out.println("Removed "+relay.toString()+" from Network "+network.toString());
} }
} }
@ -122,7 +123,7 @@ public class LaserRelayConnectionHandler{
} }
this.networks.remove(secondNetwork); this.networks.remove(secondNetwork);
WorldData.makeDirty(); WorldData.makeDirty();
System.out.println("Merged Two Networks!"); //System.out.println("Merged Two Networks!");
} }
public int transferEnergyToReceiverInNeed(ArrayList<ConnectionPair> network, int maxTransfer, boolean simulate){ public int transferEnergyToReceiverInNeed(ArrayList<ConnectionPair> network, int maxTransfer, boolean simulate){
@ -137,14 +138,11 @@ public class LaserRelayConnectionHandler{
ForgeDirection side = ForgeDirection.getOrientation(i); ForgeDirection side = ForgeDirection.getOrientation(i);
//Get the TileEntity at the side //Get the TileEntity at the side
TileEntity tile = WorldUtil.getTileEntityFromSide(side, relay.getWorld(), relay.getX(), relay.getY(), relay.getZ()); TileEntity tile = WorldUtil.getTileEntityFromSide(side, relay.getWorld(), relay.getX(), relay.getY(), relay.getZ());
if((tile instanceof TileEntityLaserRelay && this.getNetworkFor(new WorldPos(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord)) != network) || tile instanceof IEnergyReceiver){ if(tile instanceof IEnergyReceiver && !(tile instanceof TileEntityLaserRelay)){
IEnergyReceiver receiver = (IEnergyReceiver)tile; IEnergyReceiver receiver = (IEnergyReceiver)tile;
//Does it need Energy? if(receiver.canConnectEnergy(side.getOpposite())){
if(receiver.getEnergyStored(side.getOpposite()) < receiver.getMaxEnergyStored(side.getOpposite())){ //Transfer the energy
if(receiver.canConnectEnergy(side.getOpposite())){ return ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), maxTransfer, simulate);
//Transfer the energy
return ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), maxTransfer, simulate);
}
} }
} }
} }