Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


brandon3055
 Share

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hazmat Suit from Mekanism is the problem. I just found it populating itself to the max over and over raising havok in my Refined storage. Not sure why but i deleted it through transmutation and then unistalled it again. This was in Vault hunters
    • [19mai2022 11:08:54.412] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, Bee_Lytho, --version, 1.16.5-forge-36.2.34, --gameDir, C:\Users\vivie\AppData\Roaming\.minecraft, --assetsDir, C:\Users\vivie\AppData\Roaming\.minecraft\assets, --assetIndex, 1.16, --uuid, 9ca0e0921a5c4760809353131bad1432, --accessToken, ????????, --userType, msa, --versionType, release, --launchTarget, fmlclient, --fml.forgeVersion, 36.2.34, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20210115.111550] [19mai2022 11:08:54.421] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.1.3+8.1.3+main-8.1.x.c94d18ec starting: java version 1.8.0_51 by Oracle Corporation [19mai2022 11:08:54.475] [main/WARN] [cpw.mods.modlauncher.SecureJarHandler/]: LEGACY JDK DETECTED, SECURED JAR HANDLING DISABLED [19mai2022 11:08:54.814] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.onLoad [19mai2022 11:08:54.817] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file URL: file:/C:/Users/vivie/AppData/Roaming/.minecraft/mods/OptiFine_1.18.1_HD_U_H4.jar [19mai2022 11:08:54.819] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file: C:\Users\vivie\AppData\Roaming\.minecraft\mods\OptiFine_1.18.1_HD_U_H4.jar [19mai2022 11:08:54.824] [main/INFO] [optifine.OptiFineTransformer/]: Target.PRE_CLASS is available [19mai2022 11:08:55.172] [main/INFO] [net.minecraftforge.fml.loading.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust [19mai2022 11:08:55.296] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.4 Source=file:/C:/Users/vivie/AppData/Roaming/.minecraft/libraries/org/spongepowered/mixin/0.8.4/mixin-0.8.4.jar Service=ModLauncher Env=CLIENT [19mai2022 11:08:55.321] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.initialize [19mai2022 11:08:56.863] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.AbstractMethodError: Method optifine/OptiFineTransformationService.beginScanning(Lcpw/mods/modlauncher/api/IEnvironment;)V is abstract [19mai2022 11:08:56.863] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at optifine.OptiFineTransformationService.beginScanning(OptiFineTransformationService.java) [19mai2022 11:08:56.863] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.api.ITransformationService.runScan(ITransformationService.java:74) [19mai2022 11:08:56.867] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.TransformationServiceDecorator.runScan(TransformationServiceDecorator.java:114) [19mai2022 11:08:56.870] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.TransformationServicesHandler.lambda$runScanningTransformationServices$8(TransformationServicesHandler.java:115) [19mai2022 11:08:56.870] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.TransformationServicesHandler$$Lambda$204/901205084.apply(Unknown Source) [19mai2022 11:08:56.871] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267) [19mai2022 11:08:56.872] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1612) [19mai2022 11:08:56.873] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512) [19mai2022 11:08:56.874] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502) [19mai2022 11:08:56.874] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) [19mai2022 11:08:56.875] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [19mai2022 11:08:56.876] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) [19mai2022 11:08:56.877] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.TransformationServicesHandler.runScanningTransformationServices(TransformationServicesHandler.java:116) [19mai2022 11:08:56.877] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:63) [19mai2022 11:08:56.878] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.Launcher.run(Launcher.java:76) [19mai2022 11:08:56.879] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]:     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)     Thank you  
    • So something like this is what you meant right? I tested it and this setup works I just wanna make sure I did it correctly New Tile: https://pastebin.com/XHduUJcA InputStackHandler: https://pastebin.com/JKZiSska
    • This is how I fixed it not sure this is the correct way, but it works boolean flag = fluidstate.getType() != Fluids.EMPTY; boolean flag = fluidstate.getType() != Fluids.EMPTY; Added this method @Override public boolean canPlaceLiquid(BlockGetter p_54325_, BlockPos p_54326_, BlockState p_54327_, Fluid p_54328_) { return false; }  
    • Hello, I also want to increase the reach attack of some tools. I would like you to help me especially with the PacketHandler and put it in the tools
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.