3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Update wolf textures again, add utility methods

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-03 20:07:16 +02:00
Ursprung 228689f181
Commit c743c20334
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
3 geänderte Dateien mit 44 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.Unit; import com.viaversion.viaversion.util.Unit;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public final class StructuredDataContainer { public final class StructuredDataContainer {
@ -69,6 +70,26 @@ public final class StructuredDataContainer {
return data != null && data.isPresent() ? data : null; return data != null && data.isPresent() ? data : null;
} }
/**
* Returns structured data by id if not empty, or creates it.
*
* @param key serializer id
* @param mappingFunction function to create structured data if not present
* @param <T> data type
* @return structured data if not empty
*/
public <T> StructuredData<T> computeIfAbsent(final StructuredDataKey<T> key, final Function<StructuredDataKey<T>, T> mappingFunction) {
final StructuredData<T> data = this.getNonEmpty(key);
if (data != null) {
return data;
}
final int id = serializerId(key);
final StructuredData<T> empty = StructuredData.of(key, mappingFunction.apply(key), id);
this.data.put(key, empty);
return empty;
}
public <T> void set(final StructuredDataKey<T> key, final T value) { public <T> void set(final StructuredDataKey<T> key, final T value) {
final int id = serializerId(key); final int id = serializerId(key);
if (id != -1) { if (id != -1) {

Datei anzeigen

@ -62,6 +62,10 @@ public final class Enchantments {
this.showInTooltip = showInTooltip; this.showInTooltip = showInTooltip;
} }
public Enchantments(final boolean showInTooltip) {
this(new Int2IntOpenHashMap(), showInTooltip);
}
public Int2IntMap enchantments() { public Int2IntMap enchantments() {
return enchantments; return enchantments;
} }
@ -73,4 +77,20 @@ public final class Enchantments {
public boolean showInTooltip() { public boolean showInTooltip() {
return showInTooltip; return showInTooltip;
} }
public void add(final int id, final int level) {
enchantments.put(id, level);
}
public void remove(final int id) {
enchantments.remove(id);
}
public void clear() {
enchantments.clear();
}
public int getLevel(final int id) {
return enchantments.getOrDefault(id, -1);
}
} }

Datei anzeigen

@ -116,9 +116,9 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
final PacketWrapper wolfVariantsPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA); final PacketWrapper wolfVariantsPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
wolfVariantsPacket.write(Type.STRING, "minecraft:wolf_variant"); wolfVariantsPacket.write(Type.STRING, "minecraft:wolf_variant");
final CompoundTag paleWolf = new CompoundTag(); final CompoundTag paleWolf = new CompoundTag();
paleWolf.putString("wild_texture", "textures/entity/wolf/wolf.png"); paleWolf.putString("wild_texture", "entity/wolf/wolf");
paleWolf.putString("tame_texture", "textures/entity/wolf/wolf_tame.png"); paleWolf.putString("tame_texture", "entity/wolf/wolf_tame");
paleWolf.putString("angry_texture", "textures/entity/wolf/wolf_angry.png"); paleWolf.putString("angry_texture", "entity/wolf/wolf_angry");
paleWolf.put("biomes", new ListTag<>(StringTag.class)); paleWolf.put("biomes", new ListTag<>(StringTag.class));
wolfVariantsPacket.write(Type.REGISTRY_ENTRY_ARRAY, new RegistryEntry[]{new RegistryEntry("minecraft:pale", paleWolf)}); wolfVariantsPacket.write(Type.REGISTRY_ENTRY_ARRAY, new RegistryEntry[]{new RegistryEntry("minecraft:pale", paleWolf)});
wolfVariantsPacket.send(Protocol1_20_5To1_20_3.class); wolfVariantsPacket.send(Protocol1_20_5To1_20_3.class);