Skip to content

Commit

Permalink
Implement all new components
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Aug 30, 2024
1 parent c9d42f8 commit 7cdb951
Show file tree
Hide file tree
Showing 17 changed files with 901 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mappingCompression {
compress("entity/painting_mappings.json")
compress("entity/wolf_variant_mappings.json")

compress("item/consume_effect_type_mappings.json")
compress("item/item_armor_material_mappings.json")
compress("item/item_banner_pattern_mappings.json")
compress("item/item_component_mappings.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemAttributeModifiers;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemBees;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemBlockStateProperties;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemConsumable;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemContainerContents;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemContainerLoot;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemDyeColor;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantable;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemFireworks;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemJukeboxPlayable;
Expand All @@ -45,7 +47,10 @@
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemProfile;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRarity;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRecipes;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemRepairable;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemTool;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemUseCooldown;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemUseRemainder;
import com.github.retrooper.packetevents.protocol.component.builtin.item.LodestoneTracker;
import com.github.retrooper.packetevents.protocol.component.builtin.item.PotDecorations;
import com.github.retrooper.packetevents.protocol.component.builtin.item.SuspiciousStewEffects;
Expand Down Expand Up @@ -220,6 +225,18 @@ public static ComponentType<?> getById(ClientVersion version, int id) {
public static final ComponentType<ItemJukeboxPlayable> JUKEBOX_PLAYABLE = define("jukebox_playable",
ItemJukeboxPlayable::read, ItemJukeboxPlayable::write);

// added in 1.21.2
public static final ComponentType<ItemConsumable> CONSUMABLE = define("consumable",
ItemConsumable::read, ItemConsumable::write);
public static final ComponentType<ItemUseRemainder> USE_REMAINDER = define("use_remainder",
ItemUseRemainder::read, ItemUseRemainder::write);
public static final ComponentType<ItemUseCooldown> USE_COOLDOWN = define("use_cooldown",
ItemUseCooldown::read, ItemUseCooldown::write);
public static final ComponentType<ItemEnchantable> ENCHANTABLE = define("enchantable",
ItemEnchantable::read, ItemEnchantable::write);
public static final ComponentType<ItemRepairable> REPAIRABLE = define("repairable",
ItemRepairable::read, ItemRepairable::write);

/**
* Returns an immutable view of the component types.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.github.retrooper.packetevents.protocol.component.builtin.item;

import com.github.retrooper.packetevents.protocol.item.consumables.ConsumeEffect;
import com.github.retrooper.packetevents.protocol.sound.Sound;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

import java.util.List;
import java.util.Objects;

public class ItemConsumable {

private float consumeSeconds;
private Animation animation;
private Sound sound;
private boolean consumeParticles;
private List<ConsumeEffect> effects;

public ItemConsumable(
float consumeSeconds, Animation animation, Sound sound,
boolean consumeParticles, List<ConsumeEffect> effects
) {
this.consumeSeconds = consumeSeconds;
this.animation = animation;
this.sound = sound;
this.consumeParticles = consumeParticles;
this.effects = effects;
}

public static ItemConsumable read(PacketWrapper<?> wrapper) {
float consumeSeconds = wrapper.readFloat();
Animation animation = wrapper.readEnum(Animation.values());
Sound sound = Sound.read(wrapper);
boolean consumeParticles = wrapper.readBoolean();
List<ConsumeEffect> effects = wrapper.readList(ConsumeEffect::readFull);
return new ItemConsumable(consumeSeconds, animation, sound, consumeParticles, effects);
}

public static void write(PacketWrapper<?> wrapper, ItemConsumable consumable) {
wrapper.writeFloat(consumable.consumeSeconds);
wrapper.writeEnum(consumable.animation);
Sound.write(wrapper, consumable.sound);
wrapper.writeBoolean(consumable.consumeParticles);
wrapper.writeList(consumable.effects, ConsumeEffect::writeFull);
}

public float getConsumeSeconds() {
return this.consumeSeconds;
}

public void setConsumeSeconds(float consumeSeconds) {
this.consumeSeconds = consumeSeconds;
}

public Animation getAnimation() {
return this.animation;
}

public void setAnimation(Animation animation) {
this.animation = animation;
}

public Sound getSound() {
return this.sound;
}

public void setSound(Sound sound) {
this.sound = sound;
}

public boolean isConsumeParticles() {
return this.consumeParticles;
}

public void setConsumeParticles(boolean consumeParticles) {
this.consumeParticles = consumeParticles;
}

public List<ConsumeEffect> getEffects() {
return this.effects;
}

public void setEffects(List<ConsumeEffect> effects) {
this.effects = effects;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemConsumable)) return false;
ItemConsumable that = (ItemConsumable) obj;
if (Float.compare(that.consumeSeconds, this.consumeSeconds) != 0) return false;
if (this.consumeParticles != that.consumeParticles) return false;
if (this.animation != that.animation) return false;
if (!this.sound.equals(that.sound)) return false;
return this.effects.equals(that.effects);
}

@Override
public int hashCode() {
return Objects.hash(this.consumeSeconds, this.animation, this.sound, this.consumeParticles, this.effects);
}

@Override
public String toString() {
return "ItemConsumable{consumeSeconds=" + this.consumeSeconds + ", animation=" + this.animation + ", sound=" + this.sound + ", consumeParticles=" + this.consumeParticles + ", effects=" + this.effects + '}';
}

public enum Animation {
NONE,
EAT,
DRINK,
BLOCK,
BOW,
SPEAR,
CROSSBOW,
SPYGLASS,
TOOT_HORN,
BRUSH,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.github.retrooper.packetevents.protocol.component.builtin.item;

import com.github.retrooper.packetevents.wrapper.PacketWrapper;

import java.util.Objects;

public class ItemEnchantable {

private int value;

public ItemEnchantable(int value) {
this.value = value;
}

public static ItemEnchantable read(PacketWrapper<?> wrapper) {
int value = wrapper.readVarInt();
return new ItemEnchantable(value);
}

public static void write(PacketWrapper<?> wrapper, ItemEnchantable enchantable) {
wrapper.writeVarInt(enchantable.value);
}

public int getValue() {
return this.value;
}

public void setValue(int value) {
this.value = value;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemEnchantable)) return false;
ItemEnchantable that = (ItemEnchantable) obj;
return this.value == that.value;
}

@Override
public int hashCode() {
return Objects.hashCode(this.value);
}

@Override
public String toString() {
return "ItemEnchantable{value=" + this.value + '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.github.retrooper.packetevents.protocol.component.builtin.item;

import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

import java.util.Objects;

public class ItemRepairable {

private MappedEntitySet<ItemType> items;

public ItemRepairable(MappedEntitySet<ItemType> items) {
this.items = items;
}

public static ItemRepairable read(PacketWrapper<?> wrapper) {
MappedEntitySet<ItemType> items = MappedEntitySet.read(wrapper, ItemTypes.getRegistry());
return new ItemRepairable(items);
}

public static void write(PacketWrapper<?> wrapper, ItemRepairable repairable) {
MappedEntitySet.write(wrapper, repairable.items);
}

public MappedEntitySet<ItemType> getItems() {
return this.items;
}

public void setItems(MappedEntitySet<ItemType> items) {
this.items = items;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof ItemRepairable)) return false;
ItemRepairable that = (ItemRepairable) obj;
return this.items.equals(that.items);
}

@Override
public int hashCode() {
return Objects.hashCode(this.items);
}

@Override
public String toString() {
return "ItemRepairable{items=" + this.items + '}';
}
}
Loading

0 comments on commit 7cdb951

Please sign in to comment.