Skip to content

Commit

Permalink
prevent creating a placed item tile entity if the associated item is …
Browse files Browse the repository at this point in the history
…null (#54)
  • Loading branch information
Alexdoru authored Oct 21, 2024
1 parent ab82b92 commit 101a1d4
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;

import com.brandon3055.draconicevolution.common.ModBlocks;

Expand Down Expand Up @@ -52,7 +53,9 @@ public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
NBTTagCompound[] tag = new NBTTagCompound[1];
tag[0] = new NBTTagCompound();
if (stack != null) tag[0] = stack.writeToNBT(tag[0]);
if (stack != null) {
stack.writeToNBT(tag[0]);
}
compound.setTag("Item" + 0, tag[0]);
compound.setFloat("Rotation", rotation);
}
Expand All @@ -63,6 +66,12 @@ public void readFromNBT(NBTTagCompound compound) {
NBTTagCompound[] tag = new NBTTagCompound[1];
tag[0] = compound.getCompoundTag("Item" + 0);
stack = ItemStack.loadItemStackFromNBT(tag[0]);
if (stack == null) {
throw new NullPointerException(
"Cannot load the Placed Item at location "
+ Vec3.createVectorHelper(this.xCoord, this.yCoord, this.zCoord)
+ " because the associated item is null!");
}
rotation = compound.getFloat("Rotation");
}
}

0 comments on commit 101a1d4

Please sign in to comment.