Skip to content

Commit 993a688

Browse files
committed
Don't store tileId when saving structures.
1 parent f88655d commit 993a688

File tree

8 files changed

+63
-16
lines changed

8 files changed

+63
-16
lines changed

src/main/java/noobanidus/mods/lootr/api/ILootrAPI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ default boolean clearPlayerLoot(ServerPlayer entity) {
5252
*/
5353
@Nullable
5454
MenuProvider getModdedMenu(Level level, UUID id, BlockPos pos, ServerPlayer player, IntSupplier sizeSupplier, Supplier<Component> displaySupplier, LootFiller filler, Supplier<ResourceLocation> tableSupplier, LongSupplier seedSupplier);
55+
56+
boolean isSavingStructure ();
5557
}

src/main/java/noobanidus/mods/lootr/api/LootrAPI.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class LootrAPI {
2222

2323
public static ILootrAPI INSTANCE;
2424

25+
public static boolean isSavingStructure;
26+
2527
public static boolean clearPlayerLoot(ServerPlayer entity) {
2628
return INSTANCE.clearPlayerLoot(entity);
2729
}
@@ -37,4 +39,7 @@ public static MenuProvider getModdedMenu(Level level, UUID id, BlockPos pos, Ser
3739
public static MenuProvider getModdedMenu(Level level, UUID id, BlockPos pos, ServerPlayer player, IntSupplier sizeSupplier, Supplier<Component> displaySupplier, LootFiller filler, Supplier<ResourceLocation> tableSupplier, LongSupplier seedSupplier) {
3840
return INSTANCE.getModdedMenu(level, id, pos, player, sizeSupplier, displaySupplier, filler, tableSupplier, seedSupplier);
3941
}
42+
public static boolean isSavingStructure() {
43+
return INSTANCE.isSavingStructure();
44+
}
4045
}

src/main/java/noobanidus/mods/lootr/block/entities/LootrBarrelBlockEntity.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,14 @@ protected void saveAdditional(CompoundTag compound) {
237237
compound.putLong("specialLootBarrel_seed", seed);
238238
compound.putLong("LootTableSeed", seed);
239239
}
240-
compound.putUUID("tileId", getTileId());
241-
ListTag list = new ListTag();
242-
for (UUID opener : this.openers) {
243-
list.add(NbtUtils.createUUID(opener));
240+
if (!LootrAPI.isSavingStructure()) {
241+
compound.putUUID("tileId", getTileId());
242+
ListTag list = new ListTag();
243+
for (UUID opener : this.openers) {
244+
list.add(NbtUtils.createUUID(opener));
245+
}
246+
compound.put("LootrOpeners", list);
244247
}
245-
compound.put("LootrOpeners", list);
246248
}
247249

248250
@Override

src/main/java/noobanidus/mods/lootr/block/entities/LootrChestBlockEntity.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ protected void saveAdditional(CompoundTag compound) {
143143
compound.putLong("specialLootChest_seed", seed);
144144
compound.putLong("LootTableSeed", seed);
145145
}
146-
compound.putUUID("tileId", getTileId());
147-
ListTag list = new ListTag();
148-
for (UUID opener : this.openers) {
149-
list.add(NbtUtils.createUUID(opener));
146+
if (!LootrAPI.isSavingStructure()) {
147+
compound.putUUID("tileId", getTileId());
148+
ListTag list = new ListTag();
149+
for (UUID opener : this.openers) {
150+
list.add(NbtUtils.createUUID(opener));
151+
}
152+
compound.put("LootrOpeners", list);
150153
}
151-
compound.put("LootrOpeners", list);
152154
}
153155

154156
public static <T extends BlockEntity> void lootrLidAnimateTick(Level pLevel, BlockPos pPos, BlockState pState, T pBlockEntity) {

src/main/java/noobanidus/mods/lootr/block/entities/LootrShulkerBlockEntity.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,14 @@ protected void saveAdditional(CompoundTag compound) {
257257
compound.putLong("specialLootChest_seed", seed);
258258
compound.putLong("LootTableSeed", seed);
259259
}
260-
compound.putUUID("tileId", getTileId());
261-
ListTag list = new ListTag();
262-
for (UUID opener : this.openers) {
263-
list.add(NbtUtils.createUUID(opener));
260+
if (!LootrAPI.isSavingStructure()) {
261+
compound.putUUID("tileId", getTileId());
262+
ListTag list = new ListTag();
263+
for (UUID opener : this.openers) {
264+
list.add(NbtUtils.createUUID(opener));
265+
}
266+
compound.put("LootrOpeners", list);
264267
}
265-
compound.put("LootrOpeners", list);
266268
}
267269

268270
@Override

src/main/java/noobanidus/mods/lootr/impl/LootrAPIImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
1111
import noobanidus.mods.lootr.api.ILootrAPI;
1212
import noobanidus.mods.lootr.api.LootFiller;
13+
import noobanidus.mods.lootr.api.LootrAPI;
14+
import noobanidus.mods.lootr.api.MenuBuilder;
15+
import noobanidus.mods.lootr.config.ConfigManager;
1316
import noobanidus.mods.lootr.data.DataStorage;
1417
import org.jetbrains.annotations.Nullable;
1518

@@ -19,6 +22,7 @@
1922
import java.util.function.Supplier;
2023

2124
public class LootrAPIImpl implements ILootrAPI {
25+
2226
@Override
2327
public boolean clearPlayerLoot(UUID id) {
2428
return DataStorage.clearInventories(id);
@@ -34,4 +38,9 @@ public MenuProvider getModdedMenu(Level level, UUID id, BlockPos pos, ServerPlay
3438
public MenuProvider getModdedMenu(Level level, UUID id, BlockPos pos, ServerPlayer player, IntSupplier sizeSupplier, Supplier<Component> displaySupplier, LootFiller filler, Supplier<ResourceLocation> tableSupplier, LongSupplier seedSupplier) {
3539
return DataStorage.getInventory(level, id, pos, player, sizeSupplier, displaySupplier, filler, tableSupplier, seedSupplier);
3640
}
41+
42+
@Override
43+
public boolean isSavingStructure() {
44+
return LootrAPI.isSavingStructure;
45+
}
3746
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package noobanidus.mods.lootr.mixins;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.Vec3i;
5+
import net.minecraft.world.level.Level;
6+
import net.minecraft.world.level.block.Block;
7+
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
8+
import noobanidus.mods.lootr.api.LootrAPI;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(StructureTemplate.class)
15+
public class MixinStructureTemplate {
16+
@Inject(method="fillFromWorld", at=@At(value="INVOKE", target="Lnet/minecraft/world/level/block/entity/BlockEntity;saveWithId()Lnet/minecraft/nbt/CompoundTag;", shift=At.Shift.BEFORE))
17+
private void LootrInjectStructureSavingStart(Level p_163803_, BlockPos p_163804_, Vec3i p_163805_, boolean p_163806_, Block p_163807_, CallbackInfo ci) {
18+
LootrAPI.isSavingStructure = true;
19+
}
20+
@Inject(method="fillFromWorld", at=@At(value="INVOKE", target="Lnet/minecraft/world/level/block/entity/BlockEntity;saveWithId()Lnet/minecraft/nbt/CompoundTag;", shift=At.Shift.AFTER))
21+
private void LootrInjectStructureSavingStop (Level p_163803_, BlockPos p_163804_, Vec3i p_163805_, boolean p_163806_, Block p_163807_, CallbackInfo ci) {
22+
LootrAPI.isSavingStructure = false;
23+
}
24+
}

src/main/resources/lootr.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"MixinBlockStateBase",
88
"MixinCatSitOnBlockGoal",
99
"MixinEndCityPieces$EndCityPiece",
10-
"MixinLevelChunk"
10+
"MixinLevelChunk",
11+
"MixinStructureTemplate"
1112
],
1213
"client": [
1314
],

0 commit comments

Comments
 (0)