Make retextured tile entities support update packets as well

This commit is contained in:
KnightMiner committed 2021-05-08 17:10:26 -04:00
1 parent 422b3a59f7
commit c0ca7ebcbf
2 files changed
+23 -4

No files matched your search

@@ -3,7 +3,9 @@ package slimeknights.mantle.tileentity;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.common.util.Constants.NBT;
import slimeknights.mantle.client.model.data.SinglePropertyData;
import slimeknights.mantle.util.RetexturedHelper;
@@ -52,4 +54,15 @@ public interface IRetexturedTileEntity {
}
return new SinglePropertyData<>(RetexturedHelper.BLOCK_PROPERTY, block);
}
/** Adds the NBT to the update tag, intended to be called in {@link TileEntity#getUpdateTag()} */
default void writeTextureToUpdateTag(CompoundNBT nbt) {
String textureName = getTextureName();
if (!textureName.isEmpty()) {
if (!nbt.contains("ForgeData", NBT.TAG_COMPOUND)) {
nbt.put("ForgeData", new CompoundNBT());
}
RetexturedHelper.setTexture(nbt.getCompound("ForgeData"), textureName);
}
}
}
@@ -1,7 +1,6 @@
package slimeknights.mantle.tileentity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.LazyValue;
import net.minecraftforge.client.model.data.IModelData;
@@ -9,7 +8,7 @@ import net.minecraftforge.client.model.data.IModelData;
/**
* Minimal implementation for {@link IRetexturedTileEntity}, use alongside {@link slimeknights.mantle.block.RetexturedBlock} and {@link slimeknights.mantle.item.RetexturedBlockItem}
*/
public class RetexturedTileEntity extends TileEntity implements IRetexturedTileEntity {
public class RetexturedTileEntity extends MantleTileEntity implements IRetexturedTileEntity {
/** Lazy value of model data as it will not change after first fetch */
private final LazyValue<IModelData> data = new LazyValue<>(this::getRetexturedModelData);
@@ -22,9 +21,16 @@ public class RetexturedTileEntity extends TileEntity implements IRetexturedTileE
return data.getValue();
}
@Override
protected boolean shouldSyncOnUpdate() {
return true;
}
@Override
public CompoundNBT getUpdateTag() {
// new tag instead of super since default implementation calls the super of writeToNBT
return write(new CompoundNBT());
// already included in regular NBT as this lives in ForgeData, just copy to the update tag
CompoundNBT nbt = super.getUpdateTag();
writeTextureToUpdateTag(nbt);
return nbt;
}
}