Use itemstack dropping methods from InventoryHelper instead
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package refinedstorage;
|
package refinedstorage;
|
||||||
|
|
||||||
import net.minecraft.entity.item.EntityItem;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.ISidedInventory;
|
import net.minecraft.inventory.ISidedInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@@ -62,44 +61,6 @@ public class RefinedStorageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dropInventory(World world, IInventory inventory, int x, int y, int z) {
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
|
||||||
ItemStack stack = inventory.getStackInSlot(i);
|
|
||||||
|
|
||||||
if (stack != null) {
|
|
||||||
dropStack(world, stack, x, y, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void dropStack(World world, ItemStack stack, int x, int y, int z) {
|
|
||||||
float xo = world.rand.nextFloat() * 0.8F + 0.1F;
|
|
||||||
float yo = world.rand.nextFloat() * 0.8F + 0.1F;
|
|
||||||
float zo = world.rand.nextFloat() * 0.8F + 0.1F;
|
|
||||||
|
|
||||||
while (stack.stackSize > 0) {
|
|
||||||
int amount = world.rand.nextInt(21) + 10;
|
|
||||||
|
|
||||||
if (amount > stack.stackSize) {
|
|
||||||
amount = stack.stackSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.stackSize -= amount;
|
|
||||||
|
|
||||||
EntityItem entity = new EntityItem(world, (float) x + xo, (float) y + yo, (float) z + zo, new ItemStack(stack.getItem(), amount, stack.getItemDamage()));
|
|
||||||
|
|
||||||
entity.motionX = (float) world.rand.nextGaussian() * 0.05F;
|
|
||||||
entity.motionY = (float) world.rand.nextGaussian() * 0.05F + 0.2F;
|
|
||||||
entity.motionZ = (float) world.rand.nextGaussian() * 0.05F;
|
|
||||||
|
|
||||||
if (stack.hasTagCompound()) {
|
|
||||||
entity.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
|
|
||||||
}
|
|
||||||
|
|
||||||
world.spawnEntityInWorld(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean compareStack(ItemStack first, ItemStack second) {
|
public static boolean compareStack(ItemStack first, ItemStack second) {
|
||||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import net.minecraft.block.state.BlockStateContainer;
|
|||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
@@ -127,7 +128,7 @@ public abstract class BlockBase extends Block {
|
|||||||
TileEntity tile = world.getTileEntity(pos);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
if (tile instanceof TileBase && ((TileBase) tile).getDroppedInventory() != null) {
|
if (tile instanceof TileBase && ((TileBase) tile).getDroppedInventory() != null) {
|
||||||
RefinedStorageUtils.dropInventory(world, ((TileBase) tile).getDroppedInventory(), pos.getX(), pos.getY(), pos.getZ());
|
InventoryHelper.dropInventoryItems(world, pos, ((TileBase) tile).getDroppedInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
super.breakBlock(world, pos, state);
|
super.breakBlock(world, pos, state);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package refinedstorage.item;
|
|||||||
|
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
@@ -10,7 +11,6 @@ import net.minecraft.util.EnumHand;
|
|||||||
import net.minecraft.util.text.translation.I18n;
|
import net.minecraft.util.text.translation.I18n;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
|
||||||
import refinedstorage.block.EnumStorageType;
|
import refinedstorage.block.EnumStorageType;
|
||||||
import refinedstorage.storage.NBTStorage;
|
import refinedstorage.storage.NBTStorage;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class ItemStorageDisk extends ItemBase {
|
|||||||
ItemStack storagePart = new ItemStack(RefinedStorageItems.STORAGE_PART, 1, stack.getMetadata());
|
ItemStack storagePart = new ItemStack(RefinedStorageItems.STORAGE_PART, 1, stack.getMetadata());
|
||||||
|
|
||||||
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
if (!player.inventory.addItemStackToInventory(storagePart.copy())) {
|
||||||
RefinedStorageUtils.dropStack(world, storagePart, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
|
InventoryHelper.spawnItemStack(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), storagePart);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(RefinedStorageItems.STORAGE_HOUSING));
|
return new ActionResult(EnumActionResult.SUCCESS, new ItemStack(RefinedStorageItems.STORAGE_HOUSING));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -55,7 +56,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
|||||||
// when a destructor faces a storage network block and removes it
|
// when a destructor faces a storage network block and removes it
|
||||||
// it will essentially remove this block from the network without knowing.
|
// it will essentially remove this block from the network without knowing.
|
||||||
if (controller != null && !controller.push(drop)) {
|
if (controller != null && !controller.push(drop)) {
|
||||||
RefinedStorageUtils.dropStack(worldObj, drop, front.getX(), front.getY(), front.getZ());
|
InventoryHelper.spawnItemStack(worldObj, front.getX(), front.getY(), front.getZ(), drop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,7 @@ package refinedstorage.tile.grid;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.*;
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.inventory.InventoryCraftResult;
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -165,7 +162,7 @@ public class TileGrid extends TileMachine implements IGrid {
|
|||||||
if (controller != null && controller.push(craftedItem.copy())) {
|
if (controller != null && controller.push(craftedItem.copy())) {
|
||||||
// NO OP
|
// NO OP
|
||||||
} else {
|
} else {
|
||||||
RefinedStorageUtils.dropStack(player.worldObj, craftedItem, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
|
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), craftedItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user