diff --git a/common/src/main/java/dev/ryanhcode/sable/api/SubLevelAssemblyHelper.java b/common/src/main/java/dev/ryanhcode/sable/api/SubLevelAssemblyHelper.java index c95b7400..22a2a1d0 100644 --- a/common/src/main/java/dev/ryanhcode/sable/api/SubLevelAssemblyHelper.java +++ b/common/src/main/java/dev/ryanhcode/sable/api/SubLevelAssemblyHelper.java @@ -353,6 +353,8 @@ public static void moveBlocks(final ServerLevel level, final AssemblyTransform t } if (blockEntity instanceof final Clearable clearable) { clearable.clearContent(); + }else if (blockEntity != null) { + SableAssemblyPlatform.INSTANCE.clearNonClearableContainerItems(blockEntity,tag); } final LevelChunk chunk = resultingAccelerator.getChunk(SectionPos.blockToSectionCoord(newPos.getX()), SectionPos.blockToSectionCoord(newPos.getZ())); diff --git a/common/src/main/java/dev/ryanhcode/sable/platform/SableAssemblyPlatform.java b/common/src/main/java/dev/ryanhcode/sable/platform/SableAssemblyPlatform.java index 9ffa4345..48efb894 100644 --- a/common/src/main/java/dev/ryanhcode/sable/platform/SableAssemblyPlatform.java +++ b/common/src/main/java/dev/ryanhcode/sable/platform/SableAssemblyPlatform.java @@ -1,6 +1,8 @@ package dev.ryanhcode.sable.platform; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal @@ -8,4 +10,6 @@ public interface SableAssemblyPlatform { SableAssemblyPlatform INSTANCE = SablePlatformUtil.load(SableAssemblyPlatform.class); void setIgnoreOnPlace(final Level level, final boolean ignore); + + void clearNonClearableContainerItems(final BlockEntity blockEntity,final CompoundTag tag); } diff --git a/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableAssemblyPlatformImpl.java b/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableAssemblyPlatformImpl.java index d9c97a7f..1e174bdc 100644 --- a/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableAssemblyPlatformImpl.java +++ b/fabric/src/main/java/dev/ryanhcode/sable/fabric/platform/SableAssemblyPlatformImpl.java @@ -2,7 +2,9 @@ import dev.ryanhcode.sable.fabric.mixinterface.LevelExtension; import dev.ryanhcode.sable.platform.SableAssemblyPlatform; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal @@ -12,4 +14,16 @@ public class SableAssemblyPlatformImpl implements SableAssemblyPlatform { public void setIgnoreOnPlace(final Level level, final boolean ignore) { ((LevelExtension) level).sable$setIgnoreOnPlace(ignore); } + + @Override + public void clearNonClearableContainerItems(final BlockEntity blockEntity,final CompoundTag tag) { + try { + final Level level = blockEntity.getLevel(); + if (level == null) return; + final String id = tag.getString("id"); + final CompoundTag newTag = new CompoundTag(); + newTag.putString("id", id); + blockEntity.loadWithComponents(newTag, level.registryAccess()); + } catch (final Exception ignored) {} + } } diff --git a/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableAssemblyPlatformImpl.java b/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableAssemblyPlatformImpl.java index 176ccca5..1894cbb1 100644 --- a/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableAssemblyPlatformImpl.java +++ b/neoforge/src/main/java/dev/ryanhcode/sable/neoforge/platform/SableAssemblyPlatformImpl.java @@ -1,7 +1,9 @@ package dev.ryanhcode.sable.neoforge.platform; import dev.ryanhcode.sable.platform.SableAssemblyPlatform; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal @@ -11,4 +13,16 @@ public class SableAssemblyPlatformImpl implements SableAssemblyPlatform { public void setIgnoreOnPlace(final Level level, final boolean ignore) { level.captureBlockSnapshots = ignore; } + + @Override + public void clearNonClearableContainerItems(final BlockEntity blockEntity,final CompoundTag tag) { + try { + final Level level = blockEntity.getLevel(); + if (level == null) return; + final String id = tag.getString("id"); + final CompoundTag newTag = new CompoundTag(); + newTag.putString("id", id); + blockEntity.loadWithComponents(newTag, level.registryAccess()); + } catch (final Exception ignored) {} + } }