Fix Wrenching, closes #418
This commit is contained in:
parent
6054610c3c
commit
d51a772979
2 changed files with 87 additions and 100 deletions
|
@ -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()
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,113 +90,109 @@ public class ItemWrench extends ItemTR implements ITexturedItem
|
||||||
{
|
{
|
||||||
return EnumActionResult.FAIL;
|
return EnumActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
if (!world.isRemote)
|
||||||
if (player.isSneaking())
|
|
||||||
{
|
{
|
||||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
if (player.isSneaking())
|
||||||
if (tile instanceof IInventory)
|
|
||||||
{
|
{
|
||||||
IInventory inventory = (IInventory) tile;
|
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
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)
|
if (itemStack != null)
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (itemStack != null && itemStack.stackSize > 0)
|
|
||||||
{
|
|
||||||
if (itemStack.getItem() instanceof ItemBlock)
|
|
||||||
{
|
{
|
||||||
if (((ItemBlock) itemStack.getItem()).block instanceof BlockFluidBase
|
if (itemStack.stackSize > 0)
|
||||||
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockStaticLiquid
|
|
||||||
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockDynamicLiquid)
|
|
||||||
{
|
{
|
||||||
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 (tile instanceof IWrenchable)
|
|
||||||
{
|
|
||||||
if (((IWrenchable) tile).wrenchCanRemove(player))
|
|
||||||
{
|
|
||||||
ItemStack itemStack = ((IWrenchable) tile).getWrenchDrop(player);
|
|
||||||
if (itemStack == null)
|
|
||||||
{
|
{
|
||||||
return EnumActionResult.FAIL;
|
if (((IWrenchable) tile).wrenchCanRemove(player))
|
||||||
}
|
|
||||||
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()
|
ItemStack itemStack = ((IWrenchable) tile).getWrenchDrop(player);
|
||||||
.setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
|
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;
|
// TODO 1.9 sounds
|
||||||
entityItem.motionX = rand.nextGaussian() * factor;
|
// world.playSoundAtEntity(player, "techreborn:block_dismantle",
|
||||||
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
|
// 0.8F, 1F);
|
||||||
entityItem.motionZ = rand.nextGaussian() * factor;
|
|
||||||
if (!world.isRemote)
|
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
|
@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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue