refactor the stripes pipe's block placing code into a separate handler
This commit is contained in:
parent
2898da9f59
commit
8c50af6e9a
3 changed files with 45 additions and 18 deletions
|
@ -153,6 +153,7 @@ import buildcraft.transport.stripes.StripesHandlerArrow;
|
||||||
import buildcraft.transport.stripes.StripesHandlerBucket;
|
import buildcraft.transport.stripes.StripesHandlerBucket;
|
||||||
import buildcraft.transport.stripes.StripesHandlerEntityInteract;
|
import buildcraft.transport.stripes.StripesHandlerEntityInteract;
|
||||||
import buildcraft.transport.stripes.StripesHandlerPipes;
|
import buildcraft.transport.stripes.StripesHandlerPipes;
|
||||||
|
import buildcraft.transport.stripes.StripesHandlerPlaceBlock;
|
||||||
import buildcraft.transport.stripes.StripesHandlerRightClick;
|
import buildcraft.transport.stripes.StripesHandlerRightClick;
|
||||||
import buildcraft.transport.stripes.StripesHandlerShears;
|
import buildcraft.transport.stripes.StripesHandlerShears;
|
||||||
|
|
||||||
|
@ -466,6 +467,7 @@ public class BuildCraftTransport extends BuildCraftMod {
|
||||||
PipeManager.registerStripesHandler(new StripesHandlerShears());
|
PipeManager.registerStripesHandler(new StripesHandlerShears());
|
||||||
PipeManager.registerStripesHandler(new StripesHandlerPipes());
|
PipeManager.registerStripesHandler(new StripesHandlerPipes());
|
||||||
PipeManager.registerStripesHandler(new StripesHandlerEntityInteract());
|
PipeManager.registerStripesHandler(new StripesHandlerEntityInteract());
|
||||||
|
PipeManager.registerStripesHandler(new StripesHandlerPlaceBlock());
|
||||||
|
|
||||||
PipeManager.registerPipePluggable(FacadePluggable.class, "facade");
|
PipeManager.registerPipePluggable(FacadePluggable.class, "facade");
|
||||||
PipeManager.registerPipePluggable(GatePluggable.class, "gate");
|
PipeManager.registerPipePluggable(GatePluggable.class, "gate");
|
||||||
|
|
|
@ -108,24 +108,6 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> implements IEnerg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Special, generic actions not handled by the handler.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (stack.getItem() instanceof ItemBlock) {
|
|
||||||
if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) {
|
|
||||||
stack.tryPlaceItemIntoWorld(
|
|
||||||
player,
|
|
||||||
getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f,
|
|
||||||
0.0f);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stack.tryPlaceItemIntoWorld(
|
|
||||||
player,
|
|
||||||
getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f,
|
|
||||||
0.0f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* The BuildCraft API is distributed under the terms of the MIT License.
|
||||||
|
* Please check the contents of the license, which should be located
|
||||||
|
* as "LICENSE.API" in the BuildCraft source code distribution.
|
||||||
|
*/
|
||||||
|
package buildcraft.transport.stripes;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
|
import buildcraft.api.transport.IStripesHandler;
|
||||||
|
import buildcraft.api.transport.IStripesPipe;
|
||||||
|
|
||||||
|
public class StripesHandlerPlaceBlock implements IStripesHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StripesHandlerType getType() {
|
||||||
|
return StripesHandlerType.ITEM_USE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldHandle(ItemStack stack) {
|
||||||
|
return stack.getItem() instanceof ItemBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handle(World world, int x, int y, int z,
|
||||||
|
ForgeDirection direction, ItemStack stack, EntityPlayer player,
|
||||||
|
IStripesPipe pipe) {
|
||||||
|
if (!world.isAirBlock(x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return stack.tryPlaceItemIntoWorld(player, world, x, y, z, 1, 0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue