Combine SoundEvent and ParticleEvent into LevelEvent

Remove them from MagicValues
Add new Sculk Block charge level event + event data
Add new Sculk Shrieker shriek level event
This commit is contained in:
davchoo 2022-05-26 19:57:21 -04:00
parent 4dff74676b
commit 3e163501aa
No known key found for this signature in database
GPG key ID: A0168C8E45799B7D
7 changed files with 181 additions and 187 deletions

View file

@ -53,9 +53,7 @@ import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValue
import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValueType;
import com.github.steveice10.mc.protocol.data.game.level.event.ComposterEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.DragonFireballEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.ParticleEvent;
import com.github.steveice10.mc.protocol.data.game.level.event.SmokeEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent;
import com.github.steveice10.mc.protocol.data.game.level.map.MapIconType;
import com.github.steveice10.mc.protocol.data.game.level.notify.DemoMessageValue;
import com.github.steveice10.mc.protocol.data.game.level.notify.EnterCreditsValue;
@ -441,79 +439,6 @@ public class MagicValues {
register(PistonValue.WEST, 4);
register(PistonValue.EAST, 5);
register(SoundEvent.BLOCK_DISPENSER_DISPENSE, 1000);
register(SoundEvent.BLOCK_DISPENSER_FAIL, 1001);
register(SoundEvent.BLOCK_DISPENSER_LAUNCH, 1002);
register(SoundEvent.ENTITY_ENDEREYE_LAUNCH, 1003);
register(SoundEvent.ENTITY_FIREWORK_SHOOT, 1004);
register(SoundEvent.BLOCK_IRON_DOOR_OPEN, 1005);
register(SoundEvent.BLOCK_WOODEN_DOOR_OPEN, 1006);
register(SoundEvent.BLOCK_WOODEN_TRAPDOOR_OPEN, 1007);
register(SoundEvent.BLOCK_FENCE_GATE_OPEN, 1008);
register(SoundEvent.BLOCK_FIRE_EXTINGUISH, 1009);
register(SoundEvent.RECORD, 1010);
register(SoundEvent.BLOCK_IRON_DOOR_CLOSE, 1011);
register(SoundEvent.BLOCK_WOODEN_DOOR_CLOSE, 1012);
register(SoundEvent.BLOCK_WOODEN_TRAPDOOR_CLOSE, 1013);
register(SoundEvent.BLOCK_FENCE_GATE_CLOSE, 1014);
register(SoundEvent.ENTITY_GHAST_WARN, 1015);
register(SoundEvent.ENTITY_GHAST_SHOOT, 1016);
register(SoundEvent.ENTITY_ENDERDRAGON_SHOOT, 1017);
register(SoundEvent.ENTITY_BLAZE_SHOOT, 1018);
register(SoundEvent.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, 1019);
register(SoundEvent.ENTITY_ZOMBIE_ATTACK_DOOR_IRON, 1020);
register(SoundEvent.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, 1021);
register(SoundEvent.ENTITY_WITHER_BREAK_BLOCK, 1022);
register(SoundEvent.ENTITY_WITHER_SPAWN, 1023);
register(SoundEvent.ENTITY_WITHER_SHOOT, 1024);
register(SoundEvent.ENTITY_BAT_TAKEOFF, 1025);
register(SoundEvent.ENTITY_ZOMBIE_INFECT, 1026);
register(SoundEvent.ENTITY_ZOMBIE_VILLAGER_CONVERTED, 1027);
register(SoundEvent.ENTITY_ENDERDRAGON_DEATH, 1028);
register(SoundEvent.BLOCK_ANVIL_DESTROY, 1029);
register(SoundEvent.BLOCK_ANVIL_USE, 1030);
register(SoundEvent.BLOCK_ANVIL_LAND, 1031);
register(SoundEvent.BLOCK_PORTAL_TRAVEL, 1032);
register(SoundEvent.BLOCK_CHORUS_FLOWER_GROW, 1033);
register(SoundEvent.BLOCK_CHORUS_FLOWER_DEATH, 1034);
register(SoundEvent.BLOCK_BREWING_STAND_BREW, 1035);
register(SoundEvent.BLOCK_IRON_TRAPDOOR_CLOSE, 1036);
register(SoundEvent.BLOCK_IRON_TRAPDOOR_OPEN, 1037);
register(SoundEvent.BLOCK_END_PORTAL_SPAWN, 1038);
register(SoundEvent.ENTITY_PHANTOM_BITE, 1039);
register(SoundEvent.ENTITY_ZOMBIE_CONVERTED_TO_DROWNED, 1040);
register(SoundEvent.ENTITY_HUSK_CONVERTED_TO_ZOMBIE, 1041);
register(SoundEvent.BLOCK_GRINDSTONE_USE, 1042);
register(SoundEvent.ITEM_BOOK_PAGE_TURN, 1043);
register(SoundEvent.BLOCK_SMITHING_TABLE_USE, 1044);
register(SoundEvent.POINTED_DRIPSTONE_LAND, 1045);
register(SoundEvent.DRIP_LAVA_INTO_CAULDRON, 1046);
register(SoundEvent.DRIP_WATER_INTO_CAULDRON, 1047);
register(SoundEvent.ENTITY_SKELETON_CONVERTED_TO_STRAY, 1048);
register(SoundEvent.ENTITY_ENDERDRAGON_GROWL, 3001);
register(ParticleEvent.COMPOSTER, 1500);
register(ParticleEvent.BLOCK_LAVA_EXTINGUISH, 1501);
register(ParticleEvent.BLOCK_REDSTONE_TORCH_BURNOUT, 1502);
register(ParticleEvent.BLOCK_END_PORTAL_FRAME_FILL, 1503);
register(ParticleEvent.DRIPSTONE_DRIP, 1504);
register(ParticleEvent.BONEMEAL_GROW_WITH_SOUND, 1505);
register(ParticleEvent.SMOKE, 2000);
register(ParticleEvent.BREAK_BLOCK, 2001);
register(ParticleEvent.BREAK_SPLASH_POTION, 2002);
register(ParticleEvent.BREAK_EYE_OF_ENDER, 2003);
register(ParticleEvent.MOB_SPAWN, 2004);
register(ParticleEvent.BONEMEAL_GROW, 2005);
register(ParticleEvent.ENDERDRAGON_FIREBALL_EXPLODE, 2006);
register(ParticleEvent.BREAK_SPLASH_POTION, 2007);
register(ParticleEvent.EXPLOSION, 2008);
register(ParticleEvent.EVAPORATE, 2009);
register(ParticleEvent.END_GATEWAY_SPAWN, 3000);
register(ParticleEvent.ELECTRIC_SPARK, 3002);
register(ParticleEvent.WAX_ON, 3003);
register(ParticleEvent.WAX_OFF, 3004);
register(ParticleEvent.SCRAPE, 3005);
register(SmokeEventData.DOWN, 0);
register(SmokeEventData.UP, 1);
register(SmokeEventData.NORTH, 2);

View file

@ -1,4 +1,110 @@
package com.github.steveice10.mc.protocol.data.game.level.event;
public interface LevelEvent {
import com.github.steveice10.packetlib.io.NetInput;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@AllArgsConstructor
public enum LevelEvent {
BLOCK_DISPENSER_DISPENSE(1000),
BLOCK_DISPENSER_FAIL(1001),
BLOCK_DISPENSER_LAUNCH(1002),
ENTITY_ENDEREYE_LAUNCH(1003),
ENTITY_FIREWORK_SHOOT(1004),
BLOCK_IRON_DOOR_OPEN(1005),
BLOCK_WOODEN_DOOR_OPEN(1006),
BLOCK_WOODEN_TRAPDOOR_OPEN(1007),
BLOCK_FENCE_GATE_OPEN(1008),
BLOCK_FIRE_EXTINGUISH(1009),
RECORD(1010),
BLOCK_IRON_DOOR_CLOSE(1011),
BLOCK_WOODEN_DOOR_CLOSE(1012),
BLOCK_WOODEN_TRAPDOOR_CLOSE(1013),
BLOCK_FENCE_GATE_CLOSE(1014),
ENTITY_GHAST_WARN(1015),
ENTITY_GHAST_SHOOT(1016),
ENTITY_ENDERDRAGON_SHOOT(1017),
ENTITY_BLAZE_SHOOT(1018),
ENTITY_ZOMBIE_ATTACK_DOOR_WOOD(1019),
ENTITY_ZOMBIE_ATTACK_DOOR_IRON(1020),
ENTITY_ZOMBIE_BREAK_DOOR_WOOD(1021),
ENTITY_WITHER_BREAK_BLOCK(1022),
ENTITY_WITHER_SPAWN(1023), // Global level event
ENTITY_WITHER_SHOOT(1024),
ENTITY_BAT_TAKEOFF(1025),
ENTITY_ZOMBIE_INFECT(1026),
ENTITY_ZOMBIE_VILLAGER_CONVERTED(1027),
ENTITY_ENDERDRAGON_DEATH(1028), // Global level event
BLOCK_ANVIL_DESTROY(1029),
BLOCK_ANVIL_USE(1030),
BLOCK_ANVIL_LAND(1031),
BLOCK_PORTAL_TRAVEL(1032),
BLOCK_CHORUS_FLOWER_GROW(1033),
BLOCK_CHORUS_FLOWER_DEATH(1034),
BLOCK_BREWING_STAND_BREW(1035),
BLOCK_IRON_TRAPDOOR_CLOSE(1036),
BLOCK_IRON_TRAPDOOR_OPEN(1037),
BLOCK_END_PORTAL_SPAWN(1038), // Global level event
ENTITY_PHANTOM_BITE(1039),
ENTITY_ZOMBIE_CONVERTED_TO_DROWNED(1040),
ENTITY_HUSK_CONVERTED_TO_ZOMBIE(1041),
BLOCK_GRINDSTONE_USE(1042),
ITEM_BOOK_PAGE_TURN(1043),
BLOCK_SMITHING_TABLE_USE(1044),
POINTED_DRIPSTONE_LAND(1045),
DRIP_LAVA_INTO_CAULDRON(1046),
DRIP_WATER_INTO_CAULDRON(1047),
ENTITY_SKELETON_CONVERTED_TO_STRAY(1048),
COMPOSTER(1500),
BLOCK_LAVA_EXTINGUISH(1501),
BLOCK_REDSTONE_TORCH_BURNOUT(1502),
BLOCK_END_PORTAL_FRAME_FILL(1503),
DRIPSTONE_DRIP(1504),
BONEMEAL_GROW_WITH_SOUND(1505),
SMOKE(2000),
BREAK_BLOCK(2001),
BREAK_SPLASH_POTION(2002),
BREAK_EYE_OF_ENDER(2003),
MOB_SPAWN(2004),
BONEMEAL_GROW(2005),
ENDERDRAGON_FIREBALL_EXPLODE(2006),
BREAK_SPLASH_POTION2(2007), // Mojank
EXPLOSION(2008),
EVAPORATE(2009),
END_GATEWAY_SPAWN(3000),
ENTITY_ENDERDRAGON_GROWL(3001),
ELECTRIC_SPARK(3002),
WAX_ON(3003),
WAX_OFF(3004),
SCRAPE(3005),
SCULK_BLOCK_CHARGE(3006),
SCULK_SHRIEKER_SHRIEK(3007);
@Getter
private final int id;
private static final LevelEvent[] VALUES = values();
private static final Map<Integer, LevelEvent> LEVEL_EVENT_MAP = new HashMap<>();
public static LevelEvent read(NetInput in) throws IOException {
int levelEventId = in.readInt();
LevelEvent levelEvent = LEVEL_EVENT_MAP.get(levelEventId);
if (levelEvent == null) {
throw new IllegalStateException("Unknown level event with id: " + levelEventId);
}
return levelEvent;
}
static {
for (LevelEvent levelEvent : VALUES) {
LEVEL_EVENT_MAP.put(levelEvent.id, levelEvent);
}
}
}

View file

@ -1,24 +0,0 @@
package com.github.steveice10.mc.protocol.data.game.level.event;
public enum ParticleEvent implements LevelEvent {
COMPOSTER,
BLOCK_LAVA_EXTINGUISH,
BLOCK_REDSTONE_TORCH_BURNOUT,
BLOCK_END_PORTAL_FRAME_FILL,
DRIPSTONE_DRIP,
BONEMEAL_GROW_WITH_SOUND,
SMOKE,
BREAK_BLOCK,
BREAK_SPLASH_POTION,
BREAK_EYE_OF_ENDER,
MOB_SPAWN,
BONEMEAL_GROW,
ENDERDRAGON_FIREBALL_EXPLODE,
EXPLOSION,
EVAPORATE,
END_GATEWAY_SPAWN,
ELECTRIC_SPARK,
WAX_ON,
WAX_OFF,
SCRAPE
}

View file

@ -0,0 +1,39 @@
package com.github.steveice10.mc.protocol.data.game.level.event;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import lombok.Value;
import java.util.EnumSet;
import java.util.Set;
@Value
public class SculkBlockChargeEventData implements LevelEventData {
int charge;
Set<Direction> blockFaces;
public SculkBlockChargeEventData(int charge, Set<Direction> blockFaces) {
this.charge = charge;
this.blockFaces = blockFaces;
}
public SculkBlockChargeEventData(int value) {
this.charge = value >> 6;
this.blockFaces = EnumSet.noneOf(Direction.class);
int blockFaceBits = value & 63;
for (Direction direction : Direction.VALUES) {
if (((blockFaceBits >> direction.ordinal()) & 1) == 1) {
blockFaces.add(direction);
}
}
}
public int getLevelValue() {
int value = this.charge << 6;
for (Direction direction : blockFaces) {
value |= (1 << direction.ordinal());
}
return value;
}
}

View file

@ -1,54 +0,0 @@
package com.github.steveice10.mc.protocol.data.game.level.event;
public enum SoundEvent implements LevelEvent {
BLOCK_DISPENSER_DISPENSE,
BLOCK_DISPENSER_FAIL,
BLOCK_DISPENSER_LAUNCH,
ENTITY_ENDEREYE_LAUNCH,
ENTITY_FIREWORK_SHOOT,
BLOCK_IRON_DOOR_OPEN,
BLOCK_WOODEN_DOOR_OPEN,
BLOCK_WOODEN_TRAPDOOR_OPEN,
BLOCK_FENCE_GATE_OPEN,
BLOCK_FIRE_EXTINGUISH,
RECORD,
BLOCK_IRON_DOOR_CLOSE,
BLOCK_WOODEN_DOOR_CLOSE,
BLOCK_WOODEN_TRAPDOOR_CLOSE,
BLOCK_FENCE_GATE_CLOSE,
ENTITY_GHAST_WARN,
ENTITY_GHAST_SHOOT,
ENTITY_ENDERDRAGON_SHOOT,
ENTITY_BLAZE_SHOOT,
ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,
ENTITY_ZOMBIE_ATTACK_DOOR_IRON,
ENTITY_ZOMBIE_BREAK_DOOR_WOOD,
ENTITY_WITHER_BREAK_BLOCK,
ENTITY_WITHER_SPAWN,
ENTITY_WITHER_SHOOT,
ENTITY_BAT_TAKEOFF,
ENTITY_ZOMBIE_INFECT,
ENTITY_ZOMBIE_VILLAGER_CONVERTED,
ENTITY_ENDERDRAGON_DEATH,
BLOCK_ANVIL_DESTROY,
BLOCK_ANVIL_USE,
BLOCK_ANVIL_LAND,
BLOCK_PORTAL_TRAVEL,
BLOCK_CHORUS_FLOWER_GROW,
BLOCK_CHORUS_FLOWER_DEATH,
BLOCK_BREWING_STAND_BREW,
BLOCK_IRON_TRAPDOOR_CLOSE,
BLOCK_IRON_TRAPDOOR_OPEN,
BLOCK_END_PORTAL_SPAWN,
ENTITY_PHANTOM_BITE,
ENTITY_ZOMBIE_CONVERTED_TO_DROWNED,
ENTITY_HUSK_CONVERTED_TO_ZOMBIE,
BLOCK_GRINDSTONE_USE,
ITEM_BOOK_PAGE_TURN,
BLOCK_SMITHING_TABLE_USE,
ENTITY_ENDERDRAGON_GROWL,
POINTED_DRIPSTONE_LAND,
DRIP_LAVA_INTO_CAULDRON,
DRIP_WATER_INTO_CAULDRON,
ENTITY_SKELETON_CONVERTED_TO_STRAY;
}

View file

@ -2,17 +2,7 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound.level;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.level.event.BonemealGrowEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.BreakBlockEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.BreakPotionEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.ComposterEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.DragonFireballEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.LevelEvent;
import com.github.steveice10.mc.protocol.data.game.level.event.LevelEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.ParticleEvent;
import com.github.steveice10.mc.protocol.data.game.level.event.RecordEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.SmokeEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent;
import com.github.steveice10.mc.protocol.data.game.level.event.*;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
@ -38,25 +28,39 @@ public class ClientboundLevelEventPacket implements Packet {
}
public ClientboundLevelEventPacket(NetInput in) throws IOException {
this.event = MagicValues.key(LevelEvent.class, in.readInt());
this.event = LevelEvent.read(in);
this.position = Position.read(in);
int value = in.readInt();
if (this.event == SoundEvent.RECORD) {
this.data = new RecordEventData(value);
} else if (this.event == ParticleEvent.SMOKE) {
this.data = MagicValues.key(SmokeEventData.class, value % 6);
} else if (this.event == ParticleEvent.BREAK_BLOCK) {
this.data = new BreakBlockEventData(value);
} else if (this.event == ParticleEvent.BREAK_SPLASH_POTION) {
this.data = new BreakPotionEventData(value);
} else if (this.event == ParticleEvent.BONEMEAL_GROW || this.event == ParticleEvent.BONEMEAL_GROW_WITH_SOUND) {
this.data = new BonemealGrowEventData(value);
} else if (this.event == ParticleEvent.COMPOSTER) {
this.data = value > 0 ? ComposterEventData.FILL_SUCCESS : ComposterEventData.FILL;
} else if (this.event == ParticleEvent.ENDERDRAGON_FIREBALL_EXPLODE) {
this.data = value == 1 ? DragonFireballEventData.HAS_SOUND : DragonFireballEventData.NO_SOUND;
} else {
this.data = null;
switch (this.event) {
case RECORD:
this.data = new RecordEventData(value);
break;
case SMOKE:
this.data = MagicValues.key(SmokeEventData.class, value % 6);
break;
case BREAK_BLOCK:
this.data = new BreakBlockEventData(value);
break;
case BREAK_SPLASH_POTION:
case BREAK_SPLASH_POTION2:
this.data = new BreakPotionEventData(value);
break;
case BONEMEAL_GROW:
case BONEMEAL_GROW_WITH_SOUND:
this.data = new BonemealGrowEventData(value);
break;
case COMPOSTER:
this.data = value > 0 ? ComposterEventData.FILL_SUCCESS : ComposterEventData.FILL;
break;
case ENDERDRAGON_FIREBALL_EXPLODE:
this.data = value == 1 ? DragonFireballEventData.HAS_SOUND : DragonFireballEventData.NO_SOUND;
break;
case SCULK_BLOCK_CHARGE:
this.data = new SculkBlockChargeEventData(value);
break;
default:
this.data = null;
break;
}
this.broadcast = in.readBoolean();
@ -64,7 +68,7 @@ public class ClientboundLevelEventPacket implements Packet {
@Override
public void write(NetOutput out) throws IOException {
out.writeInt(MagicValues.value(Integer.class, this.event));
out.writeInt(this.event.getId());
Position.write(out, this.position);
int value = 0;
if (this.data instanceof RecordEventData) {
@ -81,6 +85,8 @@ public class ClientboundLevelEventPacket implements Packet {
value = MagicValues.value(Integer.class, this.data);
} else if (this.data instanceof DragonFireballEventData) {
value = MagicValues.value(Integer.class, this.data);
} else if (this.data instanceof SculkBlockChargeEventData) {
value = ((SculkBlockChargeEventData) data).getLevelValue();
}
out.writeInt(value);

View file

@ -52,9 +52,7 @@ import com.github.steveice10.mc.protocol.data.game.level.block.value.NoteBlockVa
import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValue;
import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValueType;
import com.github.steveice10.mc.protocol.data.game.level.event.ComposterEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.ParticleEvent;
import com.github.steveice10.mc.protocol.data.game.level.event.SmokeEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent;
import com.github.steveice10.mc.protocol.data.game.level.map.MapIconType;
import com.github.steveice10.mc.protocol.data.game.level.notify.DemoMessageValue;
import com.github.steveice10.mc.protocol.data.game.level.notify.EnterCreditsValue;
@ -138,8 +136,6 @@ public class MagicValuesTest {
this.register(EndGatewayValueType.class, Integer.class);
this.register(GenericBlockValueType.class, Integer.class);
this.register(PistonValue.class, Integer.class);
this.register(SoundEvent.class, Integer.class);
this.register(ParticleEvent.class, Integer.class);
this.register(SmokeEventData.class, Integer.class);
this.register(ComposterEventData.class, Integer.class);
this.register(NameTagVisibility.class, String.class);