mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 08:57:39 +01:00
Update wolf textures again, add utility methods
This commit is contained in:
parent
228689f181
commit
c743c20334
@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.util.Unit;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class StructuredDataContainer {
|
||||
@ -69,6 +70,26 @@ public final class StructuredDataContainer {
|
||||
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) {
|
||||
final int id = serializerId(key);
|
||||
if (id != -1) {
|
||||
|
@ -62,6 +62,10 @@ public final class Enchantments {
|
||||
this.showInTooltip = showInTooltip;
|
||||
}
|
||||
|
||||
public Enchantments(final boolean showInTooltip) {
|
||||
this(new Int2IntOpenHashMap(), showInTooltip);
|
||||
}
|
||||
|
||||
public Int2IntMap enchantments() {
|
||||
return enchantments;
|
||||
}
|
||||
@ -73,4 +77,20 @@ public final class Enchantments {
|
||||
public boolean 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);
|
||||
}
|
||||
}
|
||||
|
@ -116,9 +116,9 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
||||
final PacketWrapper wolfVariantsPacket = wrapper.create(ClientboundConfigurationPackets1_20_5.REGISTRY_DATA);
|
||||
wolfVariantsPacket.write(Type.STRING, "minecraft:wolf_variant");
|
||||
final CompoundTag paleWolf = new CompoundTag();
|
||||
paleWolf.putString("wild_texture", "textures/entity/wolf/wolf.png");
|
||||
paleWolf.putString("tame_texture", "textures/entity/wolf/wolf_tame.png");
|
||||
paleWolf.putString("angry_texture", "textures/entity/wolf/wolf_angry.png");
|
||||
paleWolf.putString("wild_texture", "entity/wolf/wolf");
|
||||
paleWolf.putString("tame_texture", "entity/wolf/wolf_tame");
|
||||
paleWolf.putString("angry_texture", "entity/wolf/wolf_angry");
|
||||
paleWolf.put("biomes", new ListTag<>(StringTag.class));
|
||||
wolfVariantsPacket.write(Type.REGISTRY_ENTRY_ARRAY, new RegistryEntry[]{new RegistryEntry("minecraft:pale", paleWolf)});
|
||||
wolfVariantsPacket.send(Protocol1_20_5To1_20_3.class);
|
||||
|
Loading…
Reference in New Issue
Block a user