diff --git a/common/src/main/java/org/embeddedt/modernfix/blockstate/FakeStateMap.java b/common/src/main/java/org/embeddedt/modernfix/blockstate/FakeStateMap.java index 7cc8f22cc..a31aac0b1 100644 --- a/common/src/main/java/org/embeddedt/modernfix/blockstate/FakeStateMap.java +++ b/common/src/main/java/org/embeddedt/modernfix/blockstate/FakeStateMap.java @@ -1,5 +1,6 @@ package org.embeddedt.modernfix.blockstate; +import com.google.common.collect.Iterators; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.world.level.block.state.properties.Property; import org.jetbrains.annotations.NotNull; @@ -96,42 +97,51 @@ public void clear() { this.usedSlots = 0; } + private List asList(T... array) { + var list = Arrays.asList(array); + if(usedSlots < array.length) { + list = list.subList(0, usedSlots); + } + return list; + } + @NotNull @Override public Set, Comparable>> keySet() { - throw new UnsupportedOperationException(); + return new AbstractSet<>() { + @Override + public Iterator, Comparable>> iterator() { + return keys.length == usedSlots ? Iterators.forArray(keys) : asList(keys).iterator(); + } + + @Override + public int size() { + return usedSlots; + } + }; } @NotNull @Override public Collection values() { - throw new UnsupportedOperationException(); + return (Collection)asList(values); } @NotNull @Override public Set, Comparable>, S>> entrySet() { - return new Set, Comparable>, S>>() { + return new AbstractSet<>() { @Override public int size() { return usedSlots; } - @Override - public boolean isEmpty() { - return FakeStateMap.this.isEmpty(); - } - - @Override - public boolean contains(Object o) { - throw new UnsupportedOperationException(); - } - @NotNull @Override public Iterator, Comparable>, S>> iterator() { - return new Iterator, Comparable>, S>>() { + return new Iterator<>() { int currentIdx = 0; + @Override public boolean hasNext() { return currentIdx < usedSlots; @@ -139,61 +149,14 @@ public boolean hasNext() { @Override public Entry, Comparable>, S> next() { - if(currentIdx >= usedSlots) + if (currentIdx >= usedSlots) throw new IndexOutOfBoundsException(); - Entry, Comparable>, S> entry = new AbstractMap.SimpleImmutableEntry<>(keys[currentIdx], (S)values[currentIdx]); + Entry, Comparable>, S> entry = new AbstractMap.SimpleImmutableEntry<>(keys[currentIdx], (S) values[currentIdx]); currentIdx++; return entry; } }; } - - @NotNull - @Override - public Object[] toArray() { - throw new UnsupportedOperationException(); - } - - @NotNull - @Override - public T[] toArray(@NotNull T[] ts) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean add(Entry, Comparable>, S> mapSEntry) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean containsAll(@NotNull Collection collection) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(@NotNull Collection, Comparable>, S>> collection) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean retainAll(@NotNull Collection collection) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean removeAll(@NotNull Collection collection) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } }; } } diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/SortedArraySetMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/SortedArraySetMixin.java index 0587964f9..cabf4146f 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/SortedArraySetMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/SortedArraySetMixin.java @@ -1,6 +1,7 @@ package org.embeddedt.modernfix.common.mixin.bugfix.paper_chunk_patches; import net.minecraft.util.SortedArraySet; +import org.embeddedt.modernfix.annotation.RequiresMod; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,6 +10,7 @@ import java.util.function.Predicate; @Mixin(SortedArraySet.class) +@RequiresMod("!moonrise") public abstract class SortedArraySetMixin extends AbstractSet { @Shadow private int size;