Jump to content

Recommended Posts

Posted

Hi! I am creating a Block (Basic Air Collector) that creates gas and then places the gas into a gas tank. However whenever I try to remove the filled container it disappears. Thanks for all of the help!

 

Tile Entity

package com.thatcreepyuncle.moreElementsMod.gui.collectors;

import com.thatcreepyuncle.moreElementsMod.items.ModItems;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockable;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;

public class TileEntityBAC extends TileEntity implements ISidedInventory, ITickable {
private static final int[] slots = new int[] { 0, 1, 2};

private ItemStack[] inventory = new ItemStack[slots.length];// 0 = Input, 1
															// = Output, 2 =
															// Fuel
private String customName;
public boolean isCollecting = false;
public double gasAmount = 0;
public int storageLimit = 49;
public int powerLeftInCoal = 0;
public boolean createdItem = false;

@Override
public void update() {
	if (isCollecting) {
		gasAmount += 0.5;
		powerLeftInCoal--;
	}
	if (isCollecting && gasAmount >= storageLimit) {
		isCollecting = false;
	}
	if(createdItem && inventory[1] == null){
		System.out.print("");
	}
	if (isCollecting && powerLeftInCoal <= 0 && inventory[2] != null) {
		if (inventory[2].getItem() == Items.coal && inventory[2].stackSize > 1) {
			inventory[2] = new ItemStack(inventory[2].getItem(), --inventory[2].stackSize);
			powerLeftInCoal = 1000;
		} else if (inventory[2].getItem() == Items.coal && inventory[2].stackSize == 1) {
			inventory[2] = null;
			powerLeftInCoal = 1000;
		}

	}
	if (isCollecting && powerLeftInCoal <= 0) {
		isCollecting = false;
		powerLeftInCoal = 0;
	}
	if (inventory[0] != null) {
		if (inventory[0].getItem() == ModItems.empty_gas_container && gasAmount >= storageLimit - 1) {
			if (inventory[1] == null) {
				gasAmount = 0;
				inventory[0] = new ItemStack(inventory[0].getItem(), --inventory[0].stackSize);
				inventory[1] = new ItemStack(ModItems.foroxide_gas_container);

				inventory[0].stackSize = inventory[0].stackSize;
				this.createdItem = true;
			}else if(inventory[1].getItem() == ModItems.foroxide_gas_container && inventory[1].stackSize < 64){
				gasAmount = 0;
				inventory[0] = new ItemStack(inventory[0].getItem(), --inventory[0].stackSize);
				inventory[1].stackSize = inventory[1].stackSize + 1;

				inventory[0].stackSize = inventory[0].stackSize;
				this.createdItem = true;
			}
		}
	}
}

public void start() {
	isCollecting = true;
	if (isCollecting && powerLeftInCoal >= 0 && inventory[2] != null) {
		if (inventory[2].getItem() == Items.coal && inventory[2].stackSize >= 1) {
			inventory[2].stackSize--;
			powerLeftInCoal = 1000;
		}
	}
}

public int getSizeInventory() {
	return 3;
}

@Override
public ItemStack getStackInSlot(int par1) {
	return this.inventory[par1];
}

@Override
public ItemStack decrStackSize(int par1, int par2) {
	if (this.inventory[par1] != null) {
		ItemStack var3;

		if (this.inventory[par1].stackSize <= par2) {
			var3 = this.inventory[par1];
			this.inventory[par1] = null;
			this.markDirty();
			return var3;
		}
		var3 = this.inventory[par1].splitStack(par2);

		if (this.inventory[par1].stackSize == 0) {
			this.inventory[par1] = null;
		}

		this.markDirty();
		return var3;
	}
	return null;
}

@Override
public ItemStack removeStackFromSlot(int slot) {
	System.out.println("Removing from slot: "+slot);
	if (this.inventory[slot] != null) {
		ItemStack var2 = this.inventory[slot];
		this.inventory[slot] = null;
		return var2;
	}
	return null;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	this.inventory[index] = stack;

	if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
		stack.stackSize = this.getInventoryStackLimit();
	}
	this.markDirty();
}

/**
 * Reads a tile entity from NBT.
 */
