add default stripes handler and fix style

This commit is contained in:
Hea3veN 2015-02-12 23:32:57 -03:00
parent 6ee68a5296
commit f6fe4ffcb2
4 changed files with 59 additions and 6 deletions

View file

@ -12,9 +12,7 @@ import java.util.ArrayList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
@ -38,9 +36,13 @@ import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.TravelingItem; import buildcraft.transport.TravelingItem;
import buildcraft.transport.pipes.events.PipeEventItem; import buildcraft.transport.pipes.events.PipeEventItem;
import buildcraft.transport.stripes.StripesHandlerDefault;
import buildcraft.transport.utils.TransportUtils; import buildcraft.transport.utils.TransportUtils;
public class PipeItemsStripes extends Pipe<PipeTransportItems> implements IEnergyHandler, IStripesPipe { public class PipeItemsStripes extends Pipe<PipeTransportItems> implements IEnergyHandler, IStripesPipe {
private IStripesHandler defaultItemsHandler = new StripesHandlerDefault();
public PipeItemsStripes(Item item) { public PipeItemsStripes(Item item) {
super(new PipeTransportItems(), item); super(new PipeTransportItems(), item);
} }
@ -109,6 +111,11 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> implements IEnerg
} }
} }
} }
if(defaultItemsHandler.handle(getWorld(), (int) p.x, (int) p.y, (int) p.z,
event.direction, stack, player, this)) {
event.entity = null;
}
} }
@Override @Override

View file

@ -41,7 +41,7 @@ public class StripesHandlerBucket implements IStripesHandler {
if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(world, x, y - 1, z)) { if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(world, x, y - 1, z)) {
pipe.sendItem(emptyBucket, direction.getOpposite()); pipe.sendItem(emptyBucket, direction.getOpposite());
stack.stackSize--; stack.stackSize--;
if(stack.stackSize > 0) { if (stack.stackSize > 0) {
pipe.sendItem(stack, direction.getOpposite()); pipe.sendItem(stack, direction.getOpposite());
} }
@ -68,7 +68,7 @@ public class StripesHandlerBucket implements IStripesHandler {
pipe.sendItem(filledBucket, direction.getOpposite()); pipe.sendItem(filledBucket, direction.getOpposite());
stack.stackSize--; stack.stackSize--;
if(stack.stackSize > 0) { if (stack.stackSize > 0) {
pipe.sendItem(stack, direction.getOpposite()); pipe.sendItem(stack, direction.getOpposite());
} }

View file

@ -0,0 +1,46 @@
/**
* 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.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.transport.IStripesHandler;
import buildcraft.api.transport.IStripesPipe;
public class StripesHandlerDefault implements IStripesHandler {
@Override
public StripesHandlerType getType() {
return StripesHandlerType.ITEM_USE;
}
@Override
public boolean shouldHandle(ItemStack stack) {
return true;
}
@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;
}
if (!stack.tryPlaceItemIntoWorld(player, world, x, y - 1, z, 1, 0.0f, 0.0f, 0.0f)) {
return false;
}
pipe.sendItem(stack, direction.getOpposite());
return true;
}
}

View file

@ -35,8 +35,8 @@ public class StripesHandlerShears implements IStripesHandler {
Block block = world.getBlock(x, y, z); Block block = world.getBlock(x, y, z);
if (block instanceof IShearable) { if (block instanceof IShearable) {
IShearable shearableBlock = (IShearable)block; IShearable shearableBlock = (IShearable) block;
if(shearableBlock.isShearable(stack, world, x, y, z)) { if (shearableBlock.isShearable(stack, world, x, y, z)) {
world.playSoundEffect(x, y, z, Block.soundTypeGrass.getBreakSound(), 1, 1); world.playSoundEffect(x, y, z, Block.soundTypeGrass.getBreakSound(), 1, 1);
List<ItemStack> drops = shearableBlock.onSheared(stack, world, x, y, z, List<ItemStack> drops = shearableBlock.onSheared(stack, world, x, y, z,
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)); EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));