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;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.blocks.IRotationTexture;
@ -46,14 +39,6 @@ public class BlockGenerator extends BlockMachineBase implements IRotationTexture
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
public String getFrontOff()
{

View file

@ -18,18 +18,19 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
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.fluid.BlockFluidBase;
import techreborn.blocks.storage.BlockBatBox;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.items.ItemTR;
import techreborn.lib.ModInfo;
import techreborn.tiles.storage.TileBatBox;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import techreborn.tiles.storage.TileBatBox;
/**
* Created by modmuss50 on 26/02/2016.
@ -44,8 +45,9 @@ public class ItemWrench extends ItemTR implements ITexturedItem
setMaxStackSize(1);
}
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
@Override 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;
@ -56,13 +58,17 @@ public class ItemWrench extends ItemTR implements ITexturedItem
return EnumActionResult.FAIL;
}
if(!player.isSneaking()){
if(tile instanceof TileBatBox){
tile.getWorld().setBlockState(tile.getPos(), tile.getWorld().getBlockState(pos).withProperty(BlockBatBox.FACING, side.getOpposite()));
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){
} else if (tile instanceof TileMachineBase)
{
if (side != EnumFacing.DOWN && side != EnumFacing.UP)
{
((TileMachineBase) tile).setFacing(side);
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);
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ)
@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;
@ -84,113 +90,109 @@ public class ItemWrench extends ItemTR implements ITexturedItem
{
return EnumActionResult.FAIL;
}
if (player.isSneaking())
if (!world.isRemote)
{
List<ItemStack> items = new ArrayList<ItemStack>();
if (tile instanceof IInventory)
if (player.isSneaking())
{
IInventory inventory = (IInventory) tile;
for (int i = 0; i < inventory.getSizeInventory(); i++)
List<ItemStack> items = new ArrayList<ItemStack>();
if (tile instanceof IInventory)
{
ItemStack itemStack = inventory.getStackInSlot(i);
IInventory inventory = (IInventory) tile;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack == null)
{
continue;
}
if (itemStack != null && itemStack.stackSize > 0)
{
if (itemStack.getItem() instanceof ItemBlock)
if (itemStack != null)
{
if (((ItemBlock) itemStack.getItem()).block instanceof BlockFluidBase
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockStaticLiquid
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockDynamicLiquid)
if (itemStack.stackSize > 0)
{
continue;
if (itemStack.getItem() instanceof ItemBlock)
if (!(((ItemBlock) itemStack.getItem()).block instanceof BlockFluidBase) || !(((ItemBlock) itemStack.getItem()).block instanceof BlockStaticLiquid)
|| !(((ItemBlock) itemStack.getItem()).block instanceof BlockDynamicLiquid))
{
items.add(itemStack.copy());
}
}
}
}
items.add(itemStack.copy());
}
}
if (tile instanceof IWrenchable)
{
if (((IWrenchable) tile).wrenchCanRemove(player))
{
ItemStack itemStack = ((IWrenchable) tile).getWrenchDrop(player);
if (itemStack == null)
if (tile instanceof IWrenchable)
{
return EnumActionResult.FAIL;
}
items.add(itemStack);
}
if (!items.isEmpty())
{
for (ItemStack itemStack : items)
{
Random rand = new Random();
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = 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,
itemStack.copy());
if (itemStack.hasTagCompound())
if (((IWrenchable) tile).wrenchCanRemove(player))
{
entityItem.getEntityItem()
.setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
ItemStack itemStack = ((IWrenchable) tile).getWrenchDrop(player);
if (itemStack == null)
{
return EnumActionResult.FAIL;
}
items.add(itemStack);
}
if (!items.isEmpty())
{
for (ItemStack itemStack : items)
{
Random rand = new Random();
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = 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, itemStack.copy());
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem()
.setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
if (!world.isRemote)
{
world.spawnEntityInWorld(entityItem);
}
}
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
// TODO 1.9 sounds
// world.playSoundAtEntity(player, "techreborn:block_dismantle",
// 0.8F, 1F);
if (!world.isRemote)
{
world.spawnEntityInWorld(entityItem);
world.setBlockState(pos, Blocks.air.getDefaultState(), 2);
}
return EnumActionResult.SUCCESS;
}
}
// TODO 1.9 sounds
// world.playSoundAtEntity(player, "techreborn:block_dismantle",
// 0.8F, 1F);
if (!world.isRemote)
{
world.setBlockState(pos, Blocks.air.getDefaultState(), 2);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}else{
return EnumActionResult.FAIL;
}
return EnumActionResult.FAIL;
}
@Override
public String getTextureName(int damage)
@Override public String getTextureName(int damage)
{
return "techreborn:items/tool/wrench";
}
@Override
public int getMaxMeta()
@Override public int getMaxMeta()
{
return 1;
}
@Override
@SideOnly(Side.CLIENT)
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining)
@Override @SideOnly(Side.CLIENT) public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player,
int useRemaining)
{
return new ModelResourceLocation(ModInfo.MOD_ID + ":" + getUnlocalizedName(stack).substring(5), "inventory");
}
@SideOnly(Side.CLIENT)
public boolean isFull3D()
@SideOnly(Side.CLIENT) public boolean isFull3D()
{
return true;
}