mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 15:07:36 +02:00
Merge pull request #25 from razorrider7/EntityType
Update EntityType To use Namespaced IDs
This commit is contained in:
commit
47d956c538
@ -83,7 +83,7 @@ public class ChatHoverEvent {
|
|||||||
public static ChatHoverEvent showEntity(Entity entity) {
|
public static ChatHoverEvent showEntity(Entity entity) {
|
||||||
NBTCompound compound = new NBTCompound()
|
NBTCompound compound = new NBTCompound()
|
||||||
.setString("id", entity.getUuid().toString())
|
.setString("id", entity.getUuid().toString())
|
||||||
.setString("type", EntityType.fromId(entity.getEntityType()).getNamespaceID());
|
.setString("type", entity.getEntityType().getNamespaceID());
|
||||||
return new ChatHoverEvent("show_entity", compound.toSNBT());
|
return new ChatHoverEvent("show_entity", compound.toSNBT());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
private boolean isActive; // False if entity has only been instanced without being added somewhere
|
private boolean isActive; // False if entity has only been instanced without being added somewhere
|
||||||
private boolean shouldRemove;
|
private boolean shouldRemove;
|
||||||
private long scheduledRemoveTime;
|
private long scheduledRemoveTime;
|
||||||
private int entityType;
|
private EntityType entityType;
|
||||||
private long lastUpdate;
|
private long lastUpdate;
|
||||||
private Map<Class<? extends Event>, List<EventCallback>> eventCallbacks = new ConcurrentHashMap<>();
|
private Map<Class<? extends Event>, List<EventCallback>> eventCallbacks = new ConcurrentHashMap<>();
|
||||||
protected long lastVelocityUpdateTime; // Reset velocity to 0 after countdown
|
protected long lastVelocityUpdateTime; // Reset velocity to 0 after countdown
|
||||||
@ -113,7 +113,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
private long ticks;
|
private long ticks;
|
||||||
private final EntityTickEvent tickEvent = new EntityTickEvent(this);
|
private final EntityTickEvent tickEvent = new EntityTickEvent(this);
|
||||||
|
|
||||||
public Entity(int entityType, Position spawnPosition) {
|
public Entity(EntityType entityType, Position spawnPosition) {
|
||||||
this.id = generateId();
|
this.id = generateId();
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
this.uuid = UUID.randomUUID();
|
this.uuid = UUID.randomUUID();
|
||||||
@ -131,7 +131,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
nextTick.add(callback);
|
nextTick.add(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity(int entityType) {
|
public Entity(EntityType entityType) {
|
||||||
this(entityType, new Position());
|
this(entityType, new Position());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +547,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
*
|
*
|
||||||
* @return the entity type id
|
* @return the entity type id
|
||||||
*/
|
*/
|
||||||
public int getEntityType() {
|
public EntityType getEntityType() {
|
||||||
return entityType;
|
return entityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ public abstract class EntityCreature extends LivingEntity {
|
|||||||
SpawnLivingEntityPacket spawnLivingEntityPacket = new SpawnLivingEntityPacket();
|
SpawnLivingEntityPacket spawnLivingEntityPacket = new SpawnLivingEntityPacket();
|
||||||
spawnLivingEntityPacket.entityId = getEntityId();
|
spawnLivingEntityPacket.entityId = getEntityId();
|
||||||
spawnLivingEntityPacket.entityUuid = getUuid();
|
spawnLivingEntityPacket.entityUuid = getUuid();
|
||||||
spawnLivingEntityPacket.entityType = getEntityType();
|
spawnLivingEntityPacket.entityType = getEntityType().getId();
|
||||||
spawnLivingEntityPacket.position = getPosition();
|
spawnLivingEntityPacket.position = getPosition();
|
||||||
spawnLivingEntityPacket.headPitch = 0;
|
spawnLivingEntityPacket.headPitch = 0;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ public class ExperienceOrb extends Entity {
|
|||||||
private short experienceCount;
|
private short experienceCount;
|
||||||
|
|
||||||
public ExperienceOrb(short experienceCount) {
|
public ExperienceOrb(short experienceCount) {
|
||||||
super(23);
|
super(EntityType.EXPERIENCE_ORB);
|
||||||
setGravity(0.02f);
|
setGravity(0.02f);
|
||||||
setBoundingBox(0.5f, 0.5f, 0.5f);
|
setBoundingBox(0.5f, 0.5f, 0.5f);
|
||||||
this.experienceCount = experienceCount;
|
this.experienceCount = experienceCount;
|
||||||
|
@ -55,7 +55,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
private long fireDamagePeriod = 1000L;
|
private long fireDamagePeriod = 1000L;
|
||||||
|
|
||||||
public LivingEntity(EntityType entityType, Position spawnPosition) {
|
public LivingEntity(EntityType entityType, Position spawnPosition) {
|
||||||
super(entityType.getId(), spawnPosition);
|
super(entityType, spawnPosition);
|
||||||
setupAttributes();
|
setupAttributes();
|
||||||
setGravity(0.02f);
|
setGravity(0.02f);
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityDamageEvent entityDamageEvent = new EntityDamageEvent(type, value);
|
EntityDamageEvent entityDamageEvent = new EntityDamageEvent(type, value, this);
|
||||||
callCancellableEvent(EntityDamageEvent.class, entityDamageEvent, () -> {
|
callCancellableEvent(EntityDamageEvent.class, entityDamageEvent, () -> {
|
||||||
float damage = entityDamageEvent.getDamage();
|
float damage = entityDamageEvent.getDamage();
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import net.minestom.server.utils.Position;
|
|||||||
public abstract class ObjectEntity extends Entity {
|
public abstract class ObjectEntity extends Entity {
|
||||||
|
|
||||||
public ObjectEntity(EntityType entityType, Position spawnPosition) {
|
public ObjectEntity(EntityType entityType, Position spawnPosition) {
|
||||||
super(entityType.getId(), spawnPosition);
|
super(entityType, spawnPosition);
|
||||||
setGravity(0.02f);
|
setGravity(0.02f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public abstract class ObjectEntity extends Entity {
|
|||||||
SpawnEntityPacket spawnEntityPacket = new SpawnEntityPacket();
|
SpawnEntityPacket spawnEntityPacket = new SpawnEntityPacket();
|
||||||
spawnEntityPacket.entityId = getEntityId();
|
spawnEntityPacket.entityId = getEntityId();
|
||||||
spawnEntityPacket.uuid = getUuid();
|
spawnEntityPacket.uuid = getUuid();
|
||||||
spawnEntityPacket.type = getEntityType();
|
spawnEntityPacket.type = getEntityType().getId();
|
||||||
spawnEntityPacket.position = getPosition();
|
spawnEntityPacket.position = getPosition();
|
||||||
spawnEntityPacket.data = getObjectData();
|
spawnEntityPacket.data = getObjectData();
|
||||||
playerConnection.sendPacket(spawnEntityPacket);
|
playerConnection.sendPacket(spawnEntityPacket);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.minestom.server.event.entity;
|
package net.minestom.server.event.entity;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.Entity;
|
||||||
|
import net.minestom.server.entity.LivingEntity;
|
||||||
import net.minestom.server.entity.damage.DamageType;
|
import net.minestom.server.entity.damage.DamageType;
|
||||||
import net.minestom.server.event.CancellableEvent;
|
import net.minestom.server.event.CancellableEvent;
|
||||||
|
|
||||||
@ -10,10 +12,12 @@ public class EntityDamageEvent extends CancellableEvent {
|
|||||||
|
|
||||||
private DamageType damageType;
|
private DamageType damageType;
|
||||||
private float damage;
|
private float damage;
|
||||||
|
private LivingEntity entity;
|
||||||
|
|
||||||
public EntityDamageEvent(DamageType damageType, float damage) {
|
public EntityDamageEvent(DamageType damageType, float damage, LivingEntity entity) {
|
||||||
this.damageType = damageType;
|
this.damageType = damageType;
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
|
this.entity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,4 +40,8 @@ public class EntityDamageEvent extends CancellableEvent {
|
|||||||
public void setDamage(float damage) {
|
public void setDamage(float damage) {
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LivingEntity getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user