mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 01:55:47 +01:00
Change the consume animation of swords to block (#4223)
This commit is contained in:
parent
74b9eb9f45
commit
10f2cad8fd
@ -45,6 +45,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_20_5;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_21_2;
|
import com.viaversion.viaversion.api.minecraft.item.data.Instrument1_21_2;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.PotionEffect;
|
import com.viaversion.viaversion.api.minecraft.item.data.PotionEffect;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||||
@ -417,6 +418,9 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
|||||||
super.handleItemToClient(connection, item);
|
super.handleItemToClient(connection, item);
|
||||||
updateItemData(item);
|
updateItemData(item);
|
||||||
|
|
||||||
|
// Add data components to fix issues in older protocols
|
||||||
|
appendItemDataFixComponents(connection, item);
|
||||||
|
|
||||||
// Item name is now overridden by custom implemented display names (compass, player head, potion, shield, tipped arrow)
|
// Item name is now overridden by custom implemented display names (compass, player head, potion, shield, tipped arrow)
|
||||||
final int identifier = item.identifier();
|
final int identifier = item.identifier();
|
||||||
if (identifier == 952 || identifier == 1147 || identifier == 1039 || identifier == 1203 || identifier == 1200 || identifier == 1204 || identifier == 1202) {
|
if (identifier == 952 || identifier == 1147 || identifier == 1039 || identifier == 1203 || identifier == 1200 || identifier == 1204 || identifier == 1202) {
|
||||||
@ -469,6 +473,17 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
|||||||
wrapper.write(Types.UNSIGNED_BYTE, (short) containerId);
|
wrapper.write(Types.UNSIGNED_BYTE, (short) containerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void appendItemDataFixComponents(final UserConnection connection, final Item item) {
|
||||||
|
final ProtocolVersion serverVersion = connection.getProtocolInfo().serverProtocolVersion();
|
||||||
|
if (serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_8) && item.dataContainer().hasValue(StructuredDataKey.CONSUMABLE1_21_2)) {
|
||||||
|
if (item.identifier() == 840 || item.identifier() == 845 || item.identifier() == 850 || item.identifier() == 855 || item.identifier() == 860) { // swords
|
||||||
|
// Change the consume animation of swords to block
|
||||||
|
final Consumable1_21_2 consumable = item.dataContainer().get(StructuredDataKey.CONSUMABLE1_21_2);
|
||||||
|
item.dataContainer().set(StructuredDataKey.CONSUMABLE1_21_2, new Consumable1_21_2(consumable.consumeSeconds(), 3, consumable.sound(), consumable.hasConsumeParticles(), consumable.consumeEffects()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateItemData(final Item item) {
|
public static void updateItemData(final Item item) {
|
||||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||||
dataContainer.replace(StructuredDataKey.INSTRUMENT1_20_5, StructuredDataKey.INSTRUMENT1_21_2, instrument -> {
|
dataContainer.replace(StructuredDataKey.INSTRUMENT1_20_5, StructuredDataKey.INSTRUMENT1_21_2, instrument -> {
|
||||||
@ -486,6 +501,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
|||||||
final Consumable1_21_2.ApplyStatusEffects applyStatusEffects = new Consumable1_21_2.ApplyStatusEffects(new PotionEffect[]{effect.effect()}, effect.probability());
|
final Consumable1_21_2.ApplyStatusEffects applyStatusEffects = new Consumable1_21_2.ApplyStatusEffects(new PotionEffect[]{effect.effect()}, effect.probability());
|
||||||
consumeEffects[i] = new Consumable1_21_2.ConsumeEffect<>(0 /* add status effect */, Consumable1_21_2.ApplyStatusEffects.TYPE, applyStatusEffects);
|
consumeEffects[i] = new Consumable1_21_2.ConsumeEffect<>(0 /* add status effect */, Consumable1_21_2.ApplyStatusEffects.TYPE, applyStatusEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataContainer.set(StructuredDataKey.CONSUMABLE1_21_2, new Consumable1_21_2(food.eatSeconds(), 1 /* eat */, sound, true, consumeEffects));
|
dataContainer.set(StructuredDataKey.CONSUMABLE1_21_2, new Consumable1_21_2(food.eatSeconds(), 1 /* eat */, sound, true, consumeEffects));
|
||||||
if (food.usingConvertsTo() != null) {
|
if (food.usingConvertsTo() != null) {
|
||||||
dataContainer.set(StructuredDataKey.USE_REMAINDER, food.usingConvertsTo());
|
dataContainer.set(StructuredDataKey.USE_REMAINDER, food.usingConvertsTo());
|
||||||
|
Loading…
Reference in New Issue
Block a user