From 3a2771c5c0823fdd53cb972c638b7933a6c8a21d Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 27 Feb 2021 18:24:48 -0800 Subject: [PATCH] Fix issue restricting the maximum size of contraptions. --- .../structureMovement/Contraption.java | 8 +- .../foundation/utility/UniqueLinkedList.java | 89 +++++++++++++++++++ 2 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/UniqueLinkedList.java diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index fb5c044d4..09fbc01f4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -21,6 +21,7 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; +import com.simibubi.create.foundation.utility.*; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -53,11 +54,6 @@ import com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.fluid.CombinedTankWrapper; import com.simibubi.create.foundation.render.backend.light.EmptyLighter; -import com.simibubi.create.foundation.utility.BlockFace; -import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.NBTHelper; -import com.simibubi.create.foundation.utility.NBTProcessors; -import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld; import net.minecraft.block.AbstractButtonBlock; @@ -178,7 +174,7 @@ public abstract class Contraption { public boolean searchMovedStructure(World world, BlockPos pos, @Nullable Direction forcedDirection) throws AssemblyException { initialPassengers.clear(); - Queue frontier = new LinkedList<>(); + Queue frontier = new UniqueLinkedList<>(); Set visited = new HashSet<>(); anchor = pos; diff --git a/src/main/java/com/simibubi/create/foundation/utility/UniqueLinkedList.java b/src/main/java/com/simibubi/create/foundation/utility/UniqueLinkedList.java new file mode 100644 index 000000000..d30c3badb --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/UniqueLinkedList.java @@ -0,0 +1,89 @@ +package com.simibubi.create.foundation.utility; + +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +public class UniqueLinkedList extends LinkedList { + private final HashSet contained = new HashSet<>(); + + @Override + public boolean contains(Object o) { + return contained.contains(o); + } + + @Override + public E poll() { + E e = super.poll(); + contained.remove(e); + return e; + } + + @Override + public boolean add(E e) { + if (contained.add(e)) return super.add(e); + else return false; + } + + @Override + public void add(int index, E element) { + if (contained.add(element)) super.add(index, element); + } + + @Override + public void addFirst(E e) { + if (contained.add(e)) super.addFirst(e); + } + + @Override + public void addLast(E e) { + if (contained.add(e)) super.addLast(e); + } + + @Override + public boolean addAll(Collection c) { + List filtered = c.stream().filter(it -> !contained.contains(it)).collect(Collectors.toList()); + return super.addAll(filtered); + } + + @Override + public boolean addAll(int index, Collection c) { + List filtered = c.stream().filter(it -> !contained.contains(it)).collect(Collectors.toList()); + return super.addAll(index, filtered); + } + + @Override + public boolean remove(Object o) { + contained.remove(o); + return super.remove(o); + } + + @Override + public E remove(int index) { + E e = super.remove(index); + contained.remove(e); + return e; + } + + @Override + public E removeFirst() { + E e = super.removeFirst(); + contained.remove(e); + return e; + } + + @Override + public E removeLast() { + E e = super.removeLast(); + contained.remove(e); + return e; + } + + @Override + public void clear() { + super.clear(); + contained.clear(); + } +}