Use itemstack dropping methods from InventoryHelper instead

This commit is contained in:
Raoul Van den Berge
2016-05-22 00:57:20 +02:00
parent 5099be6311
commit 10dcfc615e
5 changed files with 8 additions and 48 deletions

View File

@@ -1,6 +1,5 @@
package refinedstorage;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
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) {
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
}

View File

@@ -9,6 +9,7 @@ import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -127,7 +128,7 @@ public abstract class BlockBase extends Block {
TileEntity tile = world.getTileEntity(pos);
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);

View File

@@ -2,6 +2,7 @@ package refinedstorage.item;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
@@ -10,7 +11,6 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import refinedstorage.RefinedStorageItems;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.block.EnumStorageType;
import refinedstorage.storage.NBTStorage;
@@ -55,7 +55,7 @@ public class ItemStorageDisk extends ItemBase {
ItemStack storagePart = new ItemStack(RefinedStorageItems.STORAGE_PART, 1, stack.getMetadata());
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));

View File

@@ -5,6 +5,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
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
// it will essentially remove this block from the network without knowing.
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);
}
}
}

View File

@@ -2,10 +2,7 @@ package refinedstorage.tile.grid;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
@@ -165,7 +162,7 @@ public class TileGrid extends TileMachine implements IGrid {
if (controller != null && controller.push(craftedItem.copy())) {
// NO OP
} 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);
}
}
}