clean stripes api by canceling the DropItem event if it was handled, and fixed several item destroying bugs

This commit is contained in:
Hea3veN 2015-02-12 22:47:17 -03:00
parent 8c50af6e9a
commit 6ee68a5296
6 changed files with 38 additions and 17 deletions

View file

@ -104,6 +104,7 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> implements IEnerg
&& handler.shouldHandle(stack)) {
if (handler.handle(getWorld(), (int) p.x, (int) p.y, (int) p.z,
event.direction, stack, player, this)) {
event.entity = null;
return;
}
}

View file

@ -27,7 +27,6 @@ public class StripesHandlerArrow implements IStripesHandler {
public boolean handle(World world, int x, int y, int z,
ForgeDirection direction, ItemStack stack, EntityPlayer player,
IStripesPipe pipe) {
stack.stackSize--;
EntityArrow entityArrow = new EntityArrow(world, player, 0);
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;
world.spawnEntityInWorld(entityArrow);
stack.stackSize--;
if (stack.stackSize > 0) {
pipe.sendItem(stack, direction.getOpposite());
}
return true;
}

View file

@ -39,8 +39,11 @@ public class StripesHandlerBucket implements IStripesHandler {
Block underblock = world.getBlock(x, y - 1, z);
if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(world, x, y - 1, z)) {
stack.stackSize = 0;
pipe.sendItem(emptyBucket, direction.getOpposite());
stack.stackSize--;
if(stack.stackSize > 0) {
pipe.sendItem(stack, direction.getOpposite());
}
return true;
} else {
@ -63,14 +66,15 @@ public class StripesHandlerBucket implements IStripesHandler {
if (filledBucket != null) {
world.setBlockToAir(x, y - 1, z);
stack.stackSize = 0;
pipe.sendItem(filledBucket, direction.getOpposite());
stack.stackSize--;
if(stack.stackSize > 0) {
pipe.sendItem(stack, direction.getOpposite());
}
return true;
}
}
return false;
}
return false;
}

View file

@ -74,11 +74,9 @@ public class StripesHandlerPipes implements IStripesHandler {
pipeTile.pipe.container.pipe = newPipe;
pipeTile.updateEntity(); // Needed so that the tile does computeConnections()
ItemStack transportStack = stack.copy();
stack.stackSize = 0;
transportStack.stackSize--;
if (transportStack.stackSize > 0) {
pipeTile.pipe.container.injectItem(transportStack, true, direction.getOpposite());
stack.stackSize--;
if (stack.stackSize > 0) {
pipeTile.pipe.container.injectItem(stack, true, direction.getOpposite());
}
return true;

View file

@ -29,7 +29,8 @@ public class StripesHandlerRightClick implements IStripesHandler {
public boolean handle(World world, int x, int y, int z,
ForgeDirection direction, ItemStack stack, EntityPlayer player,
IStripesPipe pipe) {
stack.getItem().onItemRightClick(stack, world, player);
ItemStack remainingStack = stack.getItem().onItemRightClick(stack, world, player);
pipe.sendItem(remainingStack, direction.getOpposite());
return true;
}

View file

@ -1,12 +1,16 @@
package buildcraft.transport.stripes;
import java.util.List;
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.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.transport.IStripesHandler;
@ -30,12 +34,21 @@ public class StripesHandlerShears implements IStripesHandler {
IStripesPipe pipe) {
Block block = world.getBlock(x, y, z);
if (block instanceof BlockLeavesBase) {
if (block instanceof IShearable) {
IShearable shearableBlock = (IShearable)block;
if(shearableBlock.isShearable(stack, world, x, y, z)) {
world.playSoundEffect(x, y, z, Block.soundTypeGrass.getBreakSound(), 1, 1);
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;
}