diff --git a/src/main/java/fr/themode/demo/commands/HealthCommand.java b/src/main/java/fr/themode/demo/commands/HealthCommand.java index 52840ef72..be97c41a3 100644 --- a/src/main/java/fr/themode/demo/commands/HealthCommand.java +++ b/src/main/java/fr/themode/demo/commands/HealthCommand.java @@ -28,7 +28,6 @@ public class HealthCommand extends Command { } private boolean condition(Player player) { - // TODO: Your custom condition, called no matter the syntax used boolean hasPerm = true; if (!hasPerm) { player.sendMessage("You do not have permission !"); diff --git a/src/main/java/net/minestom/server/UpdateManager.java b/src/main/java/net/minestom/server/UpdateManager.java index 3deba4bdf..00c4f7b58 100644 --- a/src/main/java/net/minestom/server/UpdateManager.java +++ b/src/main/java/net/minestom/server/UpdateManager.java @@ -48,8 +48,6 @@ public class UpdateManager { // Scheduler schedulerManager.update(); - // TODO miscellaneous update (scoreboard) - // Sleep until next tick long sleepTime = (tickDistance - (System.nanoTime() - currentTime)) / 1000000; sleepTime = Math.max(1, sleepTime); diff --git a/src/main/java/net/minestom/server/entity/EntityCreature.java b/src/main/java/net/minestom/server/entity/EntityCreature.java index 33d9e5389..77eb910c5 100644 --- a/src/main/java/net/minestom/server/entity/EntityCreature.java +++ b/src/main/java/net/minestom/server/entity/EntityCreature.java @@ -129,6 +129,11 @@ public abstract class EntityCreature extends LivingEntity { refreshPosition(newX, newY, newZ); } + @Override + public void spawn() { + + } + @Override public void kill() { super.kill(); diff --git a/src/main/java/net/minestom/server/entity/LivingEntity.java b/src/main/java/net/minestom/server/entity/LivingEntity.java index f9d218971..6fa0534a3 100644 --- a/src/main/java/net/minestom/server/entity/LivingEntity.java +++ b/src/main/java/net/minestom/server/entity/LivingEntity.java @@ -120,8 +120,6 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { fillMetadataIndex(packet, 7); fillMetadataIndex(packet, 8); fillMetadataIndex(packet, 11); - - // TODO all remaining metadata }; } diff --git a/src/main/java/net/minestom/server/entity/ObjectEntity.java b/src/main/java/net/minestom/server/entity/ObjectEntity.java index 9b2b7b7ec..9ad11b812 100644 --- a/src/main/java/net/minestom/server/entity/ObjectEntity.java +++ b/src/main/java/net/minestom/server/entity/ObjectEntity.java @@ -18,6 +18,16 @@ public abstract class ObjectEntity extends Entity { */ public abstract int getObjectData(); + @Override + public void update() { + + } + + @Override + public void spawn() { + + } + @Override public boolean addViewer(Player player) { PlayerConnection playerConnection = player.getPlayerConnection(); diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index a85081836..8ea70ef14 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -23,6 +23,7 @@ import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.PlayerInventory; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; +import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.login.JoinGamePacket; @@ -80,6 +81,7 @@ public class Player extends LivingEntity { private Position respawnPoint; + private float additionalHearts; private int food; private float foodSaturation; private long startEatingTime; @@ -129,7 +131,7 @@ public class Player extends LivingEntity { public Player(UUID uuid, String username, PlayerConnection playerConnection) { super(EntityType.PLAYER); - this.uuid = uuid; + this.uuid = uuid; // Override Entity#uuid defined in the constructor this.username = username; this.playerConnection = playerConnection; @@ -570,6 +572,24 @@ public class Player extends LivingEntity { } } + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 14); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 14) { + packet.writeByte((byte) 14); + packet.writeByte(METADATA_FLOAT); + packet.writeFloat(additionalHearts); + } + } + public void sendBlockBreakAnimation(BlockPosition blockPosition, byte destroyStage) { BlockBreakAnimationPacket breakAnimationPacket = new BlockBreakAnimationPacket(); breakAnimationPacket.entityId = getEntityId() + 1; @@ -725,6 +745,15 @@ public class Player extends LivingEntity { sendUpdateHealthPacket(); } + public float getAdditionalHearts() { + return additionalHearts; + } + + public void setAdditionalHearts(float additionalHearts) { + this.additionalHearts = additionalHearts; + sendMetadataIndex(14); + } + public int getFood() { return food; } diff --git a/src/main/java/net/minestom/server/entity/type/EntityArmorStand.java b/src/main/java/net/minestom/server/entity/type/EntityArmorStand.java index 57671d1ec..8687e3cdf 100644 --- a/src/main/java/net/minestom/server/entity/type/EntityArmorStand.java +++ b/src/main/java/net/minestom/server/entity/type/EntityArmorStand.java @@ -72,17 +72,6 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { return 0; } - @Override - public void update() { - - } - - @Override - public void spawn() { - - } - - @Override public Consumer getMetadataConsumer() { return packet -> { diff --git a/src/main/java/net/minestom/server/entity/type/EntityBat.java b/src/main/java/net/minestom/server/entity/type/EntityBat.java new file mode 100644 index 000000000..ad12dac9a --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityBat.java @@ -0,0 +1,43 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityBat extends EntityCreature { + + private boolean hanging; + + public EntityBat(Position spawnPosition) { + super(EntityType.BAT, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_BYTE); + packet.writeByte((byte) (hanging ? 1 : 0)); + } + } + + public boolean isHanging() { + return hanging; + } + + public void setHanging(boolean hanging) { + this.hanging = hanging; + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityBlaze.java b/src/main/java/net/minestom/server/entity/type/EntityBlaze.java new file mode 100644 index 000000000..5cf5674a9 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityBlaze.java @@ -0,0 +1,33 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityBlaze extends EntityCreature { + + public EntityBlaze(Position spawnPosition) { + super(EntityType.BLAZE, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_BYTE); + packet.writeByte((byte) (isOnFire() ? 1 : 0)); + } + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityChicken.java b/src/main/java/net/minestom/server/entity/type/EntityChicken.java new file mode 100644 index 000000000..c9cb32965 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityChicken.java @@ -0,0 +1,11 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.utils.Position; + +public class EntityChicken extends EntityCreature { + public EntityChicken(Position spawnPosition) { + super(EntityType.CHICKEN, spawnPosition); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityCow.java b/src/main/java/net/minestom/server/entity/type/EntityCow.java new file mode 100644 index 000000000..91fea081b --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityCow.java @@ -0,0 +1,11 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.utils.Position; + +public class EntityCow extends EntityCreature { + public EntityCow(Position spawnPosition) { + super(EntityType.COW, spawnPosition); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityCreeper.java b/src/main/java/net/minestom/server/entity/type/EntityCreeper.java new file mode 100644 index 000000000..c9e570e0c --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityCreeper.java @@ -0,0 +1,87 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityCreeper extends EntityCreature { + + private CreeperState creeperState; + private boolean charged; + private boolean ignited; + + public EntityCreeper(Position spawnPosition) { + super(EntityType.CREEPER, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_VARINT); + packet.writeVarInt(creeperState.getState()); + } else if (index == 16) { + packet.writeByte((byte) 16); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(charged); + } else if (index == 17) { + packet.writeByte((byte) 17); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(ignited); + } + } + + public CreeperState getCreeperState() { + return creeperState; + } + + public void setCreeperState(CreeperState creeperState) { + this.creeperState = creeperState; + sendMetadataIndex(15); + } + + public boolean isCharged() { + return charged; + } + + public void setCharged(boolean charged) { + this.charged = charged; + sendMetadataIndex(16); + } + + public boolean isIgnited() { + return ignited; + } + + public void setIgnited(boolean ignited) { + this.ignited = ignited; + sendMetadataIndex(17); + } + + public enum CreeperState { + IDLE(-1), + FUSE(1); + + private int state; + + CreeperState(int state) { + this.state = state; + } + + private int getState() { + return state; + } + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityEndermite.java b/src/main/java/net/minestom/server/entity/type/EntityEndermite.java new file mode 100644 index 000000000..84ea5bac5 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityEndermite.java @@ -0,0 +1,11 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.utils.Position; + +public class EntityEndermite extends EntityCreature { + public EntityEndermite(Position spawnPosition) { + super(EntityType.ENDERMITE, spawnPosition); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityGhast.java b/src/main/java/net/minestom/server/entity/type/EntityGhast.java new file mode 100644 index 000000000..352f5352a --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityGhast.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityGhast extends EntityCreature { + + private boolean attacking; + + public EntityGhast(Position spawnPosition) { + super(EntityType.GHAST, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(attacking); + } + } + + public boolean isAttacking() { + return attacking; + } + + public void setAttacking(boolean attacking) { + this.attacking = attacking; + sendMetadataIndex(15); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityGiant.java b/src/main/java/net/minestom/server/entity/type/EntityGiant.java new file mode 100644 index 000000000..d18220f21 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityGiant.java @@ -0,0 +1,11 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.utils.Position; + +public class EntityGiant extends EntityCreature { + public EntityGiant(Position spawnPosition) { + super(EntityType.GIANT, spawnPosition); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityIronGolem.java b/src/main/java/net/minestom/server/entity/type/EntityIronGolem.java new file mode 100644 index 000000000..1d39e880f --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityIronGolem.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityIronGolem extends EntityCreature { + + private boolean playerCreated; + + public EntityIronGolem(Position spawnPosition) { + super(EntityType.IRON_GOLEM, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_BYTE); + packet.writeByte((byte) (playerCreated ? 1 : 0)); + } + } + + public boolean isPlayerCreated() { + return playerCreated; + } + + public void setPlayerCreated(boolean playerCreated) { + this.playerCreated = playerCreated; + sendMetadataIndex(15); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityMooshroom.java b/src/main/java/net/minestom/server/entity/type/EntityMooshroom.java new file mode 100644 index 000000000..198d000c0 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityMooshroom.java @@ -0,0 +1,60 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityMooshroom extends EntityCreature { + + private MooshroomType mooshroomType; + + public EntityMooshroom(Position spawnPosition) { + super(EntityType.MOOSHROOM, spawnPosition); + setMooshroomType(MooshroomType.RED); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 16); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 16) { + packet.writeByte((byte) 16); + packet.writeByte(METADATA_STRING); + packet.writeSizedString(mooshroomType.getIdentifier()); + } + } + + public MooshroomType getMooshroomType() { + return mooshroomType; + } + + public void setMooshroomType(MooshroomType mooshroomType) { + this.mooshroomType = mooshroomType; + sendMetadataIndex(16); + } + + public enum MooshroomType { + RED("red"), + BROWN("brown"); + + private String identifier; + + MooshroomType(String identifier) { + this.identifier = identifier; + } + + private String getIdentifier() { + return identifier; + } + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityPhantom.java b/src/main/java/net/minestom/server/entity/type/EntityPhantom.java new file mode 100644 index 000000000..cec872fd6 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityPhantom.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityPhantom extends EntityCreature { + + private int size; + + public EntityPhantom(Position spawnPosition) { + super(EntityType.PHANTOM, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_VARINT); + packet.writeVarInt(size); + } + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + sendMetadataIndex(15); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityPig.java b/src/main/java/net/minestom/server/entity/type/EntityPig.java new file mode 100644 index 000000000..ee793281e --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityPig.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityPig extends EntityCreature { + + private boolean saddle; + + public EntityPig(Position spawnPosition) { + super(EntityType.PIG, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 16); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 16) { + packet.writeByte((byte) 16); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(saddle); + } + } + + public boolean hasSaddle() { + return saddle; + } + + public void setSaddle(boolean saddle) { + this.saddle = saddle; + sendMetadataIndex(16); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityPolarBear.java b/src/main/java/net/minestom/server/entity/type/EntityPolarBear.java new file mode 100644 index 000000000..b848ce1fa --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityPolarBear.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityPolarBear extends EntityCreature { + + private boolean standingUp; + + public EntityPolarBear(Position spawnPosition) { + super(EntityType.POLAR_BEAR, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 16); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 16) { + packet.writeByte((byte) 16); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(standingUp); + } + } + + public boolean isStandingUp() { + return standingUp; + } + + public void setStandingUp(boolean standingUp) { + this.standingUp = standingUp; + sendMetadataIndex(16); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityRabbit.java b/src/main/java/net/minestom/server/entity/type/EntityRabbit.java new file mode 100644 index 000000000..aebd5c8cf --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityRabbit.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityRabbit extends EntityCreature { + + private int type; + + public EntityRabbit(Position spawnPosition) { + super(EntityType.RABBIT, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 16); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 16) { + packet.writeByte((byte) 16); + packet.writeByte(METADATA_VARINT); + packet.writeVarInt(type); + } + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + sendMetadataIndex(16); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntitySilverfish.java b/src/main/java/net/minestom/server/entity/type/EntitySilverfish.java new file mode 100644 index 000000000..9f7d8d5b6 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntitySilverfish.java @@ -0,0 +1,11 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.utils.Position; + +public class EntitySilverfish extends EntityCreature { + public EntitySilverfish(Position spawnPosition) { + super(EntityType.SILVERFISH, spawnPosition); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntitySlime.java b/src/main/java/net/minestom/server/entity/type/EntitySlime.java new file mode 100644 index 000000000..6bd92bf12 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntitySlime.java @@ -0,0 +1,45 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntitySlime extends EntityCreature { + + private int size; + + public EntitySlime(Position spawnPosition) { + super(EntityType.SLIME, spawnPosition); + setSize(1); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_VARINT); + packet.writeVarInt(size); + } + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + sendMetadataIndex(15); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntitySnowman.java b/src/main/java/net/minestom/server/entity/type/EntitySnowman.java new file mode 100644 index 000000000..57e74afd1 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntitySnowman.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntitySnowman extends EntityCreature { + + private boolean pumpkinHat; + + public EntitySnowman(Position spawnPosition) { + super(EntityType.SNOW_GOLEM, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_BYTE); + packet.writeByte((byte) (pumpkinHat ? 0x10 : 0x00)); + } + } + + public boolean hasPumpkinHat() { + return pumpkinHat; + } + + public void setPumpkinHat(boolean pumpkinHat) { + this.pumpkinHat = pumpkinHat; + sendMetadataIndex(15); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntitySpider.java b/src/main/java/net/minestom/server/entity/type/EntitySpider.java new file mode 100644 index 000000000..c4de9b06a --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntitySpider.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntitySpider extends EntityCreature { + + private boolean climbing; + + public EntitySpider(Position spawnPosition) { + super(EntityType.SPIDER, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(climbing); + } + } + + public boolean isClimbing() { + return climbing; + } + + public void setClimbing(boolean climbing) { + this.climbing = climbing; + sendMetadataIndex(15); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityWitch.java b/src/main/java/net/minestom/server/entity/type/EntityWitch.java new file mode 100644 index 000000000..f497c7b34 --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityWitch.java @@ -0,0 +1,44 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityWitch extends EntityCreature { + + private boolean drinkingPotion; + + public EntityWitch(Position spawnPosition) { + super(EntityType.WITCH, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 16); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 16) { + packet.writeByte((byte) 16); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(drinkingPotion); + } + } + + public boolean isDrinkingPotion() { + return drinkingPotion; + } + + public void setDrinkingPotion(boolean drinkingPotion) { + this.drinkingPotion = drinkingPotion; + sendMetadataIndex(16); + } +} diff --git a/src/main/java/net/minestom/server/entity/type/EntityZombie.java b/src/main/java/net/minestom/server/entity/type/EntityZombie.java new file mode 100644 index 000000000..398f7646f --- /dev/null +++ b/src/main/java/net/minestom/server/entity/type/EntityZombie.java @@ -0,0 +1,59 @@ +package net.minestom.server.entity.type; + +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.EntityType; +import net.minestom.server.network.packet.PacketWriter; +import net.minestom.server.utils.Position; + +import java.util.function.Consumer; + +public class EntityZombie extends EntityCreature { + + private boolean baby; + private boolean becomingDrowned; + + public EntityZombie(Position spawnPosition) { + super(EntityType.ZOMBIE, spawnPosition); + } + + @Override + public Consumer getMetadataConsumer() { + return packet -> { + super.getMetadataConsumer().accept(packet); + fillMetadataIndex(packet, 15); + fillMetadataIndex(packet, 17); + }; + } + + @Override + protected void fillMetadataIndex(PacketWriter packet, int index) { + super.fillMetadataIndex(packet, index); + if (index == 15) { + packet.writeByte((byte) 15); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(baby); + } else if (index == 17) { + packet.writeByte((byte) 17); + packet.writeByte(METADATA_BOOLEAN); + packet.writeBoolean(becomingDrowned); + } + } + + public boolean isBaby() { + return baby; + } + + public void setBaby(boolean baby) { + this.baby = baby; + sendMetadataIndex(15); + } + + public boolean isBecomingDrowned() { + return becomingDrowned; + } + + public void setBecomingDrowned(boolean becomingDrowned) { + this.becomingDrowned = becomingDrowned; + sendMetadataIndex(17); + } +}