Added a bunch of entities + Player#additionalHearts

This commit is contained in:
Felix Cravic 2020-05-26 22:53:58 +02:00
parent fc773044e8
commit e6f38e2773
27 changed files with 823 additions and 17 deletions

View File

@ -28,7 +28,6 @@ public class HealthCommand extends Command<Player> {
}
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 !");

View File

@ -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);

View File

@ -129,6 +129,11 @@ public abstract class EntityCreature extends LivingEntity {
refreshPosition(newX, newY, newZ);
}
@Override
public void spawn() {
}
@Override
public void kill() {
super.kill();

View File

@ -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
};
}

View File

@ -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();

View File

@ -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<PacketWriter> 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;
}

View File

@ -72,17 +72,6 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
return 0;
}
@Override
public void update() {
}
@Override
public void spawn() {
}
@Override
public Consumer<PacketWriter> getMetadataConsumer() {
return packet -> {

View File

@ -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<PacketWriter> 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;
}
}

View File

@ -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<PacketWriter> 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));
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<PacketWriter> 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;
}
}
}

View File

@ -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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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;
}
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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);
}
}

View File

@ -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<PacketWriter> 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);
}
}