Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-27 08:30:10 +01:00
Ursprung
418357d8eb
Commit
38af6f883b
@ -30,7 +30,6 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||||
import com.viaversion.viaversion.libs.fastutil.ints.IntIntPair;
|
|
||||||
import com.viaversion.viaversion.libs.fastutil.objects.ObjectIterator;
|
import com.viaversion.viaversion.libs.fastutil.objects.ObjectIterator;
|
||||||
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
||||||
import com.viaversion.viaversion.util.ComponentUtil;
|
import com.viaversion.viaversion.util.ComponentUtil;
|
||||||
@ -86,20 +85,20 @@ public class StructuredEnchantmentRewriter {
|
|||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
||||||
final ObjectIterator<Int2IntMap.Entry> iterator = enchantments.enchantments().int2IntEntrySet().iterator();
|
final ObjectIterator<Int2IntMap.Entry> iterator = enchantments.enchantments().int2IntEntrySet().iterator();
|
||||||
final List<IntIntPair> updatedIds = new ArrayList<>();
|
final List<PendingIdChange> updatedIds = new ArrayList<>();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final Int2IntMap.Entry entry = iterator.next();
|
final Int2IntMap.Entry entry = iterator.next();
|
||||||
final int id = entry.getIntKey();
|
final int id = entry.getIntKey();
|
||||||
final int mappedId = rewriteFunction.rewrite(id);
|
final int mappedId = rewriteFunction.rewrite(id);
|
||||||
|
final int level = entry.getIntValue();
|
||||||
if (mappedId != -1) {
|
if (mappedId != -1) {
|
||||||
if (rewriteIds) {
|
if (rewriteIds) {
|
||||||
// Update the map after to iteration to preserve the current ids before possibly saving the original, avoid CME
|
// Update the map after to iteration to preserve the current ids before possibly saving the original, avoid CME
|
||||||
updatedIds.add(IntIntPair.of(id, mappedId));
|
updatedIds.add(new PendingIdChange(id, mappedId, level));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int level = entry.getIntValue();
|
|
||||||
final Tag description = descriptionSupplier.get(id, level);
|
final Tag description = descriptionSupplier.get(id, level);
|
||||||
if (description != null) {
|
if (description != null) {
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
@ -113,9 +112,12 @@ public class StructuredEnchantmentRewriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final IntIntPair pair : updatedIds) {
|
// Remove all first, then add the new ones
|
||||||
final int level = enchantments.enchantments().remove(pair.firstInt());
|
for (final PendingIdChange change : updatedIds) {
|
||||||
enchantments.add(pair.secondInt(), level);
|
enchantments.remove(change.id());
|
||||||
|
}
|
||||||
|
for (final PendingIdChange change : updatedIds) {
|
||||||
|
enchantments.add(change.mappedId(), change.level());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loreToAdd.isEmpty()) {
|
if (loreToAdd.isEmpty()) {
|
||||||
@ -198,4 +200,7 @@ public class StructuredEnchantmentRewriter {
|
|||||||
|
|
||||||
Tag get(int id, int level);
|
Tag get(int id, int level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record PendingIdChange(int id, int mappedId, int level) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ import com.viaversion.viaversion.rewriter.BlockRewriter;
|
|||||||
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.downgradeItemData;
|
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.downgradeItemData;
|
||||||
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.updateItemData;
|
import static com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21.updateItemData;
|
||||||
@ -186,7 +187,8 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Enchantments enchantments = enchantmentsData.value();
|
final Enchantments enchantments = enchantmentsData.value();
|
||||||
for (final Int2IntMap.Entry entry : new ArrayList<>(enchantments.enchantments().int2IntEntrySet())) {
|
final List<PendingIdChange> updatedIds = new ArrayList<>();
|
||||||
|
for (final Int2IntMap.Entry entry : enchantments.enchantments().int2IntEntrySet()) {
|
||||||
final int id = entry.getIntKey();
|
final int id = entry.getIntKey();
|
||||||
final String enchantmentKey = Enchantments1_20_5.idToKey(id);
|
final String enchantmentKey = Enchantments1_20_5.idToKey(id);
|
||||||
if (enchantmentKey == null) {
|
if (enchantmentKey == null) {
|
||||||
@ -195,9 +197,20 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe
|
|||||||
|
|
||||||
final int mappedId = storage.enchantments().keyToId(enchantmentKey);
|
final int mappedId = storage.enchantments().keyToId(enchantmentKey);
|
||||||
if (id != mappedId) {
|
if (id != mappedId) {
|
||||||
enchantments.enchantments().remove(id);
|
final int level = entry.getIntValue();
|
||||||
enchantments.enchantments().put(mappedId, entry.getIntValue());
|
updatedIds.add(new PendingIdChange(id, mappedId, level));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove first, then add updated entries
|
||||||
|
for (final PendingIdChange change : updatedIds) {
|
||||||
|
enchantments.remove(change.id);
|
||||||
|
}
|
||||||
|
for (final PendingIdChange change : updatedIds) {
|
||||||
|
enchantments.add(change.mappedId, change.level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record PendingIdChange(int id, int mappedId, int level) {
|
||||||
}
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren