Fix Wrenching, closes #418

This commit is contained in:
Stuart Pomeroy 2016-03-28 13:35:59 +01:00
parent 6054610c3c
commit d51a772979
2 changed files with 87 additions and 100 deletions

View file

@ -1,14 +1,7 @@
package techreborn.blocks.generator; package techreborn.blocks.generator;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.blocks.IRotationTexture; import reborncore.common.blocks.IRotationTexture;
@ -46,14 +39,6 @@ public class BlockGenerator extends BlockMachineBase implements IRotationTexture
return true; return true;
} }
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
List<ItemStack> items = new ArrayList<ItemStack>();
items.add(new ItemStack(this));
return items;
}
@Override @Override
public String getFrontOff() public String getFrontOff()
{ {

View file

@ -18,18 +18,19 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.common.tile.TileMachineBase; import reborncore.common.tile.TileMachineBase;
import techreborn.blocks.fluid.BlockFluidBase;
import techreborn.blocks.storage.BlockBatBox; import techreborn.blocks.storage.BlockBatBox;
import techreborn.client.TechRebornCreativeTabMisc; import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.items.ItemTR; import techreborn.items.ItemTR;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import techreborn.tiles.storage.TileBatBox;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import techreborn.tiles.storage.TileBatBox;
/** /**
* Created by modmuss50 on 26/02/2016. * Created by modmuss50 on 26/02/2016.
@ -44,8 +45,9 @@ public class ItemWrench extends ItemTR implements ITexturedItem
setMaxStackSize(1); setMaxStackSize(1);
} }
@Override @Override public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos,
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
{
if (world.isAirBlock(pos)) if (world.isAirBlock(pos))
{ {
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
@ -56,13 +58,17 @@ public class ItemWrench extends ItemTR implements ITexturedItem
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
} }
if(!player.isSneaking()){ if (!player.isSneaking())
if(tile instanceof TileBatBox){ {
tile.getWorld().setBlockState(tile.getPos(), tile.getWorld().getBlockState(pos).withProperty(BlockBatBox.FACING, side.getOpposite())); if (tile instanceof TileBatBox)
{
tile.getWorld().setBlockState(tile.getPos(),
tile.getWorld().getBlockState(pos).withProperty(BlockBatBox.FACING, side.getOpposite()));
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} else } else if (tile instanceof TileMachineBase)
if(tile instanceof TileMachineBase){ {
if(side != EnumFacing.DOWN && side != EnumFacing.UP){ if (side != EnumFacing.DOWN && side != EnumFacing.UP)
{
((TileMachineBase) tile).setFacing(side); ((TileMachineBase) tile).setFacing(side);
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} }
@ -71,10 +77,10 @@ public class ItemWrench extends ItemTR implements ITexturedItem
return super.onItemUseFirst(stack, player, world, pos, side, hitX, hitY, hitZ, hand); return super.onItemUseFirst(stack, player, world, pos, side, hitX, hitY, hitZ, hand);
} }
@Override @Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos,
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
EnumFacing facing, float hitX, float hitY, float hitZ)
{ {
if (world.isAirBlock(pos)) if (world.isAirBlock(pos))
{ {
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
@ -84,7 +90,8 @@ public class ItemWrench extends ItemTR implements ITexturedItem
{ {
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
} }
if (!world.isRemote)
{
if (player.isSneaking()) if (player.isSneaking())
{ {
List<ItemStack> items = new ArrayList<ItemStack>(); List<ItemStack> items = new ArrayList<ItemStack>();
@ -95,26 +102,20 @@ public class ItemWrench extends ItemTR implements ITexturedItem
{ {
ItemStack itemStack = inventory.getStackInSlot(i); ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack == null) if (itemStack != null)
{ {
continue; if (itemStack.stackSize > 0)
}
if (itemStack != null && itemStack.stackSize > 0)
{ {
if (itemStack.getItem() instanceof ItemBlock) if (itemStack.getItem() instanceof ItemBlock)
if (!(((ItemBlock) itemStack.getItem()).block instanceof BlockFluidBase) || !(((ItemBlock) itemStack.getItem()).block instanceof BlockStaticLiquid)
|| !(((ItemBlock) itemStack.getItem()).block instanceof BlockDynamicLiquid))
{ {
if (((ItemBlock) itemStack.getItem()).block instanceof BlockFluidBase
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockStaticLiquid
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockDynamicLiquid)
{
continue;
}
}
}
items.add(itemStack.copy()); items.add(itemStack.copy());
} }
} }
}
}
if (tile instanceof IWrenchable) if (tile instanceof IWrenchable)
{ {
if (((IWrenchable) tile).wrenchCanRemove(player)) if (((IWrenchable) tile).wrenchCanRemove(player))
@ -130,14 +131,15 @@ public class ItemWrench extends ItemTR implements ITexturedItem
{ {
for (ItemStack itemStack : items) for (ItemStack itemStack : items)
{ {
Random rand = new Random(); Random rand = new Random();
float dX = rand.nextFloat() * 0.8F + 0.1F; float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F; float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F; float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY,
itemStack.copy()); pos.getZ() + dZ, itemStack.copy());
if (itemStack.hasTagCompound()) if (itemStack.hasTagCompound())
{ {
@ -167,30 +169,30 @@ public class ItemWrench extends ItemTR implements ITexturedItem
} }
} }
}
return EnumActionResult.FAIL;
}else{
return EnumActionResult.FAIL; return EnumActionResult.FAIL;
} }
}
@Override @Override public String getTextureName(int damage)
public String getTextureName(int damage)
{ {
return "techreborn:items/tool/wrench"; return "techreborn:items/tool/wrench";
} }
@Override @Override public int getMaxMeta()
public int getMaxMeta()
{ {
return 1; return 1;
} }
@Override @Override @SideOnly(Side.CLIENT) public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player,
@SideOnly(Side.CLIENT) int useRemaining)
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining)
{ {
return new ModelResourceLocation(ModInfo.MOD_ID + ":" + getUnlocalizedName(stack).substring(5), "inventory"); return new ModelResourceLocation(ModInfo.MOD_ID + ":" + getUnlocalizedName(stack).substring(5), "inventory");
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT) public boolean isFull3D()
public boolean isFull3D()
{ {
return true; return true;
} }