public void readFromNBT(NBTTagCompound tagCompound) {
	super.readFromNBT(tagCompound);
	NBTTagList tagList = (NBTTagList) tagCompound.getTag("Items");
	this.inventory = new ItemStack[this.getSizeInventory()];

	for (int count = 0; count < tagList.tagCount(); ++count) {
		NBTTagCompound nbt = (NBTTagCompound) tagList.getCompoundTagAt(count);
		int slot = nbt.getByte("Slot") & 255;

		if (slot >= 0 && slot < this.inventory.length) {
			this.inventory[slot] = ItemStack.loadItemStackFromNBT(nbt);
		}
	}

	if (tagCompound.hasKey("CustomName", ) {
		this.customName = tagCompound.getString("CustomName");
	}
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	NBTTagList nbtTabList = new NBTTagList();

	for (int i = 0; i < this.inventory.length; ++i) {
		if (this.inventory[i] != null) {
			NBTTagCompound var4 = new NBTTagCompound();
			var4.setByte("Slot", (byte) i);
			this.inventory[i].writeToNBT(var4);
			nbtTabList.appendTag(var4);
		}
	}

	compound.setTag("Items", nbtTabList);
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
	NBTTagCompound tagCom = pkt.getNbtCompound();
	this.readFromNBT(tagCom);
}

@Override
public Packet getDescriptionPacket() {
	NBTTagCompound tagCom = new NBTTagCompound();
	this.writeToNBT(tagCom);
	return new SPacketUpdateTileEntity(pos, getBlockMetadata(), tagCom);
}

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

@Override
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) {
	return this.worldObj.getTileEntity(pos) != this ? false : par1EntityPlayer.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D;
}

@Override
public void invalidate() {
	this.updateContainingBlockInfo();
	super.invalidate();
}

@Override
public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack) {
	return true;
}

@Override
public String getName() {
	return this.hasCustomName() ? this.customName : "container.basic_air_container";
}

@Override
public boolean hasCustomName() {
	return this.customName != null && this.customName.length() > 0;
}

@Override
public ITextComponent getDisplayName() {
	return new TextComponentString(getName());
}

@Override
public void openInventory(EntityPlayer playerIn) {
}

@Override
public void closeInventory(EntityPlayer playerIn) {
}

@Override
public int getField(int id) {
	return 0;
}

@Override
public void setField(int id, int value) {
}

@Override
public int getFieldCount() {
	return 0;
}

@Override
public void clear() {
	for (int i = 0; i < inventory.length; i++) {
		inventory[i] = null;
	}
}

@Override
public int[] getSlotsForFace(EnumFacing side) {
	return slots;
}

@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) {
	if (index == 0 && direction == EnumFacing.UP) {
		return true;
	}else if(index == 2){
		switch(direction){
		case NORTH:
		case EAST:
		case SOUTH:
		case WEST:
			return true;
		default:
			return false;
		}
	}
	return false;
}

@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
	if (index == 1){
		System.out.println("Extracting from 1");
		return true;
	}
	if(stack.getItem() == ModItems.foroxide_gas_container){
		return true;
	}
	//System.out.println("Index: " + index);

	return false;
}
}

 

Container:

package com.thatcreepyuncle.moreElementsMod.gui.collectors;

import com.thatcreepyuncle.moreElementsMod.items.ModItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;

public class BasicAirCollectorContainer extends Container {
private IInventory lowerChestInventory;
private int numRows;

public BasicAirCollectorContainer(IInventory playerInventory, IInventory inventory) {
	this.lowerChestInventory = playerInventory;
	inventory.openInventory(null);
	int var4, var5;
	System.out.println("Google");
	this.addSlotToContainer(new Slot(inventory, 0, 8, 61));// Input
	this.addSlotToContainer(new Slot(inventory, 1, 31, 61));// Output
	this.addSlotToContainer(new Slot(inventory, 2, 231, 143)); // Fuel

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 9; ++j) {
			this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, j * 18 + 8, i * 18 + 85));
		}
	}

	for (int i = 0; i < 9; i++) {
		this.addSlotToContainer(new Slot(playerInventory, i, i * 18 + 8, 143));
	}
}

public boolean canInteractWith(EntityPlayer par1EntityPlayer) {
	return this.lowerChestInventory.isUseableByPlayer(par1EntityPlayer);
}

@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {

	ItemStack previous = null;
	Slot slot = (Slot) this.inventorySlots.get(fromSlot);

	if (slot != null && slot.getHasStack()) {
		ItemStack current = slot.getStack();
		previous = current.copy();

		if (fromSlot <= 3) {
			// From TE Inventory to Player Inventory
			if (!this.mergeItemStack(current, 3, 38, true))
				return null;
		} else {
			// From Player Inventory to TE Inventory
			if (!this.mergeItemStack(current, 0, 2, false))
				return null;
		}

		if (current.stackSize == 0)
			slot.putStack((ItemStack) null);
		else
			slot.onSlotChanged();

		if (current.stackSize == previous.stackSize)
			return null;
		slot.onPickupFromSlot(playerIn, current);
	}
	return previous;

}

/**
 * Callback for when the crafting gui is closed.
 */
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
	super.onContainerClosed(par1EntityPlayer);
	this.lowerChestInventory.closeInventory(par1EntityPlayer);
}

public IInventory func_85151_d() {
	return this.lowerChestInventory;
}

@Override
public boolean canMergeSlot(ItemStack stack, Slot slotIn) {
	return super.canMergeSlot(stack, slotIn);
}
}

Posted

You have a lot of funky stuff in there...

// this is the worst way to decrement stack size that I have ever seen:
inventory[0] = new ItemStack(inventory[0].getItem(), --inventory[0].stackSize);

// this does absolutely nothing:
inventory[0].stackSize = inventory[0].stackSize;

 

Anyway, it sounds like your output slot either has a stack size of 0 (which you should be able to see in the GUI) or only exists on the client side, so when you pick it up it doesn't actually register as a real stack. Try adding the following to the beginning of your #update method:

if (this.worldObj.isRemote) {
    return; // don't do anything on client
}

I'd also recommend taking a closer look at the vanilla furnace's TileEntity code - there is lots of information there that is applicable to your situation.

Posted

I think you may be running into the same issue I was having when I was tinkering with a machine like thingy. Basically the changes you're making to the items/inventory are only happening client side, and the client needs to send a networking packet to the server, which the server then needs to actually handle the modification of the inventory.

 

http://www.minecraftforge.net/forum/index.php/topic,39598.msg208543.html#msg208543 is the link to the post I made

 

http://www.minecraftforge.net/forum/index.php/topic,20135.0.html a good tutorial on the networking packets.

 

This should hopefully get you going in the right direction, hope it helps!

Posted

So I set up  Packet Handling, but I get an DecoderException!

 

Error

[15:33:09] [Netty Server IO #1/ERROR] [FML]: FMLIndexedMessageCodec exception caught
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:4.0.23.Final]
at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:90) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:155) [NetworkManager.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:50) [NetworkManager.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleServerSideCustomPacket(NetworkDispatcher.java:429) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:252) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:53) [NetworkDispatcher.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:326) [LocalChannel.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:45) [LocalChannel.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:312) [LocalChannel$5.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380) [singleThreadEventExecutor.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357) [NioEventLoop.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [singleThreadEventExecutor$2.class:4.0.23.Final]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
Caused by: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage
at java.lang.Class.newInstance(Class.java:427) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:82) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.23.Final]
... 25 more
Caused by: java.lang.NoSuchMethodException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_65]
at java.lang.Class.newInstance(Class.java:412) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:82) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.23.Final]
... 25 more
[15:33:09] [Netty Server IO #1/ERROR] [FML]: SimpleChannelHandlerWrapper exception
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:4.0.23.Final]
at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:90) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:155) [NetworkManager.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:50) [NetworkManager.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleServerSideCustomPacket(NetworkDispatcher.java:429) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:252) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:53) [NetworkDispatcher.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:326) [LocalChannel.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:45) [LocalChannel.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:312) [LocalChannel$5.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380) [singleThreadEventExecutor.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357) [NioEventLoop.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [singleThreadEventExecutor$2.class:4.0.23.Final]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
Caused by: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage
at java.lang.Class.newInstance(Class.java:427) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:82) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.23.Final]
... 25 more
Caused by: java.lang.NoSuchMethodException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_65]
at java.lang.Class.newInstance(Class.java:412) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:82) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.23.Final]
... 25 more
[15:33:09] [Netty Server IO #1/ERROR] [FML]: There was a critical exception handling a packet on channel MyChannel
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[MessageToMessageDecoder.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) ~[DefaultChannelPipeline.class:4.0.23.Final]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:4.0.23.Final]
at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:90) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:155) [NetworkManager.class:?]
at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:50) [NetworkManager.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleServerSideCustomPacket(NetworkDispatcher.java:429) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:252) [NetworkDispatcher.class:?]
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:53) [NetworkDispatcher.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [simpleChannelInboundHandler.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [AbstractChannelHandlerContext.class:4.0.23.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [DefaultChannelPipeline.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel.finishPeerRead(LocalChannel.java:326) [LocalChannel.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:45) [LocalChannel.class:4.0.23.Final]
at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:312) [LocalChannel$5.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380) [singleThreadEventExecutor.class:4.0.23.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357) [NioEventLoop.class:4.0.23.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [singleThreadEventExecutor$2.class:4.0.23.Final]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
Caused by: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage
at java.lang.Class.newInstance(Class.java:427) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:82) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.23.Final]
... 25 more
Caused by: java.lang.NoSuchMethodException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_65]
at java.lang.Class.newInstance(Class.java:412) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:82) ~[FMLIndexedMessageToMessageCodec.class:?]
at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:21) ~[FMLIndexedMessageToMessageCodec.class:?]
at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.0.23.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:4.0.23.Final]
... 25 more
[15:33:09] [server thread/INFO]: Player986 lost connection: TextComponent{text='A fatal error has occurred, this connection is terminated', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}
[15:33:09] [server thread/INFO]: Player986 left the game

 

Message:

 

public class BACCraftingMessage implements IMessage {

	public int x, y, z;

	public BACCraftingMessage(BlockPos pos) {
		this.x = pos.getX();
		this.y = pos.getY();
		this.z = pos.getZ();
	}

	//Read
	@Override
	public void fromBytes(ByteBuf buf) {
		System.out.println("Reading from bytes");
		NBTTagCompound nbt = ByteBufUtils.readTag(buf);
		this.x = nbt.getInteger("X");
		this.y = nbt.getInteger("Y");
		this.z = nbt.getInteger("Z");
		System.out.println("Finished Reading");
	}

	//Write
	@Override
	public void toBytes(ByteBuf buf) {
		System.out.println("Coding Message to Bytes");
		NBTTagCompound nbt = new NBTTagCompound();
		nbt.setInteger("X", this.x);
		nbt.setInteger("Y", this.y);
		nbt.setInteger("Z", this.z);
		ByteBufUtils.writeTag(buf, nbt);
		System.out.println("Finished Writing!");
	}
}

 

Handler

 

public static class BACInventoryHandler implements IMessageHandler<BACCraftingMessage, IMessage> {

	// or in 1.8:
	@Override
	public IMessage onMessage(final BACCraftingMessage message, final MessageContext ctx) {
		IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; 
		mainThread.addScheduledTask(new Runnable() {
			@Override
			public void run() {
				System.out.println("Running Task");
				TileEntity t = ctx.getServerHandler().playerEntity.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
				if(t instanceof TileEntityBAC){
					System.out.println("Running Fill Gas Container");
					((TileEntityBAC) t).fillGasContainer();
				}
			}
		});
		return null;
	}
}

Posted
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage

...

Caused by: java.lang.InstantiationException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage

...

Caused by: java.lang.NoSuchMethodException: com.thatcreepyuncle.moreElementsMod.network.NetworkMessages$BACCraftingMessage.<init>()

 

IMessage

classes must have a zero-argument constructor. This means that you can't implement

IMessage

with a non-static nested class (a.k.a an inner class) because Java adds the enclosing class as a parameter to all constructors, so it's not possible to have a zero-argument constructor. You can implement with a static nested class, since Java doesn't interfere with your constructors.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

You shouldn't need packets for this... unless things have changed very considerably. ITickable#update should be called on both sides automatically, but you should only update your TileEntity data on the server (i.e. when the world is NOT remote, as I mentioned).

 

If you open the GUI, the Container sends the current inventory data to the client so it can be viewed, and you should use the various Container methods such as #detectAndSendChanges (or whatever that has become in whatever version of Minecraft you are coding for) to handle progress bars such as burn time. Check out the vanilla ContainerFurnace class for an example of that.

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.