mirror of
https://github.com/Minestom/Minestom.git
synced 2024-06-26 06:24:54 +02:00
More entity + added boundingboxes
This commit is contained in:
parent
29aae491d1
commit
b0ccb91c31
|
@ -1,19 +1,16 @@
|
|||
package fr.themode.demo.entity;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.type.EntityChicken;
|
||||
import net.minestom.server.entity.vehicle.PlayerVehicleInformation;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.Vector;
|
||||
|
||||
public class ChickenCreature extends EntityCreature {
|
||||
public class ChickenCreature extends EntityChicken {
|
||||
|
||||
public ChickenCreature(Position defaultPosition) {
|
||||
super(EntityType.CHICKEN, defaultPosition);
|
||||
|
||||
setBoundingBox(0.4f, 0.7f, 0.4f);
|
||||
super(defaultPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,6 +50,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||
protected static final byte METADATA_BOOLEAN = 7;
|
||||
protected static final byte METADATA_ROTATION = 8;
|
||||
protected static final byte METADATA_POSITION = 9;
|
||||
protected static final byte METADATA_PARTICLE = 15;
|
||||
protected static final byte METADATA_POSE = 18;
|
||||
|
||||
protected Instance instance;
|
||||
|
|
|
@ -26,7 +26,6 @@ public class ItemEntity extends ObjectEntity {
|
|||
super(EntityType.ITEM, spawnPosition);
|
||||
this.itemStack = itemStack;
|
||||
setBoundingBox(0.25f, 0.25f, 0.25f);
|
||||
setGravity(0.025f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package net.minestom.server.entity.type;
|
||||
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.ObjectEntity;
|
||||
import net.minestom.server.network.packet.PacketWriter;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.utils.Position;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EntityAreaEffectCloud extends ObjectEntity {
|
||||
|
||||
public Consumer<PacketWriter> particleDataConsumer;
|
||||
private float radius;
|
||||
private int color;
|
||||
private boolean ignoreRadius;
|
||||
private Particle particle;
|
||||
|
||||
public EntityAreaEffectCloud(Position spawnPosition) {
|
||||
super(EntityType.AREA_EFFECT_CLOUD, spawnPosition);
|
||||
setRadius(0.5f);
|
||||
setColor(0);
|
||||
setIgnoreRadius(false);
|
||||
setParticle(Particle.EFFECT);
|
||||
setParticleDataConsumer(packetWriter -> {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Consumer<PacketWriter> getMetadataConsumer() {
|
||||
return packet -> {
|
||||
super.getMetadataConsumer().accept(packet);
|
||||
fillMetadataIndex(packet, 7);
|
||||
fillMetadataIndex(packet, 8);
|
||||
fillMetadataIndex(packet, 9);
|
||||
fillMetadataIndex(packet, 10);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillMetadataIndex(PacketWriter packet, int index) {
|
||||
super.fillMetadataIndex(packet, index);
|
||||
if (index == 7) {
|
||||
packet.writeByte((byte) 7);
|
||||
packet.writeByte(METADATA_FLOAT);
|
||||
packet.writeFloat(radius);
|
||||
} else if (index == 8) {
|
||||
packet.writeByte((byte) 8);
|
||||
packet.writeByte(METADATA_VARINT);
|
||||
packet.writeVarInt(color);
|
||||
} else if (index == 9) {
|
||||
packet.writeByte((byte) 9);
|
||||
packet.writeByte(METADATA_BOOLEAN);
|
||||
packet.writeBoolean(ignoreRadius);
|
||||
} else if (index == 10) {
|
||||
packet.writeByte((byte) 10);
|
||||
packet.writeByte(METADATA_PARTICLE);
|
||||
packet.writeVarInt(particle.getId());
|
||||
particleDataConsumer.accept(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getObjectData() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
setBoundingBox(2 * radius, 0.5f, 2 * radius);
|
||||
sendMetadataIndex(7);
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
sendMetadataIndex(8);
|
||||
}
|
||||
|
||||
public boolean isIgnoreRadius() {
|
||||
return ignoreRadius;
|
||||
}
|
||||
|
||||
public void setIgnoreRadius(boolean ignoreRadius) {
|
||||
this.ignoreRadius = ignoreRadius;
|
||||
sendMetadataIndex(9);
|
||||
}
|
||||
|
||||
public Particle getParticle() {
|
||||
return particle;
|
||||
}
|
||||
|
||||
public void setParticle(Particle particle) {
|
||||
this.particle = particle;
|
||||
sendMetadataIndex(10);
|
||||
}
|
||||
|
||||
public Consumer<PacketWriter> getParticleDataConsumer() {
|
||||
return particleDataConsumer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to add data to the particle
|
||||
*
|
||||
* @param particleDataConsumer the particle data consumer
|
||||
* @see @see <a href="https://wiki.vg/Data_types#Particle">Particle data</a>
|
||||
*/
|
||||
public void setParticleDataConsumer(Consumer<PacketWriter> particleDataConsumer) {
|
||||
this.particleDataConsumer = particleDataConsumer;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ public class EntityBat extends EntityCreature {
|
|||
|
||||
public EntityBat(Position spawnPosition) {
|
||||
super(EntityType.BAT, spawnPosition);
|
||||
setBoundingBox(0.5f, 0.9f, 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,6 +11,7 @@ public class EntityBlaze extends EntityCreature {
|
|||
|
||||
public EntityBlaze(Position spawnPosition) {
|
||||
super(EntityType.BLAZE, spawnPosition);
|
||||
setBoundingBox(0.6f, 1.8f, 0.6f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
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 EntityCaveSpider extends EntityCreature {
|
||||
public EntityCaveSpider(Position spawnPosition) {
|
||||
super(EntityType.CAVE_SPIDER, spawnPosition);
|
||||
setBoundingBox(0.7f, 0.5f, 0.7f);
|
||||
}
|
||||
}
|
|
@ -7,5 +7,6 @@ import net.minestom.server.utils.Position;
|
|||
public class EntityChicken extends EntityCreature {
|
||||
public EntityChicken(Position spawnPosition) {
|
||||
super(EntityType.CHICKEN, spawnPosition);
|
||||
setBoundingBox(0.4f, 0.7f, 0.4f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,6 @@ import net.minestom.server.utils.Position;
|
|||
public class EntityCow extends EntityCreature {
|
||||
public EntityCow(Position spawnPosition) {
|
||||
super(EntityType.COW, spawnPosition);
|
||||
setBoundingBox(0.9f, 1.4f, 0.9f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public class EntityCreeper extends EntityCreature {
|
|||
|
||||
public EntityCreeper(Position spawnPosition) {
|
||||
super(EntityType.CREEPER, spawnPosition);
|
||||
setBoundingBox(0.6f, 1.7f, 0.6f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,5 +7,6 @@ import net.minestom.server.utils.Position;
|
|||
public class EntityEndermite extends EntityCreature {
|
||||
public EntityEndermite(Position spawnPosition) {
|
||||
super(EntityType.ENDERMITE, spawnPosition);
|
||||
setBoundingBox(0.4f, 0.3f, 0.4f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntityGhast extends EntityCreature {
|
|||
|
||||
public EntityGhast(Position spawnPosition) {
|
||||
super(EntityType.GHAST, spawnPosition);
|
||||
setBoundingBox(4, 4, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,5 +7,6 @@ import net.minestom.server.utils.Position;
|
|||
public class EntityGiant extends EntityCreature {
|
||||
public EntityGiant(Position spawnPosition) {
|
||||
super(EntityType.GIANT, spawnPosition);
|
||||
setBoundingBox(3.6f, 10.8f, 3.6f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package net.minestom.server.entity.type;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
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 EntityGuardian extends EntityCreature {
|
||||
|
||||
private boolean retractingSpikes;
|
||||
private Entity target;
|
||||
|
||||
public EntityGuardian(Position spawnPosition) {
|
||||
super(EntityType.GUARDIAN, spawnPosition);
|
||||
setBoundingBox(0.85f, 0.85f, 0.85f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Consumer<PacketWriter> getMetadataConsumer() {
|
||||
return packet -> {
|
||||
super.getMetadataConsumer().accept(packet);
|
||||
fillMetadataIndex(packet, 15);
|
||||
fillMetadataIndex(packet, 16);
|
||||
};
|
||||
}
|
||||
|
||||
@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(retractingSpikes);
|
||||
} else if (index == 16) {
|
||||
packet.writeByte((byte) 16);
|
||||
packet.writeByte(METADATA_VARINT);
|
||||
packet.writeVarInt(target == null ? 0 : target.getEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRetractingSpikes() {
|
||||
return retractingSpikes;
|
||||
}
|
||||
|
||||
public void setRetractingSpikes(boolean retractingSpikes) {
|
||||
this.retractingSpikes = retractingSpikes;
|
||||
}
|
||||
|
||||
public Entity getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(Entity target) {
|
||||
this.target = target;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ public class EntityIronGolem extends EntityCreature {
|
|||
|
||||
public EntityIronGolem(Position spawnPosition) {
|
||||
super(EntityType.IRON_GOLEM, spawnPosition);
|
||||
setBoundingBox(1.4f, 2.7f, 1.4f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntityMooshroom extends EntityCreature {
|
|||
|
||||
public EntityMooshroom(Position spawnPosition) {
|
||||
super(EntityType.MOOSHROOM, spawnPosition);
|
||||
setBoundingBox(0.9f, 1.4f, 0.9f);
|
||||
setMooshroomType(MooshroomType.RED);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntityPhantom extends EntityCreature {
|
|||
|
||||
public EntityPhantom(Position spawnPosition) {
|
||||
super(EntityType.PHANTOM, spawnPosition);
|
||||
setBoundingBox(0.9f, 0.5f, 0.9f); // TODO change based on size
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntityPig extends EntityCreature {
|
|||
|
||||
public EntityPig(Position spawnPosition) {
|
||||
super(EntityType.PIG, spawnPosition);
|
||||
setBoundingBox(0.9f, 0.9f, 0.9f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
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 EntityPigZombie extends EntityCreature {
|
||||
public EntityPigZombie(Position spawnPosition) {
|
||||
super(EntityType.ZOMBIE_PIGMAN, spawnPosition);
|
||||
setBoundingBox(0.6f, 1.95f, 0.6f);
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ public class EntityPolarBear extends EntityCreature {
|
|||
|
||||
public EntityPolarBear(Position spawnPosition) {
|
||||
super(EntityType.POLAR_BEAR, spawnPosition);
|
||||
setBoundingBox(1.3f, 1.4f, 1.3f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ public class EntityPotion extends ObjectEntity {
|
|||
|
||||
public EntityPotion(Position spawnPosition, ItemStack potion) {
|
||||
super(EntityType.POTION, spawnPosition);
|
||||
setBoundingBox(0.25f, 0.25f, 0.25f);
|
||||
setPotion(potion);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntityRabbit extends EntityCreature {
|
|||
|
||||
public EntityRabbit(Position spawnPosition) {
|
||||
super(EntityType.RABBIT, spawnPosition);
|
||||
setBoundingBox(0.4f, 0.5f, 0.4f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,5 +7,6 @@ import net.minestom.server.utils.Position;
|
|||
public class EntitySilverfish extends EntityCreature {
|
||||
public EntitySilverfish(Position spawnPosition) {
|
||||
super(EntityType.SILVERFISH, spawnPosition);
|
||||
setBoundingBox(0.4f, 0.3f, 0.4f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public class EntitySlime extends EntityCreature {
|
|||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
final float boxSize = 0.51000005f * size;
|
||||
setBoundingBox(boxSize, boxSize, boxSize);
|
||||
sendMetadataIndex(15);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntitySnowman extends EntityCreature {
|
|||
|
||||
public EntitySnowman(Position spawnPosition) {
|
||||
super(EntityType.SNOW_GOLEM, spawnPosition);
|
||||
setBoundingBox(0.7f, 1.9f, 0.7f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntitySpider extends EntityCreature {
|
|||
|
||||
public EntitySpider(Position spawnPosition) {
|
||||
super(EntityType.SPIDER, spawnPosition);
|
||||
setBoundingBox(1.4f, 0.9f, 1.4f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,7 @@ public class EntityWitch extends EntityCreature {
|
|||
|
||||
public EntityWitch(Position spawnPosition) {
|
||||
super(EntityType.WITCH, spawnPosition);
|
||||
setBoundingBox(0.6f, 1.95f, 0.6f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ public class EntityZombie extends EntityCreature {
|
|||
|
||||
public EntityZombie(Position spawnPosition) {
|
||||
super(EntityType.ZOMBIE, spawnPosition);
|
||||
setBoundingBox(0.6f, 1.95f, 0.6f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -256,6 +256,10 @@ public class ItemStack implements DataContainer {
|
|||
itemStack.setStackingRule(getStackingRule());
|
||||
|
||||
itemStack.enchantmentMap = new HashMap<>(enchantmentMap);
|
||||
itemStack.storedEnchantmentMap = new HashMap<>(storedEnchantmentMap);
|
||||
itemStack.attributes = new ArrayList<>(attributes);
|
||||
itemStack.potionTypes = new HashSet<>(potionTypes);
|
||||
itemStack.hideFlag = hideFlag;
|
||||
|
||||
Data data = getData();
|
||||
if (data != null)
|
||||
|
|
|
@ -29,7 +29,7 @@ public class FakePlayerConnection extends PlayerConnection {
|
|||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
throw new UnsupportedOperationException("FakePlayer does not have anything to flush");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -220,7 +220,6 @@ public class Utils {
|
|||
packet.writeByte((byte) 0x08); // type id (string)
|
||||
packet.writeShortSizedString("Potion");
|
||||
packet.writeShortSizedString("minecraft:" + potionType.name().toLowerCase());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user