Added EntityEndCrystal

This commit is contained in:
themode 2020-12-22 05:36:15 +01:00
parent b5feb35619
commit 6e0ad54d5e
3 changed files with 85 additions and 0 deletions

View File

@ -66,6 +66,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
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_OPTPOSITION = 10;
protected static final byte METADATA_PARTICLE = 15;
protected static final byte METADATA_POSE = 18;

View File

@ -0,0 +1,76 @@
package net.minestom.server.entity.type.other;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.ObjectEntity;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
public class EntityEndCrystal extends ObjectEntity {
private BlockPosition beamTarget;
private boolean showBottom;
public EntityEndCrystal(@NotNull Position spawnPosition) {
super(EntityType.END_CRYSTAL, spawnPosition);
setBoundingBox(2f, 2f, 2f);
}
@NotNull
@Override
public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> {
super.getMetadataConsumer().accept(packet);
fillMetadataIndex(packet, 7);
fillMetadataIndex(packet, 8);
};
}
@Override
protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index);
if (index == 7) {
final boolean hasTarget = beamTarget != null;
packet.writeByte((byte) 7);
packet.writeByte(METADATA_OPTPOSITION);
packet.writeBoolean(hasTarget);
if (hasTarget) {
packet.writeBlockPosition(beamTarget);
}
} else if (index == 8) {
packet.writeByte((byte) 8);
packet.writeByte(METADATA_BOOLEAN);
packet.writeBoolean(showBottom);
}
}
@Nullable
public BlockPosition getBeamTarget() {
return beamTarget;
}
public void setBeamTarget(@Nullable BlockPosition beamTarget) {
this.beamTarget = beamTarget;
sendMetadataIndex(7);
}
public boolean showBottom() {
return showBottom;
}
public void setShowBottom(boolean showBottom) {
this.showBottom = showBottom;
sendMetadataIndex(8);
}
@Override
public int getObjectData() {
return 0;
}
}

View File

@ -8,6 +8,8 @@ import net.minestom.server.chat.ColoredText;
import net.minestom.server.entity.*;
import net.minestom.server.entity.damage.DamageType;
import net.minestom.server.entity.type.monster.EntityZombie;
import net.minestom.server.entity.type.other.EntityEndCrystal;
import net.minestom.server.event.EntityEvent;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.entity.EntityAttackEvent;
import net.minestom.server.event.item.ItemDropEvent;
@ -189,6 +191,12 @@ public class PlayerInit {
EntityZombie entityZombie = new EntityZombie(new Position(0, 41, 0));
entityZombie.setInstance(player.getInstance());
entityZombie.setPathTo(player.getPosition());
{
EntityEndCrystal entityEndCrystal = new EntityEndCrystal(player.getPosition());
entityEndCrystal.setInstance(instanceContainer);
entityEndCrystal.setBeamTarget(player.getPosition().toBlockPosition().add(5, 5, 0));
}
});
globalEventHandler.addEventCallback(PlayerDisconnectEvent.class, event -> {