This commit is contained in:
gigabit101 2016-03-27 19:40:22 +01:00
commit 33c8386324

View file

@ -24,10 +24,13 @@ import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.common.tile.TileMachineBase;
import techreborn.blocks.storage.BlockBatBox;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.items.ItemTR;
import techreborn.lib.ModInfo;
import ic2.api.tile.IWrenchable;
import techreborn.tiles.storage.TileBatBox;
/**
* Created by modmuss50 on 26/02/2016.
@ -43,10 +46,8 @@ public class ItemWrench extends ItemTR implements ITexturedItem
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isAirBlock(pos) || !player.isSneaking())
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (world.isAirBlock(pos))
{
return EnumActionResult.FAIL;
}
@ -55,12 +56,41 @@ public class ItemWrench extends ItemTR implements ITexturedItem
{
return EnumActionResult.FAIL;
}
if (!(tile instanceof IInventory))
if(!player.isSneaking()){
if(tile instanceof TileBatBox){
tile.getWorld().setBlockState(tile.getPos(), tile.getWorld().getBlockState(pos).withProperty(BlockBatBox.FACING, side.getOpposite()));
return EnumActionResult.SUCCESS;
} else
if(tile instanceof TileMachineBase){
if(side != EnumFacing.DOWN && side != EnumFacing.UP){
((TileMachineBase) tile).setFacing(side);
return EnumActionResult.SUCCESS;
}
}
}
return super.onItemUseFirst(stack, player, world, pos, side, hitX, hitY, hitZ, hand);
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isAirBlock(pos))
{
return EnumActionResult.FAIL;
}
TileEntity tile = world.getTileEntity(pos);
if (tile == null)
{
return EnumActionResult.FAIL;
}
if (player.isSneaking())
{
List<ItemStack> items = new ArrayList<ItemStack>();
if (tile instanceof IInventory)
{
IInventory inventory = (IInventory) tile;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
@ -84,6 +114,7 @@ public class ItemWrench extends ItemTR implements ITexturedItem
}
items.add(itemStack.copy());
}
}
if (tile instanceof IWrenchable)
{
@ -96,6 +127,8 @@ public class ItemWrench extends ItemTR implements ITexturedItem
}
items.add(itemStack);
}
if (!items.isEmpty())
{
for (ItemStack itemStack : items)
{
Random rand = new Random();
@ -109,7 +142,8 @@ public class ItemWrench extends ItemTR implements ITexturedItem
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
entityItem.getEntityItem()
.setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
@ -121,6 +155,8 @@ public class ItemWrench extends ItemTR implements ITexturedItem
world.spawnEntityInWorld(entityItem);
}
}
}
// TODO 1.9 sounds
// world.playSoundAtEntity(player, "techreborn:block_dismantle",
// 0.8F, 1F);
@ -130,6 +166,8 @@ public class ItemWrench extends ItemTR implements ITexturedItem
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.FAIL;
}