Added a few constructors to specify the instance directly

This commit is contained in:
themode 2020-10-31 01:38:57 +01:00
parent f91f7abb26
commit f328a9cb2b
5 changed files with 34 additions and 4 deletions

View File

@ -344,6 +344,8 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
/**
* Updates the entity, called every tick.
* <p>
* Ignored if {@link #getInstance()} returns null.
*
* @param time the update time in milliseconds
*/

View File

@ -55,7 +55,7 @@ public abstract class EntityCreature extends LivingEntity {
private final ReentrantLock pathLock = new ReentrantLock();
public EntityCreature(EntityType entityType, Position spawnPosition) {
public EntityCreature(@NotNull EntityType entityType, @NotNull Position spawnPosition) {
super(entityType, spawnPosition);
this.mainHandItem = ItemStack.getAirItem();
@ -69,6 +69,14 @@ public abstract class EntityCreature extends LivingEntity {
heal();
}
public EntityCreature(@NotNull EntityType entityType, @NotNull Position spawnPosition, @Nullable Instance instance) {
this(entityType, spawnPosition);
if (instance != null) {
setInstance(instance);
}
}
@Override
public void update(long time) {

View File

@ -1,20 +1,31 @@
package net.minestom.server.entity;
import net.minestom.server.instance.Instance;
import net.minestom.server.network.packet.server.play.SpawnExperienceOrbPacket;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.Position;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ExperienceOrb extends Entity {
private short experienceCount;
public ExperienceOrb(short experienceCount) {
super(EntityType.EXPERIENCE_ORB);
public ExperienceOrb(short experienceCount, @NotNull Position spawnPosition) {
super(EntityType.EXPERIENCE_ORB, spawnPosition);
setGravity(0.02f);
setBoundingBox(0.5f, 0.5f, 0.5f);
this.experienceCount = experienceCount;
}
public ExperienceOrb(short experienceCount, @NotNull Position spawnPosition, @Nullable Instance instance) {
this(experienceCount, spawnPosition);
if (instance != null) {
setInstance(instance);
}
}
@Override
public void update(long time) {
// TODO slide toward nearest player

View File

@ -2,6 +2,7 @@ package net.minestom.server.entity;
import net.minestom.server.event.entity.EntityItemMergeEvent;
import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.Instance;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.StackingRule;
import net.minestom.server.utils.Position;
@ -45,6 +46,14 @@ public class ItemEntity extends ObjectEntity {
setBoundingBox(0.25f, 0.25f, 0.25f);
}
public ItemEntity(@NotNull ItemStack itemStack, @NotNull Position spawnPosition, @Nullable Instance instance) {
this(itemStack, spawnPosition);
if (instance != null) {
setInstance(instance);
}
}
/**
* Gets the update option for the merging feature.
*

View File

@ -6,7 +6,7 @@ import net.minestom.server.instance.Instance;
import org.jetbrains.annotations.NotNull;
/**
* Called when a new instance is set for a player
* Called when a new instance is set for a player.
*/
public class PlayerSpawnEvent extends EntitySpawnEvent {