add stripes pipe retraction with void pipes

This commit is contained in:
Hea3veN 2015-02-20 08:46:32 -03:00
parent 9d61900d5f
commit 5f3ea0fe0b
2 changed files with 51 additions and 10 deletions

View file

@ -432,6 +432,8 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
public void initializeFromItemMetadata(int i) {
if (i >= 1 && i <= 16) {
setPipeColor((i - 1) & 15);
} else {
setPipeColor(-1);
}
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.transport.stripes;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
@ -32,7 +34,7 @@ public class StripesHandlerPipes implements IStripesHandler {
public StripesHandlerType getType() {
return StripesHandlerType.ITEM_USE;
}
@Override
public boolean shouldHandle(ItemStack stack) {
return stack.getItem() instanceof ItemPipe;
@ -50,10 +52,10 @@ public class StripesHandlerPipes implements IStripesHandler {
if (world.getBlock(x, y, z) != Blocks.air) {
return false;
}
Position p = new Position(x, y, z, direction);
p.moveBackwards(1.0d);
TileEntity tile = world.getTileEntity((int) p.x, (int) p.y, (int) p.z);
if (!(tile instanceof TileGenericPipe)) {
return false;
@ -62,23 +64,32 @@ public class StripesHandlerPipes implements IStripesHandler {
if (!(pipeTile.pipe.transport instanceof PipeTransportItems)) {
return false;
}
// Checks done, start to actually do stuff
if (stack.getItem() != BuildCraftTransport.pipeItemsVoid) {
return extendPipe(world, x, y, z, direction, stack, player, pipeTile);
} else {
p.moveBackwards(1.0d);
return retractPipe(world, (int) p.x, (int) p.y, (int) p.z, direction, stack, player, pipeTile);
}
}
private boolean extendPipe(World world, int x, int y, int z, ForgeDirection direction, ItemStack stack, EntityPlayer player,
TileGenericPipe pipeTile) {
if (!copyPipeTo(world, pipeTile, x, y, z, player)) {
return false;
}
pipeTile.pipe.transport.container.initializeFromItemMetadata(stack.getItemDamage() - 1);
pipeTile.initializeFromItemMetadata(stack.getItemDamage());
Pipe<?> newPipe = BlockGenericPipe.createPipe(stack.getItem());
newPipe.setTile(pipeTile.pipe.container);
pipeTile.pipe.container.pipe = newPipe;
newPipe.setTile(pipeTile);
pipeTile.pipe = newPipe;
pipeTile.updateEntity(); // Needed so that the tile does computeConnections()
stack.stackSize--;
if (stack.stackSize > 0) {
pipeTile.pipe.container.injectItem(stack, true, direction.getOpposite());
pipeTile.injectItem(stack, true, direction.getOpposite());
}
return true;
}
@ -90,4 +101,32 @@ public class StripesHandlerPipes implements IStripesHandler {
}
return true;
}
private boolean retractPipe(World world, int x, int y, int z, ForgeDirection direction, ItemStack stack, EntityPlayer player,
TileGenericPipe pipeTile) {
TileEntity prevTile = world.getTileEntity(x, y, z);
if (!(prevTile instanceof TileGenericPipe)) {
return false;
}
TileGenericPipe prevPipeTile = (TileGenericPipe) prevTile;
if (!(prevPipeTile.pipe.transport instanceof PipeTransportItems)) {
return false;
}
int meta = prevPipeTile.getItemMetadata();
ArrayList<ItemStack> removedPipeStacks = world.getBlock(x, y, z).getDrops(world, x, y, z, meta, 0);
prevPipeTile.initializeFromItemMetadata(pipeTile.getItemMetadata());
Pipe<?> newPipe = BlockGenericPipe.createPipe(BuildCraftTransport.pipeItemsStripes);
newPipe.setTile(prevPipeTile);
prevPipeTile.pipe = newPipe;
world.setBlockToAir(pipeTile.x(), pipeTile.y(), pipeTile.z());
prevPipeTile.injectItem(stack, true, direction);
for (ItemStack itemStack : removedPipeStacks) {
prevPipeTile.injectItem(itemStack, true, direction);
}
return true;
}
}