add stripes pipe retraction with void pipes
This commit is contained in:
parent
9d61900d5f
commit
5f3ea0fe0b
2 changed files with 51 additions and 10 deletions
|
@ -432,6 +432,8 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
|
||||||
public void initializeFromItemMetadata(int i) {
|
public void initializeFromItemMetadata(int i) {
|
||||||
if (i >= 1 && i <= 16) {
|
if (i >= 1 && i <= 16) {
|
||||||
setPipeColor((i - 1) & 15);
|
setPipeColor((i - 1) & 15);
|
||||||
|
} else {
|
||||||
|
setPipeColor(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.transport.stripes;
|
package buildcraft.transport.stripes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -62,23 +64,32 @@ public class StripesHandlerPipes implements IStripesHandler {
|
||||||
if (!(pipeTile.pipe.transport instanceof PipeTransportItems)) {
|
if (!(pipeTile.pipe.transport instanceof PipeTransportItems)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks done, start to actually do stuff
|
// 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)) {
|
if (!copyPipeTo(world, pipeTile, x, y, z, player)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeTile.pipe.transport.container.initializeFromItemMetadata(stack.getItemDamage() - 1);
|
pipeTile.initializeFromItemMetadata(stack.getItemDamage());
|
||||||
Pipe<?> newPipe = BlockGenericPipe.createPipe(stack.getItem());
|
Pipe<?> newPipe = BlockGenericPipe.createPipe(stack.getItem());
|
||||||
newPipe.setTile(pipeTile.pipe.container);
|
newPipe.setTile(pipeTile);
|
||||||
pipeTile.pipe.container.pipe = newPipe;
|
pipeTile.pipe = newPipe;
|
||||||
pipeTile.updateEntity(); // Needed so that the tile does computeConnections()
|
pipeTile.updateEntity(); // Needed so that the tile does computeConnections()
|
||||||
|
|
||||||
stack.stackSize--;
|
stack.stackSize--;
|
||||||
if (stack.stackSize > 0) {
|
if (stack.stackSize > 0) {
|
||||||
pipeTile.pipe.container.injectItem(stack, true, direction.getOpposite());
|
pipeTile.injectItem(stack, true, direction.getOpposite());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,4 +101,32 @@ public class StripesHandlerPipes implements IStripesHandler {
|
||||||
}
|
}
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue