Merge remote-tracking branch 'origin/1.20' into 1.21.1

This commit is contained in:
embeddedt 2024-08-24 16:34:59 -04:00
commit 523cb97276
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 28 additions and 63 deletions

View File

@ -1,5 +1,6 @@
package org.embeddedt.modernfix.blockstate; package org.embeddedt.modernfix.blockstate;
import com.google.common.collect.Iterators;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.Property;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -96,42 +97,51 @@ public class FakeStateMap<S> implements Map<Map<Property<?>, Comparable<?>>, S>
this.usedSlots = 0; this.usedSlots = 0;
} }
private <T> List<T> asList(T... array) {
var list = Arrays.asList(array);
if(usedSlots < array.length) {
list = list.subList(0, usedSlots);
}
return list;
}
@NotNull @NotNull
@Override @Override
public Set<Map<Property<?>, Comparable<?>>> keySet() { public Set<Map<Property<?>, Comparable<?>>> keySet() {
throw new UnsupportedOperationException(); return new AbstractSet<>() {
@Override
public Iterator<Map<Property<?>, Comparable<?>>> iterator() {
return keys.length == usedSlots ? Iterators.forArray(keys) : asList(keys).iterator();
}
@Override
public int size() {
return usedSlots;
}
};
} }
@NotNull @NotNull
@Override @Override
public Collection<S> values() { public Collection<S> values() {
throw new UnsupportedOperationException(); return (Collection<S>)asList(values);
} }
@NotNull @NotNull
@Override @Override
public Set<Entry<Map<Property<?>, Comparable<?>>, S>> entrySet() { public Set<Entry<Map<Property<?>, Comparable<?>>, S>> entrySet() {
return new Set<Entry<Map<Property<?>, Comparable<?>>, S>>() { return new AbstractSet<>() {
@Override @Override
public int size() { public int size() {
return usedSlots; return usedSlots;
} }
@Override
public boolean isEmpty() {
return FakeStateMap.this.isEmpty();
}
@Override
public boolean contains(Object o) {
throw new UnsupportedOperationException();
}
@NotNull @NotNull
@Override @Override
public Iterator<Entry<Map<Property<?>, Comparable<?>>, S>> iterator() { public Iterator<Entry<Map<Property<?>, Comparable<?>>, S>> iterator() {
return new Iterator<Entry<Map<Property<?>, Comparable<?>>, S>>() { return new Iterator<>() {
int currentIdx = 0; int currentIdx = 0;
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return currentIdx < usedSlots; return currentIdx < usedSlots;
@ -139,61 +149,14 @@ public class FakeStateMap<S> implements Map<Map<Property<?>, Comparable<?>>, S>
@Override @Override
public Entry<Map<Property<?>, Comparable<?>>, S> next() { public Entry<Map<Property<?>, Comparable<?>>, S> next() {
if(currentIdx >= usedSlots) if (currentIdx >= usedSlots)
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
Entry<Map<Property<?>, Comparable<?>>, S> entry = new AbstractMap.SimpleImmutableEntry<>(keys[currentIdx], (S)values[currentIdx]); Entry<Map<Property<?>, Comparable<?>>, S> entry = new AbstractMap.SimpleImmutableEntry<>(keys[currentIdx], (S) values[currentIdx]);
currentIdx++; currentIdx++;
return entry; return entry;
} }
}; };
} }
@NotNull
@Override
public Object[] toArray() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public <T> T[] toArray(@NotNull T[] ts) {
throw new UnsupportedOperationException();
}
@Override
public boolean add(Entry<Map<Property<?>, 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<? extends Entry<Map<Property<?>, 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();
}
}; };
} }
} }

View File

@ -1,6 +1,7 @@
package org.embeddedt.modernfix.common.mixin.bugfix.paper_chunk_patches; package org.embeddedt.modernfix.common.mixin.bugfix.paper_chunk_patches;
import net.minecraft.util.SortedArraySet; import net.minecraft.util.SortedArraySet;
import org.embeddedt.modernfix.annotation.RequiresMod;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@ -9,6 +10,7 @@ import java.util.Arrays;
import java.util.function.Predicate; import java.util.function.Predicate;
@Mixin(SortedArraySet.class) @Mixin(SortedArraySet.class)
@RequiresMod("!moonrise")
public abstract class SortedArraySetMixin<T> extends AbstractSet<T> { public abstract class SortedArraySetMixin<T> extends AbstractSet<T> {
@Shadow private int size; @Shadow private int size;