From 55e0af173460c1346e6396701b9c39d31267d7a8 Mon Sep 17 00:00:00 2001 From: Matti Ruohonen Date: Tue, 7 Feb 2017 06:53:04 +0200 Subject: [PATCH 1/2] Fix infinite NBT tag recursion in getUpdateTag(). Fixes #101. --- .../blocks/TileMovingBase.java | 6 +++-- .../blocks/TileMovingServer.java | 25 +++---------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingBase.java b/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingBase.java index 9a62a23..f7960eb 100644 --- a/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingBase.java +++ b/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingBase.java @@ -113,8 +113,10 @@ public void readFromNBT(NBTTagCompound tag) { @Nonnull public NBTTagCompound writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); - tag.setTag("BlockTag", block); - tag.setTag("DescTag", desc); + if (block != null) + tag.setTag("BlockTag", block); + if (desc != null) + tag.setTag("DescTag", desc); tag.setInteger("Time", time); tag.setInteger("MaxTime", maxTime); tag.setByte("Dir", (byte) dir); diff --git a/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java b/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java index 2fc65e4..b0f570d 100644 --- a/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java +++ b/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java @@ -1,5 +1,7 @@ package com.rwtema.funkylocomotion.blocks; +import java.lang.ref.WeakReference; +import javax.annotation.Nonnull; import com.rwtema.funkylocomotion.movers.MoverEventHandler; import com.rwtema.funkylocomotion.movers.MovingTileRegistry; import net.minecraft.entity.player.EntityPlayer; @@ -8,9 +10,6 @@ import net.minecraft.util.EnumHand; import net.minecraftforge.fml.relauncher.Side; -import javax.annotation.Nonnull; -import java.lang.ref.WeakReference; - public class TileMovingServer extends TileMovingBase { public WeakReference activatingPlayer = null; @@ -26,25 +25,7 @@ public TileMovingServer() { @Override @Nonnull public NBTTagCompound getUpdateTag() { - if (desc == null) - return super.getUpdateTag(); - - super.writeToNBT(desc); - - desc.setInteger("Time", time); - desc.setInteger("MaxTime", maxTime); - desc.setByte("Dir", (byte) dir); - - if (lightLevel > 0) - desc.setByte("Light", (byte) lightLevel); - if (lightOpacity > 0) - desc.setShort("Opacity", (short) lightOpacity); - - if (collisions.length > 0) { - desc.setTag("Collisions", TagsAxis(collisions)); - } - - return desc; + return this.writeToNBT(new NBTTagCompound()); } @Override From d005a52c0041ccf23683cff8e63fecf53fdfa9ec Mon Sep 17 00:00:00 2001 From: Matti Ruohonen Date: Fri, 10 Feb 2017 06:39:05 +0200 Subject: [PATCH 2/2] Fix the NBT recursion fix... Movement animation now works again. --- .../blocks/TileMovingServer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java b/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java index b0f570d..d280cbb 100644 --- a/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java +++ b/src/main/java/com/rwtema/funkylocomotion/blocks/TileMovingServer.java @@ -25,7 +25,23 @@ public TileMovingServer() { @Override @Nonnull public NBTTagCompound getUpdateTag() { - return this.writeToNBT(new NBTTagCompound()); + if (this.desc == null) + return super.getUpdateTag(); + + this.desc.setInteger("Time", this.time); + this.desc.setInteger("MaxTime", this.maxTime); + this.desc.setByte("Dir", (byte) this.dir); + + if (this.block != null) + this.desc.setTag("BlockTag", this.block); + if (this.collisions.length > 0) + this.desc.setTag("Collisions", TagsAxis(this.collisions)); + if (this.lightLevel != 0) + this.desc.setByte("Light", (byte) this.lightLevel); + if (this.lightOpacity != 0) + this.desc.setShort("Opacity", (short) this.lightOpacity); + + return this.desc; } @Override