Jump to content

[SOLVED][1.7.2] Custom inventory not interacting with hoppers properly.


brandon3055

Recommended Posts

I made my inventory based on a 1.6.4 tutorial but im guessing something changed in 1.7.2.

The  problem i am having is hopper interaction. it works fine when putting items in but when i try to remove items with a hopper it acts very weird. If there is a full stack in the inventory ()the inventory only holds one stack) it will take 5 items from the inventory and will the hopper.

 

It seems like it is each stack the hopper pulls out is the size of the stack in the inventory so if there is 50 items in the inventory and i place a hopper under it the hopper will pull 5 items and each slot in the hopper will receive 50 of the item in the inventory it will then pull 5 more items to fill each slot to 64.

 

This is my tile and all related classes i would really appreciate some help with this because i'm completely lost.

 

tile class

 

package tolkienaddon.tileentities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.storage.WorldInfo;

public class TileWeatherController extends TileEntity implements IInventory {
int tick;
boolean running = false;

private ItemStack[] items;
public int charges;

public TileWeatherController() {
	items = new ItemStack[1];
}

@Override
public void updateEntity() {
	if (charges == 0)
		reload();

	final WorldInfo worldinfo = MinecraftServer.getServer().worldServers[0].getWorldInfo();
	toggleDownfall(worldinfo);
	if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) && charges > 0) {
		if (worldinfo.isRaining()) {
			running = true;
		}
	}
}

private void reload() {
	ItemStack fuel = getStackInSlot(0);

	if (charges == 0 && fuel != null) {

		if (fuel.stackSize > 0 && fuel.isItemEqual(new ItemStack(Items.emerald))) {
			addCharge(10);
		}
	}
}

private void toggleDownfall(final WorldInfo worldinfo) {
	if (running) {

		if (tick < 70) {
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, 0D, 3D, 0D);
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, 0D, 5D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1, zCoord + 0.5, 0D, 1D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1, zCoord + 0.5, 0D, 2D, 0D);
			worldObj.spawnParticle("flame", xCoord + 0.5, yCoord + 1, zCoord + 0.5, 0D, 1D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1.2, zCoord + 0.5, 0D, -0.3D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1.2, zCoord + 0.5, 0D, -0.3D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1.2, zCoord + 0.5, 0D, -0.3D, 0D);

			worldObj.spawnParticle("flame", xCoord + 0.2, yCoord + 1, zCoord + 0.8, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.spawnParticle("flame", xCoord + 0.8, yCoord + 1, zCoord + 0.8, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.spawnParticle("flame", xCoord + 0.2, yCoord + 1, zCoord + 0.2, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.spawnParticle("flame", xCoord + 0.8, yCoord + 1, zCoord + 0.2, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.playSound(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "mob.ghast.fireball", 10F, worldObj.rand.nextFloat() * 0.1F + 0.9F, false);

		}
		if (tick > 80 && tick < 90) {
			worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "tolkienaddon:boom", 10F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
			if (!worldObj.isRemote)
				worldinfo.setRaining(!worldinfo.isRaining());
		}
		if (tick > 110) {

			worldObj.playSound(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.fizz", 10F, worldObj.rand.nextFloat() * 0.1F + 0.9F, false);
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 0, zCoord + 0, 0D, 0D, 0D);
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 0, zCoord + 1, 0D, 0D, 0D);
			worldObj.spawnParticle("explode", xCoord + 0, yCoord + 0, zCoord + 0.5, 0D, 0D, 0D);
			worldObj.spawnParticle("explode", xCoord + 1, yCoord + 0, zCoord + 0.5, 0D, 0D, 0D);

		}
		if (tick > 130) {
			tick = 0;
			running = false;
			useCharge();
		}
		tick++;
	}

}

private void addCharge(int count) {
	if (!worldObj.isRemote) {
		charges = 10;
		decrStackSize(0, 1);
	}
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

private void useCharge() {
	if (!worldObj.isRemote)
		charges--;
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

@Override
public Packet getDescriptionPacket() {
	//Debug
	System.out.println("[DEBUG]:Server sent tile sync packet");

	NBTTagCompound tagCompound = new NBTTagCompound();
	this.writeToNBT(tagCompound);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tagCompound);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	//Debug
	System.out.println("[DEBUG]:Client recived tile sync packet");

	readFromNBT(pkt.func_148857_g());
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

//==============================================INVENTORY====================================================//



@Override
public int getSizeInventory() {
	return items.length;
}

@Override
public ItemStack getStackInSlot(int i) {
	return items[i];
}

@Override
public ItemStack decrStackSize(int i, int count) {
	ItemStack itemstack = getStackInSlot(i);

	if (itemstack != null) {
		if (itemstack.stackSize <= count) {
			setInventorySlotContents(i, null);
		} else {
			itemstack.splitStack(count);
		}
	}
	return itemstack;
}

@Override
public ItemStack getStackInSlotOnClosing(int i) {
	ItemStack item = getStackInSlot(i);
	setInventorySlotContents(i, null);
	return item;
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	items[i] = itemstack;
}

@Override
public String getInventoryName() {
	return "InventoryWeatherController";
}

@Override
public boolean hasCustomInventoryName() {
	return false;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.4) < 64;
}

@Override
public void openInventory() {
}

@Override
public void closeInventory() {
}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	return itemstack.isItemEqual(new ItemStack(Items.emerald));
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	NBTTagCompound[] tag = new NBTTagCompound[items.length];

	for (int i = 0; i < items.length; i++) {
		tag[i] = new NBTTagCompound();

		if (items[i] != null) {
			tag[i] = items[i].writeToNBT(tag[i]);
		}

		compound.setTag("Item" + i, tag[i]);
	}

	compound.setShort("Charges", (short) charges);

	super.writeToNBT(compound);
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	NBTTagCompound[] tag = new NBTTagCompound[items.length];

	for (int i = 0; i < items.length; i++) {
		tag[i] = compound.getCompoundTag("Item" + i);
		items[i] = ItemStack.loadItemStackFromNBT(tag[i]);
	}

	charges = compound.getShort("Charges");

	System.out.println("charges:" + compound.getShort("Charges"));
	super.readFromNBT(compound);
}

}

 

