mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Horses
This commit is contained in:
parent
d2c5d87582
commit
7a7c63afc2
@ -0,0 +1,112 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.entity.type.Animal;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntityAbstractHorse extends EntityCreature implements Animal {
|
||||
|
||||
private final static byte TAMED_BIT = 0x02;
|
||||
private final static byte SADDLED_BIT = 0x04;
|
||||
private final static byte HAS_BRED_BIT = 0x08;
|
||||
private final static byte EATING_BIT = 0x10;
|
||||
private final static byte REARING_BIT = 0x20;
|
||||
private final static byte MOUTH_OPEN_BIT = 0x40;
|
||||
|
||||
EntityAbstractHorse(@NotNull EntityType entityType, @NotNull Position spawnPosition) {
|
||||
super(entityType, spawnPosition);
|
||||
}
|
||||
|
||||
EntityAbstractHorse(@NotNull EntityType entityType, @NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(entityType, spawnPosition, instance);
|
||||
}
|
||||
|
||||
public boolean isTamed() {
|
||||
return (getMask() & TAMED_BIT) != 0;
|
||||
}
|
||||
|
||||
public void setTamed(boolean value) {
|
||||
modifyMask(TAMED_BIT, value);
|
||||
}
|
||||
|
||||
public boolean isSaddled() {
|
||||
return (getMask() & SADDLED_BIT) != 0;
|
||||
}
|
||||
|
||||
public void setSaddled(boolean value) {
|
||||
modifyMask(SADDLED_BIT, value);
|
||||
}
|
||||
|
||||
public boolean isHasBred() {
|
||||
return (getMask() & HAS_BRED_BIT) != 0;
|
||||
}
|
||||
|
||||
public void setHasBred(boolean value) {
|
||||
modifyMask(HAS_BRED_BIT, value);
|
||||
}
|
||||
|
||||
public boolean isEating() {
|
||||
return (getMask() & EATING_BIT) != 0;
|
||||
}
|
||||
|
||||
public void setEating(boolean value) {
|
||||
modifyMask(EATING_BIT, value);
|
||||
}
|
||||
|
||||
public boolean isRearing() {
|
||||
return (getMask() & REARING_BIT) != 0;
|
||||
}
|
||||
|
||||
public void setRearing(boolean value) {
|
||||
modifyMask(REARING_BIT, value);
|
||||
}
|
||||
|
||||
public boolean isMouthOpen() {
|
||||
return (getMask() & MOUTH_OPEN_BIT) != 0;
|
||||
}
|
||||
|
||||
public void setMouthOpen(boolean value) {
|
||||
modifyMask(MOUTH_OPEN_BIT, value);
|
||||
}
|
||||
|
||||
public UUID getOwner() {
|
||||
return this.metadata.getIndex((byte) 17, null);
|
||||
}
|
||||
|
||||
public void setOwner(UUID value) {
|
||||
this.metadata.setIndex((byte) 17, Metadata.OptUUID(value));
|
||||
}
|
||||
|
||||
private byte getMask() {
|
||||
return this.metadata.getIndex((byte) 16, (byte) 0);
|
||||
}
|
||||
|
||||
private void setMask(byte mask) {
|
||||
this.metadata.setIndex((byte) 16, Metadata.Byte(mask));
|
||||
}
|
||||
|
||||
private void modifyMask(byte bit, boolean value) {
|
||||
byte mask = getMask();
|
||||
boolean isPresent = (mask & bit) == bit;
|
||||
if (isPresent == value) {
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
mask |= bit;
|
||||
} else {
|
||||
mask &= ~bit;
|
||||
}
|
||||
setMask(mask);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntityChestedHorse extends EntityAbstractHorse {
|
||||
|
||||
EntityChestedHorse(@NotNull EntityType entityType, @NotNull Position spawnPosition) {
|
||||
super(entityType, spawnPosition);
|
||||
}
|
||||
|
||||
EntityChestedHorse(@NotNull EntityType entityType, @NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(entityType, spawnPosition, instance);
|
||||
}
|
||||
|
||||
public boolean hasChest() {
|
||||
return this.metadata.getIndex((byte) 18, false);
|
||||
}
|
||||
|
||||
public void setChest(boolean value) {
|
||||
this.metadata.setIndex((byte) 18, Metadata.Boolean(value));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntityDonkey extends EntityChestedHorse {
|
||||
|
||||
public EntityDonkey(@NotNull Position spawnPosition) {
|
||||
super(EntityType.DONKEY, spawnPosition);
|
||||
setBoundingBox(1.3965D, 1.5D, 1.3965D);
|
||||
}
|
||||
|
||||
public EntityDonkey(@NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(EntityType.DONKEY, spawnPosition, instance);
|
||||
setBoundingBox(1.3965D, 1.5D, 1.3965D);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntityHorse extends EntityAbstractHorse {
|
||||
|
||||
public EntityHorse(@NotNull Position spawnPosition) {
|
||||
super(EntityType.HORSE, spawnPosition);
|
||||
setBoundingBox(1.3965D, 1.6D, 1.3965D);
|
||||
}
|
||||
|
||||
public EntityHorse(@NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(EntityType.HORSE, spawnPosition, instance);
|
||||
setBoundingBox(1.3965D, 1.6D, 1.3965D);
|
||||
}
|
||||
|
||||
public Variant getVariant() {
|
||||
return getVariantFromID(this.metadata.getIndex((byte) 18, 0));
|
||||
}
|
||||
|
||||
public void setVariant(Variant variant) {
|
||||
this.metadata.setIndex((byte) 18, Metadata.VarInt(getVariantID(variant.marking, variant.color)));
|
||||
}
|
||||
|
||||
public static int getVariantID(@NotNull Marking marking, @NotNull Color color) {
|
||||
return (marking.ordinal() << 8) + color.ordinal();
|
||||
}
|
||||
|
||||
public static Variant getVariantFromID(int variantID) {
|
||||
return new Variant(
|
||||
Marking.VALUES[variantID >> 8],
|
||||
Color.VALUES[variantID & 0xFF]
|
||||
);
|
||||
}
|
||||
|
||||
public static class Variant {
|
||||
|
||||
private Marking marking;
|
||||
private Color color;
|
||||
|
||||
public Variant(@NotNull Marking marking, @NotNull Color color) {
|
||||
this.marking = marking;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Marking getMarking() {
|
||||
return this.marking;
|
||||
}
|
||||
|
||||
public void setMarking(@NotNull Marking marking) {
|
||||
this.marking = marking;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Color getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void setColor(@NotNull Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum Marking {
|
||||
NONE,
|
||||
WHITE,
|
||||
WHITE_FIELD,
|
||||
WHITE_DOTS,
|
||||
BLACK_DOTS;
|
||||
|
||||
private final static Marking[] VALUES = values();
|
||||
}
|
||||
|
||||
public enum Color {
|
||||
WHITE,
|
||||
CREAMY,
|
||||
CHESTNUT,
|
||||
BROWN,
|
||||
BLACK,
|
||||
GRAY,
|
||||
DARK_BROWN;
|
||||
|
||||
private final static Color[] VALUES = values();
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,58 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.type.Animal;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EntityLlama extends EntityCreature implements Animal {
|
||||
public EntityLlama(Position spawnPosition) {
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntityLlama extends EntityChestedHorse {
|
||||
|
||||
public EntityLlama(@NotNull Position spawnPosition) {
|
||||
super(EntityType.LLAMA, spawnPosition);
|
||||
setBoundingBox(0.45f, 0.9375f, 0.45f);
|
||||
setBoundingBox(.9D, 1.87D, .9D);
|
||||
}
|
||||
|
||||
public EntityLlama(@NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(EntityType.LLAMA, spawnPosition, instance);
|
||||
setBoundingBox(.9D, 1.87D, .9D);
|
||||
}
|
||||
|
||||
public int getStrength() {
|
||||
return this.metadata.getIndex((byte) 19, 0);
|
||||
}
|
||||
|
||||
public void setStrength(int value) {
|
||||
this.metadata.setIndex((byte) 19, Metadata.VarInt(value));
|
||||
}
|
||||
|
||||
public int getCarpetColor() {
|
||||
return this.metadata.getIndex((byte) 20, -1);
|
||||
}
|
||||
|
||||
public void setCarpetColor(int value) {
|
||||
this.metadata.setIndex((byte) 20, Metadata.VarInt(value));
|
||||
}
|
||||
|
||||
public Variant getVariant() {
|
||||
return Variant.VALUES[this.metadata.getIndex((byte) 21, 0)];
|
||||
}
|
||||
|
||||
public void setVariant(Variant value) {
|
||||
this.metadata.setIndex((byte) 21, Metadata.VarInt(value.ordinal()));
|
||||
}
|
||||
|
||||
public enum Variant {
|
||||
CREAMY,
|
||||
WHITE,
|
||||
BROWN,
|
||||
GRAY;
|
||||
|
||||
private final static Variant[] VALUES = values();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntityMule extends EntityChestedHorse {
|
||||
|
||||
public EntityMule(@NotNull Position spawnPosition) {
|
||||
super(EntityType.MULE, spawnPosition);
|
||||
setBoundingBox(1.3965D, 1.6D, 1.3965D);
|
||||
}
|
||||
|
||||
public EntityMule(@NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(EntityType.MULE, spawnPosition, instance);
|
||||
setBoundingBox(1.3965D, 1.6D, 1.3965D);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntitySkeletonHorse extends EntityAbstractHorse {
|
||||
|
||||
public EntitySkeletonHorse(@NotNull Position spawnPosition) {
|
||||
super(EntityType.SKELETON_HORSE, spawnPosition);
|
||||
setBoundingBox(1.3965D, 1.6D, 1.3965D);
|
||||
}
|
||||
|
||||
public EntitySkeletonHorse(@NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(EntityType.SKELETON_HORSE, spawnPosition, instance);
|
||||
setBoundingBox(1.3965D, 1.6D, 1.3965D);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.minestom.server.entity.type.animal;
|
||||
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by k.shandurenko on 23.02.2021
|
||||
*/
|
||||
public class EntityZombieHorse extends EntityAbstractHorse {
|
||||
|
||||
public EntityZombieHorse(@NotNull Position spawnPosition) {
|
||||
super(EntityType.ZOMBIE_HORSE, spawnPosition);
|
||||
}
|
||||
|
||||
public EntityZombieHorse(@NotNull Position spawnPosition, @Nullable Instance instance) {
|
||||
super(EntityType.ZOMBIE_HORSE, spawnPosition, instance);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user