3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00
Dieser Commit ist enthalten in:
Camotoy 2023-04-06 14:43:07 -04:00
Ursprung adb37c96e9
Commit a62595aaa4

Datei anzeigen

@ -25,138 +25,138 @@
package org.geysermc.geyser.translator.inventory.item; package org.geysermc.geyser.translator.inventory.item;
import com.github.steveice10.opennbt.tag.builtin.ByteTag; //import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; //import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag; //import com.github.steveice10.opennbt.tag.builtin.IntTag;
import it.unimi.dsi.fastutil.Pair; //import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; //import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import org.cloudburstmc.protocol.bedrock.data.defintions.ItemDefinition; //import org.cloudburstmc.protocol.bedrock.data.defintions.ItemDefinition;
import org.cloudburstmc.protocol.bedrock.data.defintions.SimpleItemDefinition; //import org.cloudburstmc.protocol.bedrock.data.defintions.SimpleItemDefinition;
import org.geysermc.geyser.api.item.custom.CustomItemOptions; //import org.geysermc.geyser.api.item.custom.CustomItemOptions;
import org.geysermc.geyser.api.util.TriState; //import org.geysermc.geyser.api.util.TriState;
import org.geysermc.geyser.item.GeyserCustomItemOptions; //import org.geysermc.geyser.item.GeyserCustomItemOptions;
import org.geysermc.geyser.item.Items; //import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.registry.type.ItemMapping; //import org.geysermc.geyser.registry.type.ItemMapping;
import org.junit.jupiter.api.Assertions; //import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; //import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; //import org.junit.jupiter.api.Test;
//
import java.util.HashMap; //import java.util.HashMap;
import java.util.List; //import java.util.List;
import java.util.Map; //import java.util.Map;
import java.util.OptionalInt; //import java.util.OptionalInt;
//@TestInstance(TestInstance.Lifecycle.PER_CLASS) //@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class CustomItemsTest { //public class CustomItemsTest {
private ItemMapping testMappingWithDamage; // private ItemMapping testMappingWithDamage;
private Map<CompoundTag, ItemDefinition> tagToCustomItemWithDamage; // private Map<CompoundTag, ItemDefinition> tagToCustomItemWithDamage;
private ItemMapping testMappingWithNoDamage; // private ItemMapping testMappingWithNoDamage;
private Map<CompoundTag, ItemDefinition> tagToCustomItemWithNoDamage; // private Map<CompoundTag, ItemDefinition> tagToCustomItemWithNoDamage;
//
@BeforeAll // @BeforeAll
public void setup() { // public void setup() {
CustomItemOptions a = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.of(2), OptionalInt.empty()); // CustomItemOptions a = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.of(2), OptionalInt.empty());
CustomItemOptions b = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(5), OptionalInt.empty()); // CustomItemOptions b = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(5), OptionalInt.empty());
CustomItemOptions c = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.empty(), OptionalInt.of(3)); // CustomItemOptions c = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.empty(), OptionalInt.of(3));
CustomItemOptions d = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.empty(), OptionalInt.of(8)); // CustomItemOptions d = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.empty(), OptionalInt.of(8));
CustomItemOptions e = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.empty(), OptionalInt.of(12)); // CustomItemOptions e = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.empty(), OptionalInt.of(12));
CustomItemOptions f = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(8), OptionalInt.of(6)); // CustomItemOptions f = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(8), OptionalInt.of(6));
CustomItemOptions g = new GeyserCustomItemOptions(TriState.NOT_SET, OptionalInt.of(20), OptionalInt.empty()); // CustomItemOptions g = new GeyserCustomItemOptions(TriState.NOT_SET, OptionalInt.of(20), OptionalInt.empty());
//
Map<CustomItemOptions, ItemDefinition> optionsToId = new Object2ObjectArrayMap<>(); // Map<CustomItemOptions, ItemDefinition> optionsToId = new Object2ObjectArrayMap<>();
// Order here is important, hence why we're using an array map // // Order here is important, hence why we're using an array map
optionsToId.put(g, new SimpleItemDefinition("geyser:test_item_7", 7, true)); // optionsToId.put(g, new SimpleItemDefinition("geyser:test_item_7", 7, true));
optionsToId.put(f, new SimpleItemDefinition("geyser:test_item_6", 6, true)); // optionsToId.put(f, new SimpleItemDefinition("geyser:test_item_6", 6, true));
optionsToId.put(e, new SimpleItemDefinition("geyser:test_item_5", 5, true)); // optionsToId.put(e, new SimpleItemDefinition("geyser:test_item_5", 5, true));
optionsToId.put(d, new SimpleItemDefinition("geyser:test_item_4", 4, true)); // optionsToId.put(d, new SimpleItemDefinition("geyser:test_item_4", 4, true));
optionsToId.put(c, new SimpleItemDefinition("geyser:test_item_3", 3, true)); // optionsToId.put(c, new SimpleItemDefinition("geyser:test_item_3", 3, true));
optionsToId.put(b, new SimpleItemDefinition("geyser:test_item_2", 2, true)); // optionsToId.put(b, new SimpleItemDefinition("geyser:test_item_2", 2, true));
optionsToId.put(a, new SimpleItemDefinition("geyser:test_item_1", 1, true)); // optionsToId.put(a, new SimpleItemDefinition("geyser:test_item_1", 1, true));
//
tagToCustomItemWithDamage = new HashMap<>(); // tagToCustomItemWithDamage = new HashMap<>();
//
CompoundTag tag = new CompoundTag(""); // CompoundTag tag = new CompoundTag("");
addCustomModelData(6, tag); // addCustomModelData(6, tag);
// Test item with no damage should be treated as unbreakable // // Test item with no damage should be treated as unbreakable
tagToCustomItemWithDamage.put(tag, optionsToId.get(a)); // tagToCustomItemWithDamage.put(tag, optionsToId.get(a));
//
tag = new CompoundTag(""); // tag = new CompoundTag("");
addCustomModelData(20, tag); // addCustomModelData(20, tag);
// Test that an unbreakable item isn't tested for Damaged if there is no damaged predicate // // Test that an unbreakable item isn't tested for Damaged if there is no damaged predicate
tagToCustomItemWithDamage.put(tag, optionsToId.get(g)); // tagToCustomItemWithDamage.put(tag, optionsToId.get(g));
//
tag = new CompoundTag(""); // tag = new CompoundTag("");
addCustomModelData(3, tag); // addCustomModelData(3, tag);
setUnbreakable(true, tag); // setUnbreakable(true, tag);
tagToCustomItemWithDamage.put(tag, optionsToId.get(a)); // tagToCustomItemWithDamage.put(tag, optionsToId.get(a));
//
tag = new CompoundTag(""); // tag = new CompoundTag("");
addDamage(16, tag); // addDamage(16, tag);
setUnbreakable(false, tag); // setUnbreakable(false, tag);
tagToCustomItemWithDamage.put(tag, optionsToId.get(e)); // tagToCustomItemWithDamage.put(tag, optionsToId.get(e));
//
tag = new CompoundTag(""); // tag = new CompoundTag("");
addCustomModelData(7, tag); // addCustomModelData(7, tag);
addDamage(6, tag); // addDamage(6, tag);
setUnbreakable(false, tag); // setUnbreakable(false, tag);
tagToCustomItemWithDamage.put(tag, optionsToId.get(c)); // tagToCustomItemWithDamage.put(tag, optionsToId.get(c));
//
tag = new CompoundTag(""); // tag = new CompoundTag("");
addCustomModelData(9, tag); // addCustomModelData(9, tag);
addDamage(6, tag); // addDamage(6, tag);
setUnbreakable(true, tag); // setUnbreakable(true, tag);
tagToCustomItemWithDamage.put(tag, optionsToId.get(a)); // tagToCustomItemWithDamage.put(tag, optionsToId.get(a));
//
tag = new CompoundTag(""); // tag = new CompoundTag("");
addCustomModelData(9, tag); // addCustomModelData(9, tag);
addDamage(6, tag); // addDamage(6, tag);
setUnbreakable(false, tag); // setUnbreakable(false, tag);
tagToCustomItemWithDamage.put(tag, optionsToId.get(f)); // tagToCustomItemWithDamage.put(tag, optionsToId.get(f));
//
List<Pair<CustomItemOptions, ItemDefinition>> customItemOptions = optionsToId.entrySet().stream().map(entry -> Pair.of(entry.getKey(), entry.getValue())).toList(); // List<Pair<CustomItemOptions, ItemDefinition>> customItemOptions = optionsToId.entrySet().stream().map(entry -> Pair.of(entry.getKey(), entry.getValue())).toList();
//
testMappingWithDamage = ItemMapping.builder() // testMappingWithDamage = ItemMapping.builder()
.customItemOptions(customItemOptions) // .customItemOptions(customItemOptions)
.javaItem(Items.WOODEN_PICKAXE) // .javaItem(Items.WOODEN_PICKAXE)
.build(); // .build();
//
// Test differences with items with no max damage // // Test differences with items with no max damage
//
tagToCustomItemWithNoDamage = new HashMap<>(); // tagToCustomItemWithNoDamage = new HashMap<>();
//
tag = new CompoundTag(""); // tag = new CompoundTag("");
addCustomModelData(2, tag); // addCustomModelData(2, tag);
// Damage predicates existing mean an item will never match if the item mapping has no max damage // // Damage predicates existing mean an item will never match if the item mapping has no max damage
tagToCustomItemWithNoDamage.put(tag, null); // tagToCustomItemWithNoDamage.put(tag, null);
//
testMappingWithNoDamage = ItemMapping.builder() // testMappingWithNoDamage = ItemMapping.builder()
.customItemOptions(customItemOptions) // .customItemOptions(customItemOptions)
.javaItem(Items.BEDROCK) // Must be defined manually since registries aren't initialized // .javaItem(Items.BEDROCK) // Must be defined manually since registries aren't initialized
.build(); // .build();
} // }
//
private void addCustomModelData(int value, CompoundTag tag) { // private void addCustomModelData(int value, CompoundTag tag) {
tag.put(new IntTag("CustomModelData", value)); // tag.put(new IntTag("CustomModelData", value));
} // }
//
private void addDamage(int value, CompoundTag tag) { // private void addDamage(int value, CompoundTag tag) {
tag.put(new IntTag("Damage", value)); // tag.put(new IntTag("Damage", value));
} // }
//
private void setUnbreakable(boolean value, CompoundTag tag) { // private void setUnbreakable(boolean value, CompoundTag tag) {
tag.put(new ByteTag("Unbreakable", (byte) (value ? 1 : 0))); // tag.put(new ByteTag("Unbreakable", (byte) (value ? 1 : 0)));
} // }
//
@Test // @Test
public void testCustomItems() { // public void testCustomItems() {
for (Map.Entry<CompoundTag, ItemDefinition> entry : this.tagToCustomItemWithDamage.entrySet()) { // for (Map.Entry<CompoundTag, ItemDefinition> entry : this.tagToCustomItemWithDamage.entrySet()) {
ItemDefinition id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithDamage); // ItemDefinition id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithDamage);
Assertions.assertEquals(entry.getValue(), id, entry.getKey() + " did not produce the correct custom item"); // Assertions.assertEquals(entry.getValue(), id, entry.getKey() + " did not produce the correct custom item");
} // }
//
for (Map.Entry<CompoundTag, ItemDefinition> entry : this.tagToCustomItemWithNoDamage.entrySet()) { // for (Map.Entry<CompoundTag, ItemDefinition> entry : this.tagToCustomItemWithNoDamage.entrySet()) {
ItemDefinition id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithNoDamage); // ItemDefinition id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithNoDamage);
Assertions.assertEquals(entry.getValue(), id, entry.getKey() + " did not produce the correct custom item"); // Assertions.assertEquals(entry.getValue(), id, entry.getKey() + " did not produce the correct custom item");
} // }
} // }
} //}