Fix block item drops and such. Closes #428
This commit is contained in:
parent
6247a2093d
commit
6ff03bc706
6 changed files with 202 additions and 41 deletions
|
@ -1,13 +1,20 @@
|
|||
package techreborn.blocks.storage;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.client.GuiHandler;
|
||||
import techreborn.tiles.storage.TileBatBox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 14/03/2016.
|
||||
*/
|
||||
|
@ -26,6 +33,34 @@ public class BlockBatBox extends BlockEnergyStorage
|
|||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
||||
{
|
||||
dropInventory(worldIn, pos, new ItemStack(this));
|
||||
ArrayList<ItemStack> items = (ArrayList<ItemStack>) dropInventory(worldIn, pos, new ItemStack(this));
|
||||
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(worldIn, 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;
|
||||
worldIn.spawnEntityInWorld(entityItem);
|
||||
itemStack.stackSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
|
||||
{
|
||||
|
||||
return new ArrayList<ItemStack>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,10 @@ import net.minecraft.block.properties.PropertyDirection;
|
|||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
@ -127,19 +125,20 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat
|
|||
|
||||
|
||||
|
||||
protected void dropInventory(World world, BlockPos pos, ItemStack itemToDrop)
|
||||
protected List<ItemStack> dropInventory(IBlockAccess world, BlockPos pos, ItemStack itemToDrop)
|
||||
{
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
|
||||
if (tileEntity == null)
|
||||
{
|
||||
System.out.print("Null");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (!(tileEntity instanceof IInventory))
|
||||
{
|
||||
|
||||
return;
|
||||
System.out.print("Not INstance");
|
||||
return null;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tileEntity;
|
||||
|
@ -168,30 +167,8 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat
|
|||
}
|
||||
items.add(itemStack.copy());
|
||||
}
|
||||
items.add(itemToDrop);
|
||||
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;
|
||||
world.spawnEntityInWorld(entityItem);
|
||||
itemStack.stackSize = 0;
|
||||
}
|
||||
items.add(itemToDrop.copy());
|
||||
return items;
|
||||
|
||||
}
|
||||
|
||||
|
@ -264,12 +241,6 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
|
||||
{
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFrontOff()
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
package techreborn.blocks.storage;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.client.GuiHandler;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.tiles.storage.TileMFE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 14/03/2016.
|
||||
*/
|
||||
|
@ -27,7 +34,34 @@ public class BlockMFE extends BlockEnergyStorage
|
|||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
||||
{
|
||||
dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe));
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
ArrayList<ItemStack> items = (ArrayList<ItemStack>) dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe, 1 , 6));
|
||||
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(worldIn, 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;
|
||||
worldIn.spawnEntityInWorld(entityItem);
|
||||
itemStack.stackSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
|
||||
{
|
||||
|
||||
return new ArrayList<ItemStack>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
package techreborn.blocks.storage;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.client.GuiHandler;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.tiles.storage.TileMFSU;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 14/03/2016.
|
||||
*/
|
||||
|
@ -29,8 +36,34 @@ public class BlockMFSU extends BlockEnergyStorage
|
|||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
||||
{
|
||||
dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe, 1 ,7));
|
||||
super.breakBlock(worldIn, pos, state);
|
||||
ArrayList<ItemStack> items = (ArrayList<ItemStack>) dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe, 1 , 7));
|
||||
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(worldIn, 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;
|
||||
worldIn.spawnEntityInWorld(entityItem);
|
||||
itemStack.stackSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
|
||||
{
|
||||
|
||||
return new ArrayList<ItemStack>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ package techreborn.tiles.storage;
|
|||
import ic2.api.tile.IWrenchable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import reborncore.api.power.IEnergyItemInfo;
|
||||
import reborncore.common.powerSystem.PoweredItem;
|
||||
|
@ -16,7 +18,7 @@ import reborncore.common.util.Inventory;
|
|||
/**
|
||||
* Created by Rushmead
|
||||
*/
|
||||
public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable, ITickable
|
||||
public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable, ITickable, IInventory
|
||||
{
|
||||
|
||||
public Inventory inventory;
|
||||
|
@ -138,4 +140,89 @@ public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable,
|
|||
super.readFromNBT(nbttagcompound);
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override public int getSizeInventory()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
return inventory.getStackInSlot(index);
|
||||
}
|
||||
|
||||
@Override public ItemStack decrStackSize(int index, int count)
|
||||
{
|
||||
return inventory.decrStackSize(index, count);
|
||||
}
|
||||
|
||||
@Override public ItemStack removeStackFromSlot(int index)
|
||||
{
|
||||
return inventory.removeStackFromSlot(index);
|
||||
}
|
||||
|
||||
@Override public void setInventorySlotContents(int index, ItemStack stack)
|
||||
{
|
||||
inventory.setInventorySlotContents(index, stack);
|
||||
}
|
||||
|
||||
@Override public int getInventoryStackLimit()
|
||||
{
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override public void openInventory(EntityPlayer player)
|
||||
{
|
||||
inventory.openInventory(player);
|
||||
}
|
||||
|
||||
@Override public void closeInventory(EntityPlayer player)
|
||||
{
|
||||
inventory.closeInventory(player);
|
||||
}
|
||||
|
||||
@Override public boolean isItemValidForSlot(int index, ItemStack stack)
|
||||
{
|
||||
return inventory.isItemValidForSlot(index, stack);
|
||||
}
|
||||
|
||||
@Override public int getField(int id)
|
||||
{
|
||||
return inventory.getField(id);
|
||||
}
|
||||
|
||||
@Override public void setField(int id, int value)
|
||||
{
|
||||
inventory.setField(id, value);
|
||||
}
|
||||
|
||||
@Override public int getFieldCount()
|
||||
{
|
||||
return inventory.getFieldCount();
|
||||
}
|
||||
|
||||
@Override public void clear()
|
||||
{
|
||||
inventory.clear();
|
||||
}
|
||||
|
||||
@Override public String getName()
|
||||
{
|
||||
return inventory.getName();
|
||||
}
|
||||
|
||||
@Override public boolean hasCustomName()
|
||||
{
|
||||
return inventory.hasCustomName();
|
||||
}
|
||||
|
||||
@Override public ITextComponent getDisplayName()
|
||||
{
|
||||
return inventory.getDisplayName();
|
||||
}
|
||||
}
|
|
@ -13,4 +13,5 @@ public class TileMFE extends TileEnergyStorage
|
|||
{
|
||||
super("MFE", 2, ModBlocks.mfe, EnumPowerTier.MEDIUM, 512, 512, 4000000);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue