Jump to content

Sending package to TileEntityRenderer isn't working


Gerolmed

Recommended Posts

I was kind of following this tutorial: https://www.youtube.com/watch?v=NNclUS5edcY&t=1230s

I have a custom item saved inside my TileEntity but it only shows up on world join not when changing the Item. Here is the Code:

 

The update get and set have the same Code as read and write so it should be working.

 

This is what is not working:

@Override
	public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
		NBTTagCompound tag = pkt.getNbtCompound();
		readUpdateTag(tag);
		this.readFromNBT(tag);
	}
	
	@Override
	public SPacketUpdateTileEntity getUpdatePacket() {
		NBTTagCompound tag = new NBTTagCompound();
		this.writeUpdateTag(tag);
		return new SPacketUpdateTileEntity(pos, getBlockMetadata(), tag);
	}
	
	@Override
	public NBTTagCompound getUpdateTag() {
		NBTTagCompound tag = super.getUpdateTag();
		writeUpdateTag(tag);
		return tag;
	}
	
	public void writeUpdateTag(NBTTagCompound tag) {
		tag.setBoolean("infusing", infusing);
		tag.setInteger("infusiontimer", infusionTimer);
		NBTTagCompound compoundItem = new NBTTagCompound();
		compoundItem = item.serializeNBT();
		tag.setTag("item", compoundItem);
	}
	
	public void readUpdateTag(NBTTagCompound tag) {
		infusing = tag.getBoolean("infusing");
		infusionTimer = tag.getInteger("infusiontimer");
		
		NBTTagCompound compoundItem = tag.getCompoundTag("item");
		item = new ItemStack(compoundItem);
	}

 

 

.

First = TileEntity. Second = renderer

package net.mysticsouls.wandustrie.tileentity;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityManaInfuser extends TileEntity {
public ItemStack item;

boolean infusing;

int infusionTimer;

public void toggleItem(ItemStack item) {
if(world.isRemote) return;
ItemStack stack = removeItem();
if(stack != null) {
world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack));
}
ItemStack newItem = item.copy();
newItem.setCount(1);
setItem(newItem);

resetInfuse();

markDirty();
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
}

ItemStack removeItem() {
ItemStack stack = this.item;
this.item = null;
return stack;
}

void setItem(ItemStack item) {
this.item = item; 
}

void resetInfuse() {
infusing = false;
infusionTimer = 0;
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
this.writeUpdateTag(compound);
return compound;
}

@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
this.readUpdateTag(compound);
}

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

@Override
public SPacketUpdateTileEntity getUpdatePacket() {
NBTTagCompound tag = new NBTTagCompound();
this.writeUpdateTag(tag);
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), tag);
}

@Override
public NBTTagCompound getUpdateTag() {
NBTTagCompound tag = super.getUpdateTag();
writeUpdateTag(tag);
return tag;
}

public void writeUpdateTag(NBTTagCompound tag) {
tag.setBoolean("infusing", infusing);
tag.setInteger("infusiontimer", infusionTimer);
NBTTagCompound compoundItem = new NBTTagCompound();
compoundItem = item.serializeNBT();
tag.setTag("item", compoundItem);
}

public void readUpdateTag(NBTTagCompound tag) {
infusing = tag.getBoolean("infusing");
infusionTimer = tag.getInteger("infusiontimer");

NBTTagCompound compoundItem = tag.getCompoundTag("item");
item = new ItemStack(compoundItem);
}
}

 

package net.mysticsouls.wandustrie.tileentity.render;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.mysticsouls.wandustrie.init.ModItems;
import net.mysticsouls.wandustrie.tileentity.TileEntityManaInfuser;

public class RendererManaInfuser extends TileEntitySpecialRenderer<TileEntityManaInfuser>{

 private EntityItem ITEM = new EntityItem(Minecraft.getMinecraft().world, 0, 0, 0, new ItemStack(ModItems.magicOreIngot));

 @Override
 public void renderTileEntityAt(TileEntityManaInfuser te, double x, double y, double z, float partialTicks,
 int destroyStage) {
 super.renderTileEntityAt(te, x, y, z, partialTicks, destroyStage); 

 GlStateManager.pushMatrix();
 {
 if(te.item != null) {
 ITEM = new EntityItem(Minecraft.getMinecraft().world, 0, 0, 0, te.item);
 ITEM.hoverStart = 0F;
 GlStateManager.translate(x, y, z);
 GlStateManager.translate(0.5, 0, 0.5);
 GlStateManager.rotate(45F, 0, 1, 0);
 Minecraft.getMinecraft().getRenderManager().doRenderEntity(ITEM, 0, 0, 0, 0F, 0F, false);
 }
 }
 GlStateManager.popMatrix();
 }
}
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.