Container class

 

package tolkienaddon.tileentities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.storage.WorldInfo;

public class TileWeatherController extends TileEntity implements IInventory {
int tick;
boolean running = false;

private ItemStack[] items;
public int charges;

public TileWeatherController() {
	items = new ItemStack[1];
}

@Override
public void updateEntity() {
	if (charges == 0)
		reload();

	final WorldInfo worldinfo = MinecraftServer.getServer().worldServers[0].getWorldInfo();
	toggleDownfall(worldinfo);
	if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) && charges > 0) {
		if (worldinfo.isRaining()) {
			running = true;
		}
	}
}

private void reload() {
	ItemStack fuel = getStackInSlot(0);

	if (charges == 0 && fuel != null) {

		if (fuel.stackSize > 0 && fuel.isItemEqual(new ItemStack(Items.emerald))) {
			addCharge(10);
		}
	}
}

private void toggleDownfall(final WorldInfo worldinfo) {
	if (running) {

		if (tick < 70) {
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, 0D, 3D, 0D);
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, 0D, 5D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1, zCoord + 0.5, 0D, 1D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1, zCoord + 0.5, 0D, 2D, 0D);
			worldObj.spawnParticle("flame", xCoord + 0.5, yCoord + 1, zCoord + 0.5, 0D, 1D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1.2, zCoord + 0.5, 0D, -0.3D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1.2, zCoord + 0.5, 0D, -0.3D, 0D);
			worldObj.spawnParticle("largesmoke", xCoord + 0.5, yCoord + 1.2, zCoord + 0.5, 0D, -0.3D, 0D);

			worldObj.spawnParticle("flame", xCoord + 0.2, yCoord + 1, zCoord + 0.8, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.spawnParticle("flame", xCoord + 0.8, yCoord + 1, zCoord + 0.8, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.spawnParticle("flame", xCoord + 0.2, yCoord + 1, zCoord + 0.2, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.spawnParticle("flame", xCoord + 0.8, yCoord + 1, zCoord + 0.2, (worldObj.rand.nextFloat() - 0.5) * 1.5, 1.7D, (worldObj.rand.nextFloat() - 0.5) * 1.5);
			worldObj.playSound(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "mob.ghast.fireball", 10F, worldObj.rand.nextFloat() * 0.1F + 0.9F, false);

		}
		if (tick > 80 && tick < 90) {
			worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "tolkienaddon:boom", 10F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
			if (!worldObj.isRemote)
				worldinfo.setRaining(!worldinfo.isRaining());
		}
		if (tick > 110) {

			worldObj.playSound(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.fizz", 10F, worldObj.rand.nextFloat() * 0.1F + 0.9F, false);
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 0, zCoord + 0, 0D, 0D, 0D);
			worldObj.spawnParticle("explode", xCoord + 0.5, yCoord + 0, zCoord + 1, 0D, 0D, 0D);
			worldObj.spawnParticle("explode", xCoord + 0, yCoord + 0, zCoord + 0.5, 0D, 0D, 0D);
			worldObj.spawnParticle("explode", xCoord + 1, yCoord + 0, zCoord + 0.5, 0D, 0D, 0D);

		}
		if (tick > 130) {
			tick = 0;
			running = false;
			useCharge();
		}
		tick++;
	}

}

private void addCharge(int count) {
	if (!worldObj.isRemote) {
		charges = 10;
		decrStackSize(0, 1);
	}
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

private void useCharge() {
	if (!worldObj.isRemote)
		charges--;
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

@Override
public Packet getDescriptionPacket() {
	//Debug
	System.out.println("[DEBUG]:Server sent tile sync packet");

	NBTTagCompound tagCompound = new NBTTagCompound();
	this.writeToNBT(tagCompound);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tagCompound);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	//Debug
	System.out.println("[DEBUG]:Client recived tile sync packet");

	readFromNBT(pkt.func_148857_g());
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

//==============================================INVENTORY====================================================//



@Override
public int getSizeInventory() {
	return items.length;
}

@Override
public ItemStack getStackInSlot(int i) {
	return items[i];
}

@Override
public ItemStack decrStackSize(int i, int count) {
	ItemStack itemstack = getStackInSlot(i);

	if (itemstack != null) {
		if (itemstack.stackSize <= count) {
			setInventorySlotContents(i, null);
		} else {
			itemstack.splitStack(count);
		}
	}
	return itemstack;
}

@Override
public ItemStack getStackInSlotOnClosing(int i) {
	ItemStack item = getStackInSlot(i);
	setInventorySlotContents(i, null);
	return item;
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	items[i] = itemstack;
}

@Override
public String getInventoryName() {
	return "InventoryWeatherController";
}

@Override
public boolean hasCustomInventoryName() {
	return false;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.4) < 64;
}

@Override
public void openInventory() {
}

@Override
public void closeInventory() {
}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	return itemstack.isItemEqual(new ItemStack(Items.emerald));
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	NBTTagCompound[] tag = new NBTTagCompound[items.length];

	for (int i = 0; i < items.length; i++) {
		tag[i] = new NBTTagCompound();

		if (items[i] != null) {
			tag[i] = items[i].writeToNBT(tag[i]);
		}

		compound.setTag("Item" + i, tag[i]);
	}

	compound.setShort("Charges", (short) charges);

	super.writeToNBT(compound);
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	NBTTagCompound[] tag = new NBTTagCompound[items.length];

	for (int i = 0; i < items.length; i++) {
		tag[i] = compound.getCompoundTag("Item" + i);
		items[i] = ItemStack.loadItemStackFromNBT(tag[i]);
	}

	charges = compound.getShort("Charges");

	System.out.println("charges:" + compound.getShort("Charges"));
	super.readFromNBT(compound);
}

}

 

