mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
24w12a
This commit is contained in:
parent
5b5c0cb183
commit
ea6ca1d37c
8 changed files with 165 additions and 22 deletions
|
@ -220,9 +220,9 @@ public class MinecraftCodec {
|
|||
}
|
||||
|
||||
public static final PacketCodec CODEC = PacketCodec.builder()
|
||||
.protocolVersion((1 << 30) | 180)
|
||||
.protocolVersion((1 << 30) | 181)
|
||||
.helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES))
|
||||
.minecraftVersion("24w11a")
|
||||
.minecraftVersion("24w12a")
|
||||
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
|
||||
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
|
||||
)
|
||||
|
|
|
@ -20,20 +20,27 @@ public class DataComponentType<T> {
|
|||
private static final List<DataComponentType<?>> VALUES = new ArrayList<>();
|
||||
|
||||
public static final DataComponentType<CompoundTag> CUSTOM_DATA = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
|
||||
public static final IntComponentType MAX_STACK_SIZE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
|
||||
public static final IntComponentType MAX_DAMAGE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
|
||||
public static final IntComponentType DAMAGE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
|
||||
public static final BooleanComponentType UNBREAKABLE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new);
|
||||
public static final DataComponentType<Component> CUSTOM_NAME = new DataComponentType<>(ItemCodecHelper::readComponent, ItemCodecHelper::writeComponent, ObjectDataComponent::new);
|
||||
public static final DataComponentType<List<Component>> LORE = new DataComponentType<>(listReader(ItemCodecHelper::readComponent), listWriter(ItemCodecHelper::writeComponent), ObjectDataComponent::new);
|
||||
public static final IntComponentType RARITY = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
|
||||
public static final DataComponentType<ItemEnchantments> ENCHANTMENTS = new DataComponentType<>(ItemCodecHelper::readItemEnchantments, ItemCodecHelper::writeItemEnchantments, ObjectDataComponent::new);
|
||||
public static final DataComponentType<AdventureModePredicate> CAN_PLACE_ON = new DataComponentType<>(ItemCodecHelper::readAdventureModePredicate, ItemCodecHelper::writeAdventureModePredicate, ObjectDataComponent::new);
|
||||
public static final DataComponentType<AdventureModePredicate> CAN_BREAK = new DataComponentType<>(ItemCodecHelper::readAdventureModePredicate, ItemCodecHelper::writeAdventureModePredicate, ObjectDataComponent::new);
|
||||
public static final DataComponentType<ItemAttributeModifiers> ATTRIBUTE_MODIFIERS = new DataComponentType<>(ItemCodecHelper::readItemAttributeModifiers, ItemCodecHelper::writeItemAttributeModifiers, ObjectDataComponent::new);
|
||||
public static final IntComponentType CUSTOM_MODEL_DATA = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
|
||||
public static final DataComponentType<Void> HIDE_ADDITIONAL_TOOLTIP = new DataComponentType<>((helper, input) -> null, (helper, output, value) -> {}, ObjectDataComponent::new);
|
||||
public static final DataComponentType<Void> HIDE_ADDITIONAL_TOOLTIP = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
|
||||
public static final DataComponentType<Void> HIDE_TOOLTIP = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
|
||||
public static final IntComponentType REPAIR_COST = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
|
||||
public static final DataComponentType<Void> CREATIVE_SLOT_LOCK = new DataComponentType<>((helper, input) -> null, (helper, output, value) -> {}, ObjectDataComponent::new);
|
||||
public static final DataComponentType<Void> CREATIVE_SLOT_LOCK = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
|
||||
public static final BooleanComponentType ENCHANTMENT_GLINT_OVERRIDE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new);
|
||||
public static final DataComponentType<CompoundTag> INTANGIBLE_PROJECTILE = new DataComponentType<>(ItemCodecHelper::readAnyTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
|
||||
public static final DataComponentType<FoodProperties> FOOD = new DataComponentType<>(ItemCodecHelper::readFoodProperties, ItemCodecHelper::writeFoodProperties, ObjectDataComponent::new);
|
||||
public static final DataComponentType<Void> FIRE_RESISTANT = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
|
||||
public static final DataComponentType<ToolData> TOOL = new DataComponentType<>(ItemCodecHelper::readToolData, ItemCodecHelper::writeToolData, ObjectDataComponent::new);
|
||||
public static final DataComponentType<ItemEnchantments> STORED_ENCHANTMENTS = new DataComponentType<>(ItemCodecHelper::readItemEnchantments, ItemCodecHelper::writeItemEnchantments, ObjectDataComponent::new);
|
||||
public static final DataComponentType<DyedItemColor> DYED_COLOR = new DataComponentType<>(ItemCodecHelper::readDyedItemColor, ItemCodecHelper::writeDyedItemColor, ObjectDataComponent::new);
|
||||
public static final IntComponentType MAP_COLOR = new IntComponentType((helper, input) -> input.readInt(), (helper, output, value) -> output.writeInt(value), IntDataComponent::new);
|
||||
|
@ -146,6 +153,14 @@ public class DataComponentType<T> {
|
|||
};
|
||||
}
|
||||
|
||||
private static Reader<Void> unitReader() {
|
||||
return (helper, input) -> null;
|
||||
}
|
||||
|
||||
private static Writer<Void> unitWriter() {
|
||||
return (helper, output, value) -> {};
|
||||
}
|
||||
|
||||
public static DataComponentType<?> read(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
int id = helper.readVarInt(in);
|
||||
if (id >= VALUES.size()) {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.item.component;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class FoodProperties {
|
||||
private final int nutrition;
|
||||
private final float saturationModifier;
|
||||
private final boolean canAlwaysEat;
|
||||
private final float eatSeconds;
|
||||
private final List<PossibleEffect> effects;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class PossibleEffect {
|
||||
private final MobEffectDetails effect;
|
||||
private final float probability;
|
||||
}
|
||||
}
|
|
@ -158,6 +158,54 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
|||
this.writeNullable(buf, blockPredicate.getNbt(), this::writeAnyTag);
|
||||
}
|
||||
|
||||
public ToolData readToolData(ByteBuf buf) {
|
||||
List<ToolData.Rule> rules = new ArrayList<>();
|
||||
int ruleCount = this.readVarInt(buf);
|
||||
for (int i = 0; i < ruleCount; i++) {
|
||||
String location = null;
|
||||
int[] holders = null;
|
||||
|
||||
int length = this.readVarInt(buf) - 1;
|
||||
if (length == -1) {
|
||||
location = this.readResourceLocation(buf);
|
||||
} else {
|
||||
holders = new int[length];
|
||||
for (int j = 0; j < length; j++) {
|
||||
holders[j] = this.readVarInt(buf);
|
||||
}
|
||||
}
|
||||
|
||||
Float speed = this.readNullable(buf, ByteBuf::readFloat);
|
||||
Boolean correctForDrops = this.readNullable(buf, ByteBuf::readBoolean);
|
||||
rules.add(new ToolData.Rule(location, holders, speed, correctForDrops));
|
||||
}
|
||||
|
||||
float defaultMiningSpeed = buf.readFloat();
|
||||
int damagePerBlock = this.readVarInt(buf);
|
||||
return new ToolData(rules, defaultMiningSpeed, damagePerBlock);
|
||||
}
|
||||
|
||||
public void writeToolData(ByteBuf buf, ToolData data) {
|
||||
this.writeVarInt(buf, data.getRules().size());
|
||||
for (ToolData.Rule rule : data.getRules()) {
|
||||
if (rule.getLocation() != null) {
|
||||
this.writeVarInt(buf, 0);
|
||||
this.writeResourceLocation(buf, rule.getLocation());
|
||||
} else {
|
||||
this.writeVarInt(buf, rule.getHolders().length + 1);
|
||||
for (int holder : rule.getHolders()) {
|
||||
this.writeVarInt(buf, holder);
|
||||
}
|
||||
}
|
||||
|
||||
this.writeNullable(buf, rule.getSpeed(), ByteBuf::writeFloat);
|
||||
this.writeNullable(buf, rule.getCorrectForDrops(), ByteBuf::writeBoolean);
|
||||
}
|
||||
|
||||
buf.writeFloat(data.getDefaultMiningSpeed());
|
||||
this.writeVarInt(buf, data.getDamagePerBlock());
|
||||
}
|
||||
|
||||
public ItemAttributeModifiers readItemAttributeModifiers(ByteBuf buf) {
|
||||
List<ItemAttributeModifiers.Entry> modifiers = new ArrayList<>();
|
||||
int modifierCount = this.readVarInt(buf);
|
||||
|
@ -206,7 +254,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
|||
int potionId = buf.readBoolean() ? this.readVarInt(buf) : -1;
|
||||
int customColor = buf.readBoolean() ? buf.readInt() : -1;
|
||||
|
||||
Int2ObjectMap<PotionContents.MobEffectDetails> customEffects = new Int2ObjectOpenHashMap<>();
|
||||
Int2ObjectMap<MobEffectDetails> customEffects = new Int2ObjectOpenHashMap<>();
|
||||
int effectCount = this.readVarInt(buf);
|
||||
for (int i = 0; i < effectCount; i++) {
|
||||
customEffects.put(this.readVarInt(buf), this.readEffectDetails(buf));
|
||||
|
@ -230,23 +278,51 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
|||
}
|
||||
|
||||
this.writeVarInt(buf, contents.getCustomEffects().size());
|
||||
for (Int2ObjectMap.Entry<PotionContents.MobEffectDetails> entry : contents.getCustomEffects().int2ObjectEntrySet()) {
|
||||
for (Int2ObjectMap.Entry<MobEffectDetails> entry : contents.getCustomEffects().int2ObjectEntrySet()) {
|
||||
this.writeVarInt(buf, entry.getIntKey());
|
||||
this.writeEffectDetails(buf, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public PotionContents.MobEffectDetails readEffectDetails(ByteBuf buf) {
|
||||
public FoodProperties readFoodProperties(ByteBuf buf) {
|
||||
int nutrition = this.readVarInt(buf);
|
||||
float saturationModifier = buf.readFloat();
|
||||
boolean canAlwaysEat = buf.readBoolean();
|
||||
float eatSeconds = buf.readFloat();
|
||||
|
||||
List<FoodProperties.PossibleEffect> effects = new ArrayList<>();
|
||||
int effectCount = this.readVarInt(buf);
|
||||
for (int i = 0; i < effectCount; i++) {
|
||||
effects.add(new FoodProperties.PossibleEffect(this.readEffectDetails(buf), buf.readFloat()));
|
||||
}
|
||||
|
||||
return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, effects);
|
||||
}
|
||||
|
||||
public void writeFoodProperties(ByteBuf buf, FoodProperties properties) {
|
||||
this.writeVarInt(buf, properties.getNutrition());
|
||||
buf.writeFloat(properties.getSaturationModifier());
|
||||
buf.writeBoolean(properties.isCanAlwaysEat());
|
||||
buf.writeFloat(properties.getEatSeconds());
|
||||
|
||||
this.writeVarInt(buf, properties.getEffects().size());
|
||||
for (FoodProperties.PossibleEffect effect : properties.getEffects()) {
|
||||
this.writeEffectDetails(buf, effect.getEffect());
|
||||
buf.writeFloat(effect.getProbability());
|
||||
}
|
||||
}
|
||||
|
||||
public MobEffectDetails readEffectDetails(ByteBuf buf) {
|
||||
int amplifier = this.readVarInt(buf);
|
||||
int duration = this.readVarInt(buf);
|
||||
boolean ambient = buf.readBoolean();
|
||||
boolean showParticles = buf.readBoolean();
|
||||
boolean showIcon = buf.readBoolean();
|
||||
PotionContents.MobEffectDetails hiddenEffect = this.readNullable(buf, this::readEffectDetails);
|
||||
return new PotionContents.MobEffectDetails(amplifier, duration, ambient, showParticles, showIcon, hiddenEffect);
|
||||
MobEffectDetails hiddenEffect = this.readNullable(buf, this::readEffectDetails);
|
||||
return new MobEffectDetails(amplifier, duration, ambient, showParticles, showIcon, hiddenEffect);
|
||||
}
|
||||
|
||||
public void writeEffectDetails(ByteBuf buf, PotionContents.MobEffectDetails details) {
|
||||
public void writeEffectDetails(ByteBuf buf, MobEffectDetails details) {
|
||||
this.writeVarInt(buf, details.getAmplifier());
|
||||
this.writeVarInt(buf, details.getDuration());
|
||||
buf.writeBoolean(details.isAmbient());
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.item.component;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class MobEffectDetails {
|
||||
private final int amplifier;
|
||||
private final int duration;
|
||||
private final boolean ambient;
|
||||
private final boolean showParticles;
|
||||
private final boolean showIcon;
|
||||
private final @Nullable MobEffectDetails hiddenEffect;
|
||||
}
|
|
@ -3,7 +3,6 @@ package com.github.steveice10.mc.protocol.data.game.item.component;
|
|||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -11,15 +10,4 @@ public class PotionContents {
|
|||
private final int potionId;
|
||||
private final int customColor;
|
||||
private final Int2ObjectMap<MobEffectDetails> customEffects;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class MobEffectDetails {
|
||||
private final int amplifier;
|
||||
private final int duration;
|
||||
private final boolean ambient;
|
||||
private final boolean showParticles;
|
||||
private final boolean showIcon;
|
||||
private final @Nullable MobEffectDetails hiddenEffect;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.item.component;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ToolData {
|
||||
private final List<Rule> rules;
|
||||
private final float defaultMiningSpeed;
|
||||
private final int damagePerBlock;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class Rule {
|
||||
private final @Nullable String location;
|
||||
private final int @Nullable[] holders;
|
||||
private final @Nullable Float speed;
|
||||
private final @Nullable Boolean correctForDrops;
|
||||
}
|
||||
}
|
|
@ -799,6 +799,7 @@ public enum BuiltinSound implements Sound {
|
|||
ITEM_LODESTONE_COMPASS_LOCK("item.lodestone_compass.lock"),
|
||||
ITEM_MACE_SMASH_AIR("item.mace.smash_air"),
|
||||
ITEM_MACE_SMASH_GROUND("item.mace.smash_ground"),
|
||||
ITEM_MACE_SMASH_GROUND_HEAVY("item.mace.smash_ground_heavy"),
|
||||
ENTITY_MAGMA_CUBE_DEATH("entity.magma_cube.death"),
|
||||
ENTITY_MAGMA_CUBE_HURT("entity.magma_cube.hurt"),
|
||||
ENTITY_MAGMA_CUBE_HURT_SMALL("entity.magma_cube.hurt_small"),
|
||||
|
|
Loading…
Reference in a new issue