added potion support in stripe pipe, close #1675

This commit is contained in:
SpaceToad 2014-05-02 23:22:34 +02:00
parent 4d81b743d0
commit 3b3100e9cf

View file

@ -12,12 +12,14 @@ import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeavesBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
@ -95,29 +97,31 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
Position from = new Position(p);
p.moveForwards(1.0);
ItemStack stack = event.entity.getEntityItem();
if (convertPipe(transport, event.item)) {
BuildCraftTransport.pipeItemsStripes.onItemUse(new ItemStack(
BuildCraftTransport.pipeItemsStripes), CoreProxy
.proxy.getBuildCraftPlayer(getWorld()), getWorld(), (int) p.x,
(int) p.y, (int) p.z, 1, 0, 0, 0
);
} else if (event.entity.getEntityItem().getItem() instanceof ItemBlock) {
} else if (stack.getItem() instanceof ItemBlock) {
if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) {
event.entity.getEntityItem().tryPlaceItemIntoWorld(
stack.tryPlaceItemIntoWorld(
CoreProxy.proxy.getBuildCraftPlayer(getWorld()),
getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f,
0.0f);
}
} else if (event.entity.getEntityItem().getItem() == Items.shears) {
} else if (stack.getItem() == Items.shears) {
Block block = getWorld().getBlock((int) p.x, (int) p.y, (int) p.z);
if (block instanceof BlockLeavesBase) {
getWorld().playSoundEffect((int) p.x, (int) p.y, (int) p.z, Block.soundTypeGrass.getBreakSound(), 1, 1);
getWorld().setBlockToAir((int) p.x, (int) p.y, (int) p.z);
event.entity.getEntityItem().damageItem(1, CoreProxy.proxy.getBuildCraftPlayer(getWorld()));
stack.damageItem(1, CoreProxy.proxy.getBuildCraftPlayer(getWorld()));
}
} else if (event.entity.getEntityItem().getItem() == Items.arrow) {
event.entity.getEntityItem().stackSize--;
} else if (stack.getItem() == Items.arrow) {
stack.stackSize--;
ForgeDirection direction = event.direction;
EntityArrow entityArrow = new EntityArrow(getWorld(), CoreProxy.proxy.getBuildCraftPlayer(getWorld()), 0);
@ -128,8 +132,48 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
direction.offsetY * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D,
direction.offsetZ * 1.8d + getWorld().rand.nextGaussian() * 0.007499999832361937D);
getWorld().spawnEntityInWorld(entityArrow);
} else if (stack.getItem() == Items.potionitem) {
if (ItemPotion.isSplash(stack.getItemDamage())) {
EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer(getWorld(),
(int) p.x, (int) p.y, (int) p.z);
switch (event.direction) {
case DOWN:
player.rotationPitch = 90;
player.rotationYaw = 0;
break;
case UP:
player.rotationPitch = 270;
player.rotationYaw = 0;
break;
case NORTH:
player.rotationPitch = 0;
player.rotationYaw = 180;
break;
case SOUTH:
player.rotationPitch = 0;
player.rotationYaw = 0;
break;
case WEST:
player.rotationPitch = 0;
player.rotationYaw = 90;
break;
case EAST:
player.rotationPitch = 0;
player.rotationYaw = 270;
break;
case UNKNOWN:
break;
}
stack.getItem().onItemRightClick(
stack,
getWorld(),
CoreProxy.proxy.getBuildCraftPlayer(getWorld(),
(int) p.x, (int) p.y, (int) p.z));
}
} else if (getWorld().getBlock((int) p.x, (int) p.y, (int) p.z) == Blocks.air) {
if (event.entity.getEntityItem().getItem() instanceof ItemBucket) {
if (stack.getItem() instanceof ItemBucket) {
Block underblock = getWorld().getBlock((int) p.x, (int) p.y - 1, (int) p.z);
Item newBucket = Items.bucket;
@ -143,7 +187,7 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
boolean rollback = false;
if (((ItemBucket) event.entity.getEntityItem().getItem()).tryPlaceContainedLiquid(getWorld(),
if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(getWorld(),
(int) p.x, (int) p.y - 1, (int) p.z)) {
rollback = true;
} else if (newBucket != Items.bucket) {
@ -152,16 +196,16 @@ public class PipeItemsStripes extends Pipe<PipeTransportItems> {
}
if (rollback) {
event.entity.getEntityItem().stackSize = 0;
stack.stackSize = 0;
rollbackItem(newBucket, 1, event.direction);
}
} else {
event.entity.getEntityItem().tryPlaceItemIntoWorld(
stack.tryPlaceItemIntoWorld(
CoreProxy.proxy.getBuildCraftPlayer(getWorld()),
getWorld(), (int) p.x, (int) p.y - 1, (int) p.z, 1, 0.0f, 0.0f, 0.0f);
}
} else {
event.entity.getEntityItem().tryPlaceItemIntoWorld(
stack.tryPlaceItemIntoWorld(
CoreProxy.proxy.getBuildCraftPlayer(getWorld()),
getWorld(), (int) p.x, (int) p.y, (int) p.z, 1, 0.0f, 0.0f,
0.0f);