Gui class

 

package tolkienaddon.client.interfaces;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import tolkienaddon.lib.References;
import tolkienaddon.tileentities.TileWeatherController;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GUIWeatherController extends GuiContainer{

public GUIWeatherController(InventoryPlayer invPlayer, TileWeatherController tileWC) {
	super(new ContainerWeatherController(invPlayer, tileWC));

	xSize = 176;
	ySize = 143;
}

private static final ResourceLocation texture = new ResourceLocation(References.MODID, "textures/gui/WeatherController.png");

@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
	GL11.glColor4f(1, 1, 1, 1);

	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}

}

 

Custome slot

 

package tolkienaddon.client.interfaces;

import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class SlotItemValid extends Slot{

private Item item;

public SlotItemValid(IInventory inventory, int id, int x, int y, Item validItem) {
	super(inventory, id, x, y);

	this.item = validItem;
}

@Override
public boolean isItemValid(ItemStack stack) {
	return stack.isItemEqual(new ItemStack(item));
}



}

 

Block class

 

package tolkienaddon.blocks;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import tolkienaddon.Tolkienaddon;
import tolkienaddon.lib.References;
import tolkienaddon.lib.Strings;
import tolkienaddon.tileentities.TileWeatherController;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockWeatherController extends BlockContainer {
@SideOnly(Side.CLIENT)
public IIcon[] icons;

public boolean blockState = true;

public BlockWeatherController() {
	super(Material.rock);
	this.setBlockName(Strings.blockWeatherControllerName);
	this.setCreativeTab(Tolkienaddon.getCreativeTab());
	this.setStepSound(soundTypeStone);
	this.setHardness(1f);
	this.setResistance(200.0f);
	GameRegistry.registerBlock(this, this.getUnlocalizedName());
	icons = new IIcon[14];

}

@Override
public boolean hasTileEntity(final int meta) {
	return true;
}

@Override
public String getUnlocalizedName() {
	return String.format("tile.%s%s", References.RESOURCESPREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}

public String getUnwrappedUnlocalizedName(final String unlocalizedName) {
	return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(final IIconRegister iconRegister) {
	for (int i = 0; i < 11; i++) {
		icons[i] = iconRegister.registerIcon(getUnwrappedUnlocalizedName(getUnlocalizedWeatherControllerName()) + i);
	}
	icons[11] = iconRegister.registerIcon(getUnwrappedUnlocalizedName(getUnlocalizedWeatherControllerName()) + "Top");
	icons[12] = iconRegister.registerIcon(getUnwrappedUnlocalizedName(getUnlocalizedWeatherControllerName()) + "TopActive");
	icons[13] = iconRegister.registerIcon(getUnwrappedUnlocalizedName(getUnlocalizedWeatherControllerName()) + "Bottom");

}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
	TileWeatherController tile = (TileWeatherController) world.getTileEntity(x, y, z);
	int charges = 0;

	if (tile != null)
		charges = tile.charges;

	if (charges == 0) {
		if (side > 1)
			return icons[charges];
		else if (side == 0)
			return icons[13];
		else
			return icons[11];
	} else {
		if (side > 1)
			return icons[charges];
		else if (side == 0)
			return icons[13];
		else
			return icons[12];
	}
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {

	if (side > 1)
		return icons[0];
	else if (side == 0)
		return icons[13];
	else
		return icons[11];
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks(final Item item, final CreativeTabs tab, final List par3list) {
	par3list.add(new ItemStack(item, 1, 0));
}

@Override
public boolean onBlockActivated(final World world, final int x, final int y, final int z, final EntityPlayer entityPlayer, final int par1, final float par2, final float par3, final float par4) {
	if (!world.isRemote) {
		FMLNetworkHandler.openGui(entityPlayer, Tolkienaddon.instance, 0, world, x, y, z);
	}

	/*if (world.getBlockMetadata(x, y, z) == 0) {
		//System.out.println("go");
		if (ItemStack.areItemStacksEqual(entityPlayer.getHeldItem(), new ItemStack(Items.emerald))) {
			world.setBlock(x, y, z, ModBlocks.weatherController, 10, 2);
			entityPlayer.destroyCurrentEquippedItem();
		}
	}*/

	return true;
}

public String getUnlocalizedWeatherControllerName() {
	return String.format("tile.%s%s", References.RESOURCESPREFIX, "weatherController/weatherController");
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileWeatherController();
}

@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
	TileEntity te = world.getTileEntity(x, y, z);
	if (te != null && te instanceof IInventory) {
		IInventory inventory = (IInventory) te;

		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			ItemStack stack = inventory.getStackInSlot(i);

			if (stack != null) {
				float spawnX = x + world.rand.nextFloat();
				float spawnY = y + world.rand.nextFloat();
				float spawnZ = z + world.rand.nextFloat();

				EntityItem droppedItem = new EntityItem(world, spawnX, spawnY, spawnZ, stack);

				float mult = 0.05F;

				droppedItem.motionX = (-0.5F + world.rand.nextFloat()) * mult;
				droppedItem.motionY = (4 + world.rand.nextFloat()) * mult;
				droppedItem.motionZ = (-0.5F + world.rand.nextFloat()) * mult;

				world.spawnEntityInWorld(droppedItem);
			}
		}
	}

	super.breakBlock(world, x, y, z, block, meta);
}

}

 

 

Edit: Its a bit hard to explain exactly what its doing so i recorded what is happening.

[embed=425,349]http://youtu.be/96MH1Luw0NU[/embed]

I am the author of Draconic Evolution

Link to comment
Share on other sites

I am such a noob.

Take a look at this method

 
@Override
public ItemStack decrStackSize(int i, int count) {
        ItemStack itemstack = getStackInSlot(i);

if (itemstack != null) {
	if (itemstack.stackSize <= count) {
		setInventorySlotContents(i, null);
	} else {
		itemstack.splitStack(count);
		if (itemstack.stackSize == 0) {
			setInventorySlotContents(i, null);
		}
	}
}
return itemstack;
}

Notice anything?

 

itemstack.splitStack(count); should be

itemstack = itemstack.splitStack(count);

 

I must have checked that code half a dozen times before i made this post lol

 

But thanks for letting me know about ISidedInventory i that will come in handy in the future but unless i am mistaken it isn't required for this application.

 

I am the author of Draconic Evolution

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.