diff --git a/REPAIRED.md b/REPAIRED.md index 95e6f78..a136a7d 100644 --- a/REPAIRED.md +++ b/REPAIRED.md @@ -77,3 +77,4 @@ Unticked checkboxes indicate the issue is fixed in dev but not released yet. - [x] [Fix a dupe when breaking a Postbox while its menu is open](https://github.com/Creators-of-Create/Create/pull/9802) (Thanks, techno-sam!) - [x] [Fix a dupe with the Schematicannon ignoring BlockEntity item requirements](https://github.com/Creators-of-Create/Create/issues/9511) (Thanks, IThundxr!) - [x] [Fix a dupe with the Deployer](https://github.com/Creators-of-Create/Create/commit/dd133f667969870dd6e9b96395097ac93cd91ced) (Thanks, IThundxr!) +- [ ] [Fix a dupe when making a contraption with attached blocks to attached blocks](https://github.com/Creators-of-Create/Create/pull/9399) (Thanks, Allmoz!) diff --git a/src/main/java/ch/voidlee/repair/mixin/bug_fixes/dupes/ContraptionMixin.java b/src/main/java/ch/voidlee/repair/mixin/bug_fixes/dupes/ContraptionMixin.java new file mode 100644 index 0000000..d8e1175 --- /dev/null +++ b/src/main/java/ch/voidlee/repair/mixin/bug_fixes/dupes/ContraptionMixin.java @@ -0,0 +1,33 @@ +package ch.voidlee.repair.mixin.bug_fixes.dupes; + +import com.simibubi.create.content.contraptions.Contraption; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.*; + +// https://github.com/Creators-of-Create/Create/pull/9399 +@Mixin(Contraption.class) +public abstract class ContraptionMixin { + @Shadow(remap = false) + protected Map blocks; + + @Inject(method = "()V", at = @At("TAIL"), remap = false) + private void create_repair$blocksStoredInLinkedHashMap(CallbackInfo ci) { + this.blocks = new LinkedHashMap<>(this.blocks); + } + + @Inject(method = "removeBlocksFromWorld", at = @At("HEAD"), remap = false) + private void create_repair$iterateBlocksInReverse(Level world, BlockPos offset, CallbackInfo ci) { + List> entries = new ArrayList<>(this.blocks.entrySet()); + Collections.reverse(entries); + this.blocks.clear(); + entries.forEach(e -> this.blocks.put(e.getKey(), e.getValue())); + } +} \ No newline at end of file diff --git a/src/main/resources/mixins.create_repair.json b/src/main/resources/mixins.create_repair.json index f9f7a5a..c517401 100644 --- a/src/main/resources/mixins.create_repair.json +++ b/src/main/resources/mixins.create_repair.json @@ -44,6 +44,7 @@ "bug_fixes.clearable.StockTickerBlockEntityMixin", "bug_fixes.clearable.ThresholdSwitchBlockEntityMixin", "bug_fixes.clearable.TrackObserverBlockEntityMixin", + "bug_fixes.dupes.ContraptionMixin", "bug_fixes.dupes.DeployerNotifyUpdateMixin", "bug_fixes.dupes.PostboxBlockEntityMixin", "bug_fixes.dupes.SchematicPrinterMixin",