clean stripes api by canceling the DropItem event if it was handled, and fixed several item destroying bugs
This commit is contained in:
parent
8c50af6e9a
commit
6ee68a5296
6 changed files with 38 additions and 17 deletions
|
@ -104,6 +104,7 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> implements IEnerg
|
||||||
&& handler.shouldHandle(stack)) {
|
&& handler.shouldHandle(stack)) {
|
||||||
if (handler.handle(getWorld(), (int) p.x, (int) p.y, (int) p.z,
|
if (handler.handle(getWorld(), (int) p.x, (int) p.y, (int) p.z,
|
||||||
event.direction, stack, player, this)) {
|
event.direction, stack, player, this)) {
|
||||||
|
event.entity = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ public class StripesHandlerArrow implements IStripesHandler {
|
||||||
public boolean handle(World world, int x, int y, int z,
|
public boolean handle(World world, int x, int y, int z,
|
||||||
ForgeDirection direction, ItemStack stack, EntityPlayer player,
|
ForgeDirection direction, ItemStack stack, EntityPlayer player,
|
||||||
IStripesPipe pipe) {
|
IStripesPipe pipe) {
|
||||||
stack.stackSize--;
|
|
||||||
|
|
||||||
EntityArrow entityArrow = new EntityArrow(world, player, 0);
|
EntityArrow entityArrow = new EntityArrow(world, player, 0);
|
||||||
entityArrow.setPosition(x + 0.5d, y + 0.5d, z + 0.5d);
|
entityArrow.setPosition(x + 0.5d, y + 0.5d, z + 0.5d);
|
||||||
|
@ -38,6 +37,11 @@ public class StripesHandlerArrow implements IStripesHandler {
|
||||||
entityArrow.motionZ = direction.offsetZ * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
|
entityArrow.motionZ = direction.offsetZ * 1.8d + world.rand.nextGaussian() * 0.007499999832361937D;
|
||||||
world.spawnEntityInWorld(entityArrow);
|
world.spawnEntityInWorld(entityArrow);
|
||||||
|
|
||||||
|
stack.stackSize--;
|
||||||
|
if (stack.stackSize > 0) {
|
||||||
|
pipe.sendItem(stack, direction.getOpposite());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,11 @@ public class StripesHandlerBucket implements IStripesHandler {
|
||||||
Block underblock = world.getBlock(x, y - 1, z);
|
Block underblock = world.getBlock(x, y - 1, z);
|
||||||
|
|
||||||
if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(world, x, y - 1, z)) {
|
if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(world, x, y - 1, z)) {
|
||||||
stack.stackSize = 0;
|
|
||||||
pipe.sendItem(emptyBucket, direction.getOpposite());
|
pipe.sendItem(emptyBucket, direction.getOpposite());
|
||||||
|
stack.stackSize--;
|
||||||
|
if(stack.stackSize > 0) {
|
||||||
|
pipe.sendItem(stack, direction.getOpposite());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,14 +66,15 @@ public class StripesHandlerBucket implements IStripesHandler {
|
||||||
if (filledBucket != null) {
|
if (filledBucket != null) {
|
||||||
world.setBlockToAir(x, y - 1, z);
|
world.setBlockToAir(x, y - 1, z);
|
||||||
|
|
||||||
stack.stackSize = 0;
|
|
||||||
pipe.sendItem(filledBucket, direction.getOpposite());
|
pipe.sendItem(filledBucket, direction.getOpposite());
|
||||||
|
stack.stackSize--;
|
||||||
|
if(stack.stackSize > 0) {
|
||||||
|
pipe.sendItem(stack, direction.getOpposite());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,11 +74,9 @@ public class StripesHandlerPipes implements IStripesHandler {
|
||||||
pipeTile.pipe.container.pipe = newPipe;
|
pipeTile.pipe.container.pipe = newPipe;
|
||||||
pipeTile.updateEntity(); // Needed so that the tile does computeConnections()
|
pipeTile.updateEntity(); // Needed so that the tile does computeConnections()
|
||||||
|
|
||||||
ItemStack transportStack = stack.copy();
|
stack.stackSize--;
|
||||||
stack.stackSize = 0;
|
if (stack.stackSize > 0) {
|
||||||
transportStack.stackSize--;
|
pipeTile.pipe.container.injectItem(stack, true, direction.getOpposite());
|
||||||
if (transportStack.stackSize > 0) {
|
|
||||||
pipeTile.pipe.container.injectItem(transportStack, true, direction.getOpposite());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -29,7 +29,8 @@ public class StripesHandlerRightClick implements IStripesHandler {
|
||||||
public boolean handle(World world, int x, int y, int z,
|
public boolean handle(World world, int x, int y, int z,
|
||||||
ForgeDirection direction, ItemStack stack, EntityPlayer player,
|
ForgeDirection direction, ItemStack stack, EntityPlayer player,
|
||||||
IStripesPipe pipe) {
|
IStripesPipe pipe) {
|
||||||
stack.getItem().onItemRightClick(stack, world, player);
|
ItemStack remainingStack = stack.getItem().onItemRightClick(stack, world, player);
|
||||||
|
pipe.sendItem(remainingStack, direction.getOpposite());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package buildcraft.transport.stripes;
|
package buildcraft.transport.stripes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockLeavesBase;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemShears;
|
import net.minecraft.item.ItemShears;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.IShearable;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
import buildcraft.api.transport.IStripesHandler;
|
import buildcraft.api.transport.IStripesHandler;
|
||||||
|
@ -30,11 +34,20 @@ public class StripesHandlerShears implements IStripesHandler {
|
||||||
IStripesPipe pipe) {
|
IStripesPipe pipe) {
|
||||||
Block block = world.getBlock(x, y, z);
|
Block block = world.getBlock(x, y, z);
|
||||||
|
|
||||||
if (block instanceof BlockLeavesBase) {
|
if (block instanceof IShearable) {
|
||||||
world.playSoundEffect(x, y, z, Block.soundTypeGrass.getBreakSound(), 1, 1);
|
IShearable shearableBlock = (IShearable)block;
|
||||||
world.setBlockToAir(x, y, z);
|
if(shearableBlock.isShearable(stack, world, x, y, z)) {
|
||||||
stack.damageItem(1, player);
|
world.playSoundEffect(x, y, z, Block.soundTypeGrass.getBreakSound(), 1, 1);
|
||||||
return true;
|
List<ItemStack> drops = shearableBlock.onSheared(stack, world, x, y, z,
|
||||||
|
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
|
||||||
|
world.setBlockToAir(x, y, z);
|
||||||
|
stack.damageItem(1, player);
|
||||||
|
pipe.sendItem(stack, direction.getOpposite());
|
||||||
|
for (ItemStack dropStack : drops) {
|
||||||
|
pipe.sendItem(dropStack, direction.getOpposite());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue