Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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();
 }
}

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.