Update to support MCProtocolLib entity metadata changes

This commit is contained in:
RednedEpic 2021-11-20 13:25:21 -06:00
parent f797f84878
commit 1e0b312d9d
71 changed files with 301 additions and 324 deletions

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -45,8 +44,8 @@ public class AbstractArrowEntity extends Entity {
setMotion(motion); setMotion(motion);
} }
public void setArrowFlags(EntityMetadata<Byte> entityMetadata) { public void setArrowFlags(ByteEntityMetadata entityMetadata) {
byte data = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte data = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.CRITICAL, (data & 0x01) == 0x01); setFlag(EntityFlag.CRITICAL, (data & 0x01) == 0x01);
} }

View file

@ -56,13 +56,13 @@ public class AreaEffectCloudEntity extends Entity {
setFlag(EntityFlag.FIRE_IMMUNE, true); setFlag(EntityFlag.FIRE_IMMUNE, true);
} }
public void setRadius(EntityMetadata<Float> entityMetadata) { public void setRadius(FloatEntityMetadata entityMetadata) {
float value = ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(); float value = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, value); dirtyMetadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, value);
dirtyMetadata.put(EntityData.BOUNDING_BOX_WIDTH, 2.0f * value); dirtyMetadata.put(EntityData.BOUNDING_BOX_WIDTH, 2.0f * value);
} }
public void setParticle(EntityMetadata<Particle> entityMetadata) { public void setParticle(EntityMetadata<Particle, ?> entityMetadata) {
Particle particle = entityMetadata.getValue(); Particle particle = entityMetadata.getValue();
int particleId = EffectUtils.getParticleId(session, particle.getType()); int particleId = EffectUtils.getParticleId(session, particle.getType());
if (particleId != -1) { if (particleId != -1) {

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -114,13 +113,13 @@ public class BoatEntity extends Entity {
moveRelative(0, 0, 0, yaw + 90, 0, 0, isOnGround); moveRelative(0, 0, 0, yaw + 90, 0, 0, isOnGround);
} }
public void setVariant(EntityMetadata<Integer> entityMetadata) { public void setVariant(IntEntityMetadata entityMetadata) {
variant = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); variant = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.VARIANT, variant); dirtyMetadata.put(EntityData.VARIANT, variant);
} }
public void setPaddlingLeft(EntityMetadata<Boolean> entityMetadata) { public void setPaddlingLeft(BooleanEntityMetadata entityMetadata) {
isPaddlingLeft = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); isPaddlingLeft = entityMetadata.getPrimitiveValue();
if (isPaddlingLeft) { if (isPaddlingLeft) {
// Java sends simply "true" and "false" (is_paddling_left), Bedrock keeps sending packets as you're rowing // Java sends simply "true" and "false" (is_paddling_left), Bedrock keeps sending packets as you're rowing
// This is an asynchronous method that emulates Bedrock rowing until "false" is sent. // This is an asynchronous method that emulates Bedrock rowing until "false" is sent.
@ -138,8 +137,8 @@ public class BoatEntity extends Entity {
} }
} }
public void setPaddlingRight(EntityMetadata<Boolean> entityMetadata) { public void setPaddlingRight(BooleanEntityMetadata entityMetadata) {
isPaddlingRight = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); isPaddlingRight = entityMetadata.getPrimitiveValue();
if (isPaddlingRight) { if (isPaddlingRight) {
paddleTimeRight = 0f; paddleTimeRight = 0f;
if (!this.passengers.isEmpty()) { if (!this.passengers.isEmpty()) {

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -56,7 +55,7 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
} }
@Override @Override
public void setCustomBlock(EntityMetadata<Integer> entityMetadata) { public void setCustomBlock(IntEntityMetadata entityMetadata) {
customBlock = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); customBlock = ((IntEntityMetadata) entityMetadata).getPrimitiveValue();
if (showCustomBlock) { if (showCustomBlock) {
@ -65,8 +64,8 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
} }
@Override @Override
public void setCustomBlockOffset(EntityMetadata<Integer> entityMetadata) { public void setCustomBlockOffset(IntEntityMetadata entityMetadata) {
customBlockOffset = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); customBlockOffset = entityMetadata.getPrimitiveValue();
if (showCustomBlock) { if (showCustomBlock) {
dirtyMetadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset); dirtyMetadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset);
@ -74,8 +73,8 @@ public class DefaultBlockMinecartEntity extends MinecartEntity {
} }
@Override @Override
public void setShowCustomBlock(EntityMetadata<Boolean> entityMetadata) { public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) {
if (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()) { if (entityMetadata.getPrimitiveValue()) {
showCustomBlock = true; showCustomBlock = true;
dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock)); dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(customBlock));
dirtyMetadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset); dirtyMetadata.put(EntityData.DISPLAY_OFFSET, customBlockOffset);

View file

@ -33,6 +33,7 @@ import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class EnderCrystalEntity extends Entity { public class EnderCrystalEntity extends Entity {
@ -48,12 +49,13 @@ public class EnderCrystalEntity extends Entity {
setFlag(EntityFlag.FIRE_IMMUNE, true); setFlag(EntityFlag.FIRE_IMMUNE, true);
} }
public void setBlockTarget(EntityMetadata<Position> entityMetadata) { public void setBlockTarget(EntityMetadata<Optional<Position>, ?> entityMetadata) {
// Show beam // Show beam
// Usually performed client-side on Bedrock except for Ender Dragon respawn event // Usually performed client-side on Bedrock except for Ender Dragon respawn event
Position position = entityMetadata.getValue(); Optional<Position> optionalPos = entityMetadata.getValue();
if (position != null) { if (optionalPos.isPresent()) {
dirtyMetadata.put(EntityData.BLOCK_TARGET, Vector3i.from(position.getX(), position.getY(), position.getZ())); Position pos = optionalPos.get();
dirtyMetadata.put(EntityData.BLOCK_TARGET, Vector3i.from(pos.getX(), pos.getY(), pos.getZ()));
} else { } else {
dirtyMetadata.put(EntityData.BLOCK_TARGET, Vector3i.ZERO); dirtyMetadata.put(EntityData.BLOCK_TARGET, Vector3i.ZERO);
} }

View file

@ -47,6 +47,7 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.chat.MessageTranslator; import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.utils.MathUtils; import org.geysermc.connector.utils.MathUtils;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@Getter @Getter
@ -120,7 +121,7 @@ public class Entity {
this.valid = false; this.valid = false;
setPosition(position); setPosition(position);
setAir(getMaxAir()); setAirSupply(getMaxAir());
initializeMetadata(); initializeMetadata();
} }
@ -304,8 +305,8 @@ public class Entity {
} }
} }
public void setFlags(EntityMetadata<Byte> entityMetadata) { public void setFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.ON_FIRE, ((xd & 0x01) == 0x01) && !getFlag(EntityFlag.FIRE_IMMUNE)); // Otherwise immune entities sometimes flicker onfire setFlag(EntityFlag.ON_FIRE, ((xd & 0x01) == 0x01) && !getFlag(EntityFlag.FIRE_IMMUNE)); // Otherwise immune entities sometimes flicker onfire
setFlag(EntityFlag.SNEAKING, (xd & 0x02) == 0x02); setFlag(EntityFlag.SNEAKING, (xd & 0x02) == 0x02);
setFlag(EntityFlag.SPRINTING, (xd & 0x08) == 0x08); setFlag(EntityFlag.SPRINTING, (xd & 0x08) == 0x08);
@ -327,11 +328,11 @@ public class Entity {
/** /**
* Set an int from 0 - this entity's maximum air - (air / maxAir) represents the percentage of bubbles left * Set an int from 0 - this entity's maximum air - (air / maxAir) represents the percentage of bubbles left
*/ */
public final void setAir(EntityMetadata<?> entityMetadata) { public final void setAir(IntEntityMetadata entityMetadata) {
setAir(((IntEntityMetadata) entityMetadata).getPrimitiveValue()); setAirSupply(entityMetadata.getPrimitiveValue());
} }
protected void setAir(int amount) { protected void setAirSupply(int amount) {
dirtyMetadata.put(EntityData.AIR_SUPPLY, (short) MathUtils.constrain(amount, 0, getMaxAir())); dirtyMetadata.put(EntityData.AIR_SUPPLY, (short) MathUtils.constrain(amount, 0, getMaxAir()));
} }
@ -339,10 +340,10 @@ public class Entity {
return 300; return 300;
} }
public void setDisplayName(EntityMetadata<Component> entityMetadata) { public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
Component name = entityMetadata.getValue(); Optional<Component> name = entityMetadata.getValue();
if (name != null) { if (name.isPresent()) {
nametag = MessageTranslator.convertMessage(name, session.getLocale()); nametag = MessageTranslator.convertMessage(name.get(), session.getLocale());
dirtyMetadata.put(EntityData.NAMETAG, nametag); dirtyMetadata.put(EntityData.NAMETAG, nametag);
} else if (!nametag.isEmpty()) { } else if (!nametag.isEmpty()) {
// Clear nametag // Clear nametag
@ -350,18 +351,18 @@ public class Entity {
} }
} }
public void setDisplayNameVisible(EntityMetadata<Boolean> entityMetadata) { public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) {
dirtyMetadata.put(EntityData.NAMETAG_ALWAYS_SHOW, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)); dirtyMetadata.put(EntityData.NAMETAG_ALWAYS_SHOW, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0));
} }
public void setGravity(EntityMetadata<Boolean> entityMetadata) { public void setGravity(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.HAS_GRAVITY, !((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.HAS_GRAVITY, !entityMetadata.getPrimitiveValue());
} }
/** /**
* Usually used for bounding box and not animation. * Usually used for bounding box and not animation.
*/ */
public void setPose(EntityMetadata<Pose> entityMetadata) { public void setPose(EntityMetadata<Pose, ?> entityMetadata) {
Pose pose = entityMetadata.getValue(); Pose pose = entityMetadata.getValue();
setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING)); setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING));
@ -396,7 +397,7 @@ public class Entity {
/** /**
* Set a float from 0-1 - how strong the "frozen" overlay should be on screen. * Set a float from 0-1 - how strong the "frozen" overlay should be on screen.
*/ */
public float setFreezing(EntityMetadata<Integer> entityMetadata) { public float setFreezing(IntEntityMetadata entityMetadata) {
// The value that Java edition gives us is in ticks, but Bedrock uses a float percentage of the strength 0.0 -> 1.0 // The value that Java edition gives us is in ticks, but Bedrock uses a float percentage of the strength 0.0 -> 1.0
// The Java client caps its freezing tick percentage at 140 // The Java client caps its freezing tick percentage at 140
int freezingTicks = Math.min(((IntEntityMetadata) entityMetadata).getPrimitiveValue(), 140); int freezingTicks = Math.min(((IntEntityMetadata) entityMetadata).getPrimitiveValue(), 140);

View file

@ -31,6 +31,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.factory.BaseEntityFactory; import org.geysermc.connector.entity.factory.BaseEntityFactory;
import org.geysermc.connector.entity.factory.EntityFactory; import org.geysermc.connector.entity.factory.EntityFactory;
import org.geysermc.connector.registry.Registries; import org.geysermc.connector.registry.Registries;
@ -47,7 +48,7 @@ import java.util.function.BiConsumer;
* @param <T> the entity type this definition represents * @param <T> the entity type this definition represents
*/ */
public record EntityDefinition<T extends Entity>(EntityFactory<T> factory, EntityType entityType, String identifier, public record EntityDefinition<T extends Entity>(EntityFactory<T> factory, EntityType entityType, String identifier,
float width, float height, float offset, List<EntityMetadataTranslator<? super T, ?>> translators) { float width, float height, float offset, List<EntityMetadataTranslator<? super T, ?, ?>> translators) {
public static <T extends Entity> Builder<T> inherited(BaseEntityFactory<T> factory, EntityDefinition<? super T> parent) { public static <T extends Entity> Builder<T> inherited(BaseEntityFactory<T> factory, EntityDefinition<? super T> parent) {
return inherited((EntityFactory<T>) factory, parent); return inherited((EntityFactory<T>) factory, parent);
@ -61,6 +62,25 @@ public record EntityDefinition<T extends Entity>(EntityFactory<T> factory, Entit
return new Builder<>(factory); return new Builder<>(factory);
} }
public <M> void translateMetadata(T entity, EntityMetadata<M, ? extends MetadataType<M>> metadata) {
EntityMetadataTranslator<? super T, M, EntityMetadata<M, ? extends MetadataType<M>>> translator = (EntityMetadataTranslator<? super T, M, EntityMetadata<M, ? extends MetadataType<M>>>) this.translators.get(metadata.getId());
if (translator == null) {
// This can safely happen; it means we don't translate this entity metadata
return;
}
if (translator.acceptedType() != metadata.getType()) {
GeyserConnector.getInstance().getLogger().warning("Metadata ID " + metadata.getId() + " was received with type " + metadata.getType() + " but we expected " + translator.acceptedType() + " for " + entity.getDefinition().entityType());
if (GeyserConnector.getInstance().getConfig().isDebugMode()) {
GeyserConnector.getInstance().getLogger().debug(metadata.toString());
}
return;
}
translator.translateFunction().accept(entity, metadata);
}
@Setter @Setter
@Accessors(fluent = true, chain = true) @Accessors(fluent = true, chain = true)
public static class Builder<T extends Entity> { public static class Builder<T extends Entity> {
@ -70,14 +90,14 @@ public record EntityDefinition<T extends Entity>(EntityFactory<T> factory, Entit
private float width; private float width;
private float height; private float height;
private float offset; private float offset;
private final List<EntityMetadataTranslator<? super T, ?>> translators; private final List<EntityMetadataTranslator<? super T, ?, ?>> translators;
private Builder(EntityFactory<T> factory) { private Builder(EntityFactory<T> factory) {
this.factory = factory; this.factory = factory;
translators = new ObjectArrayList<>(); translators = new ObjectArrayList<>();
} }
public Builder(EntityFactory<T> factory, EntityType type, String identifier, float width, float height, float offset, List<EntityMetadataTranslator<? super T, ?>> translators) { public Builder(EntityFactory<T> factory, EntityType type, String identifier, float width, float height, float offset, List<EntityMetadataTranslator<? super T, ?, ?>> translators) {
this.factory = factory; this.factory = factory;
this.type = type; this.type = type;
this.identifier = identifier; this.identifier = identifier;
@ -105,12 +125,12 @@ public record EntityDefinition<T extends Entity>(EntityFactory<T> factory, Entit
return this; return this;
} }
public <U> Builder<T> addTranslator(MetadataType type, BiConsumer<T, EntityMetadata<U>> translateFunction) { public <U, EM extends EntityMetadata<U, ? extends MetadataType<U>>> Builder<T> addTranslator(MetadataType<U> type, BiConsumer<T, EM> translateFunction) {
translators.add(new EntityMetadataTranslator<>(type, translateFunction)); translators.add(new EntityMetadataTranslator<>(type, translateFunction));
return this; return this;
} }
public Builder<T> addTranslator(EntityMetadataTranslator<T, ?> translator) { public Builder<T> addTranslator(EntityMetadataTranslator<T, ?, ?> translator) {
translators.add(translator); translators.add(translator);
return this; return this;
} }

View file

@ -31,7 +31,6 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEnt
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType; import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import net.kyori.adventure.text.Component;
import org.geysermc.connector.entity.factory.BaseEntityFactory; import org.geysermc.connector.entity.factory.BaseEntityFactory;
import org.geysermc.connector.entity.factory.ExperienceOrbEntityFactory; import org.geysermc.connector.entity.factory.ExperienceOrbEntityFactory;
import org.geysermc.connector.entity.factory.PaintingEntityFactory; import org.geysermc.connector.entity.factory.PaintingEntityFactory;
@ -182,7 +181,7 @@ public final class EntityDefinitions {
.addTranslator(MetadataType.INT, Entity::setAir) // Air/bubbles .addTranslator(MetadataType.INT, Entity::setAir) // Air/bubbles
.addTranslator(MetadataType.OPTIONAL_CHAT, Entity::setDisplayName) .addTranslator(MetadataType.OPTIONAL_CHAT, Entity::setDisplayName)
.addTranslator(MetadataType.BOOLEAN, Entity::setDisplayNameVisible) .addTranslator(MetadataType.BOOLEAN, Entity::setDisplayNameVisible)
.<Boolean>addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.SILENT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.SILENT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.addTranslator(MetadataType.BOOLEAN, Entity::setGravity) .addTranslator(MetadataType.BOOLEAN, Entity::setGravity)
.addTranslator(MetadataType.POSE, Entity::setPose) .addTranslator(MetadataType.POSE, Entity::setPose)
.addTranslator(MetadataType.INT, Entity::setFreezing) .addTranslator(MetadataType.INT, Entity::setFreezing)
@ -204,7 +203,7 @@ public final class EntityDefinitions {
.offset(0.35f) .offset(0.35f)
.addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.HURT_TIME, entityMetadata.getValue())) // Time since last hit .addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.HURT_TIME, entityMetadata.getValue())) // Time since last hit
.addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.HURT_DIRECTION, entityMetadata.getValue())) // Rocking direction .addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.HURT_DIRECTION, entityMetadata.getValue())) // Rocking direction
.<Float>addTranslator(MetadataType.FLOAT, (boatEntity, entityMetadata) -> .addTranslator(MetadataType.FLOAT, (boatEntity, entityMetadata) ->
// 'Health' in Bedrock, damage taken in Java - it makes motion in Bedrock // 'Health' in Bedrock, damage taken in Java - it makes motion in Bedrock
boatEntity.getDirtyMetadata().put(EntityData.HEALTH, 40 - ((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue()))) boatEntity.getDirtyMetadata().put(EntityData.HEALTH, 40 - ((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue())))
.addTranslator(MetadataType.INT, BoatEntity::setVariant) .addTranslator(MetadataType.INT, BoatEntity::setVariant)
@ -220,7 +219,7 @@ public final class EntityDefinitions {
.type(EntityType.END_CRYSTAL) .type(EntityType.END_CRYSTAL)
.heightAndWidth(2.0f) .heightAndWidth(2.0f)
.addTranslator(MetadataType.OPTIONAL_POSITION, EnderCrystalEntity::setBlockTarget) .addTranslator(MetadataType.OPTIONAL_POSITION, EnderCrystalEntity::setBlockTarget)
.<Boolean>addTranslator(MetadataType.BOOLEAN, .addTranslator(MetadataType.BOOLEAN,
(enderCrystalEntity, entityMetadata) -> enderCrystalEntity.setFlag(EntityFlag.SHOW_BOTTOM, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) // There is a base located on the ender crystal (enderCrystalEntity, entityMetadata) -> enderCrystalEntity.setFlag(EntityFlag.SHOW_BOTTOM, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) // There is a base located on the ender crystal
.build(); .build();
EXPERIENCE_ORB = EntityDefinition.inherited((ExperienceOrbEntityFactory) ExpOrbEntity::new, entityBase) EXPERIENCE_ORB = EntityDefinition.inherited((ExperienceOrbEntityFactory) ExpOrbEntity::new, entityBase)
@ -337,7 +336,7 @@ public final class EntityDefinitions {
.type(EntityType.TRIDENT) .type(EntityType.TRIDENT)
.identifier("minecraft:thrown_trident") .identifier("minecraft:thrown_trident")
.addTranslator(null) // Loyalty .addTranslator(null) // Loyalty
.<Boolean>addTranslator(MetadataType.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.build(); .build();
// Item frames are handled differently as they are blocks, not items, in Bedrock // Item frames are handled differently as they are blocks, not items, in Bedrock
@ -356,7 +355,7 @@ public final class EntityDefinitions {
.offset(0.35f) .offset(0.35f)
.addTranslator(MetadataType.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityData.HEALTH, entityMetadata.getValue())) .addTranslator(MetadataType.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityData.HEALTH, entityMetadata.getValue()))
.addTranslator(MetadataType.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityData.HURT_DIRECTION, entityMetadata.getValue())) // Direction in which the minecart is shaking .addTranslator(MetadataType.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityData.HURT_DIRECTION, entityMetadata.getValue())) // Direction in which the minecart is shaking
.<Float>addTranslator(MetadataType.FLOAT, (minecartEntity, entityMetadata) -> .addTranslator(MetadataType.FLOAT, (minecartEntity, entityMetadata) ->
// Power in Java, time in Bedrock // Power in Java, time in Bedrock
minecartEntity.getDirtyMetadata().put(EntityData.HURT_TIME, Math.min((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(), 15))) minecartEntity.getDirtyMetadata().put(EntityData.HURT_TIME, Math.min((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(), 15)))
.addTranslator(MetadataType.INT, MinecartEntity::setCustomBlock) .addTranslator(MetadataType.INT, MinecartEntity::setCustomBlock)
@ -371,7 +370,7 @@ public final class EntityDefinitions {
.type(EntityType.MINECART_COMMAND_BLOCK) .type(EntityType.MINECART_COMMAND_BLOCK)
.identifier("minecraft:command_block_minecart") .identifier("minecraft:command_block_minecart")
.addTranslator(MetadataType.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.COMMAND_BLOCK_COMMAND, entityMetadata.getValue())) .addTranslator(MetadataType.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.COMMAND_BLOCK_COMMAND, entityMetadata.getValue()))
.<Component>addTranslator(MetadataType.CHAT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.COMMAND_BLOCK_LAST_OUTPUT, MessageTranslator.convertMessage(entityMetadata.getValue()))) .addTranslator(MetadataType.CHAT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.COMMAND_BLOCK_LAST_OUTPUT, MessageTranslator.convertMessage(entityMetadata.getValue())))
.build(); .build();
MINECART_FURNACE = EntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART) MINECART_FURNACE = EntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART)
.type(EntityType.MINECART_FURNACE) .type(EntityType.MINECART_FURNACE)
@ -403,9 +402,9 @@ public final class EntityDefinitions {
EntityDefinition<LivingEntity> livingEntityBase = EntityDefinition.inherited(LivingEntity::new, entityBase) EntityDefinition<LivingEntity> livingEntityBase = EntityDefinition.inherited(LivingEntity::new, entityBase)
.addTranslator(MetadataType.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataType.BYTE, LivingEntity::setLivingEntityFlags)
.addTranslator(MetadataType.FLOAT, LivingEntity::setHealth) .addTranslator(MetadataType.FLOAT, LivingEntity::setHealth)
.<Float>addTranslator(MetadataType.INT, .addTranslator(MetadataType.INT,
(livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityData.EFFECT_COLOR, entityMetadata.getValue())) (livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityData.EFFECT_COLOR, entityMetadata.getValue()))
.<Boolean>addTranslator(MetadataType.BOOLEAN, .addTranslator(MetadataType.BOOLEAN,
(livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityData.EFFECT_AMBIENT, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0))) (livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityData.EFFECT_AMBIENT, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)))
.addTranslator(null) // Arrow count .addTranslator(null) // Arrow count
.addTranslator(null) // Stinger count .addTranslator(null) // Stinger count
@ -460,7 +459,7 @@ public final class EntityDefinitions {
.height(1.7f).width(0.6f) .height(1.7f).width(0.6f)
.offset(1.62f) .offset(1.62f)
.addTranslator(MetadataType.INT, CreeperEntity::setSwelling) .addTranslator(MetadataType.INT, CreeperEntity::setSwelling)
.<Boolean>addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.POWERED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.POWERED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.addTranslator(MetadataType.BOOLEAN, CreeperEntity::setIgnited) .addTranslator(MetadataType.BOOLEAN, CreeperEntity::setIgnited)
.build(); .build();
DOLPHIN = EntityDefinition.inherited(WaterEntity::new, mobEntityBase) DOLPHIN = EntityDefinition.inherited(WaterEntity::new, mobEntityBase)
@ -746,12 +745,12 @@ public final class EntityDefinitions {
MOOSHROOM = EntityDefinition.inherited(MooshroomEntity::new, ageableEntityBase) // TODO remove class MOOSHROOM = EntityDefinition.inherited(MooshroomEntity::new, ageableEntityBase) // TODO remove class
.type(EntityType.MOOSHROOM) .type(EntityType.MOOSHROOM)
.height(1.4f).width(0.9f) .height(1.4f).width(0.9f)
.<String>addTranslator(MetadataType.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.VARIANT, entityMetadata.getValue().equals("brown") ? 1 : 0)) .addTranslator(MetadataType.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.VARIANT, entityMetadata.getValue().equals("brown") ? 1 : 0))
.build(); .build();
OCELOT = EntityDefinition.inherited(OcelotEntity::new, ageableEntityBase) OCELOT = EntityDefinition.inherited(OcelotEntity::new, ageableEntityBase)
.type(EntityType.OCELOT) .type(EntityType.OCELOT)
.height(0.35f).width(0.3f) .height(0.35f).width(0.3f)
.<Boolean>addTranslator(MetadataType.BOOLEAN, (ocelotEntity, entityMetadata) -> ocelotEntity.setFlag(EntityFlag.TRUSTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (ocelotEntity, entityMetadata) -> ocelotEntity.setFlag(EntityFlag.TRUSTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.build(); .build();
PANDA = EntityDefinition.inherited(PandaEntity::new, ageableEntityBase) PANDA = EntityDefinition.inherited(PandaEntity::new, ageableEntityBase)
.type(EntityType.PANDA) .type(EntityType.PANDA)
@ -766,13 +765,13 @@ public final class EntityDefinitions {
PIG = EntityDefinition.inherited(PigEntity::new, ageableEntityBase) PIG = EntityDefinition.inherited(PigEntity::new, ageableEntityBase)
.type(EntityType.PIG) .type(EntityType.PIG)
.heightAndWidth(0.9f) .heightAndWidth(0.9f)
.<Boolean>addTranslator(MetadataType.BOOLEAN, (pigEntity, entityMetadata) -> pigEntity.setFlag(EntityFlag.SADDLED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (pigEntity, entityMetadata) -> pigEntity.setFlag(EntityFlag.SADDLED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.addTranslator(null) // Boost time .addTranslator(null) // Boost time
.build(); .build();
POLAR_BEAR = EntityDefinition.inherited(PolarBearEntity::new, ageableEntityBase) POLAR_BEAR = EntityDefinition.inherited(PolarBearEntity::new, ageableEntityBase)
.type(EntityType.POLAR_BEAR) .type(EntityType.POLAR_BEAR)
.height(1.4f).width(1.3f) .height(1.4f).width(1.3f)
.<Boolean>addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.STANDING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.STANDING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.build(); .build();
RABBIT = EntityDefinition.inherited(RabbitEntity::new, ageableEntityBase) RABBIT = EntityDefinition.inherited(RabbitEntity::new, ageableEntityBase)
.type(EntityType.RABBIT) .type(EntityType.RABBIT)
@ -839,7 +838,7 @@ public final class EntityDefinitions {
.height(1.6f).width(1.3965f) .height(1.6f).width(1.3965f)
.build(); .build();
EntityDefinition<ChestedHorseEntity> chestedHorseEntityBase = EntityDefinition.inherited(ChestedHorseEntity::new, abstractHorseEntityBase) EntityDefinition<ChestedHorseEntity> chestedHorseEntityBase = EntityDefinition.inherited(ChestedHorseEntity::new, abstractHorseEntityBase)
.<Boolean>addTranslator(MetadataType.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.build(); .build();
DONKEY = EntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) DONKEY = EntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase)
.type(EntityType.DONKEY) .type(EntityType.DONKEY)
@ -852,7 +851,7 @@ public final class EntityDefinitions {
LLAMA = EntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase) LLAMA = EntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase)
.type(EntityType.LLAMA) .type(EntityType.LLAMA)
.height(1.87f).width(0.9f) .height(1.87f).width(0.9f)
.<Integer>addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.STRENGTH, entityMetadata.getValue())) .addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.STRENGTH, entityMetadata.getValue()))
.addTranslator(MetadataType.INT, LlamaEntity::setCarpetedColor) .addTranslator(MetadataType.INT, LlamaEntity::setCarpetedColor)
.addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.VARIANT, entityMetadata.getValue())) .addTranslator(MetadataType.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityData.VARIANT, entityMetadata.getValue()))
.build(); .build();
@ -883,7 +882,7 @@ public final class EntityDefinitions {
.type(EntityType.WOLF) .type(EntityType.WOLF)
.height(0.85f).width(0.6f) .height(0.85f).width(0.6f)
// "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head // "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head
.<Boolean>addTranslator(MetadataType.BOOLEAN, (wolfEntity, entityMetadata) -> wolfEntity.setFlag(EntityFlag.INTERESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataType.BOOLEAN, (wolfEntity, entityMetadata) -> wolfEntity.setFlag(EntityFlag.INTERESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.addTranslator(MetadataType.INT, WolfEntity::setCollarColor) .addTranslator(MetadataType.INT, WolfEntity::setCollarColor)
.addTranslator(MetadataType.INT, WolfEntity::setWolfAngerTime) .addTranslator(MetadataType.INT, WolfEntity::setWolfAngerTime)
.build(); .build();

View file

@ -33,8 +33,7 @@ import java.util.function.BiConsumer;
/** /**
* Translates a given Java {@link EntityMetadata} into a similar/same construct for Bedrock * Translates a given Java {@link EntityMetadata} into a similar/same construct for Bedrock
*/ */
public record EntityMetadataTranslator<E extends Entity, T, EM extends EntityMetadata<T, ? extends MetadataType<T>>>(
public record EntityMetadataTranslator<E extends Entity, T>( MetadataType<T> acceptedType,
MetadataType acceptedType, BiConsumer<E, EM> translateFunction) {
BiConsumer<E, EntityMetadata<T>> translateFunction) {
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -49,9 +48,9 @@ public class FallingBlockEntity extends Entity {
} }
@Override @Override
public void setGravity(EntityMetadata<Boolean> entityMetadata) { public void setGravity(BooleanEntityMetadata entityMetadata) {
super.setGravity(entityMetadata); super.setGravity(entityMetadata);
// Set the NO_AI flag based on the no gravity flag to prevent movement // Set the NO_AI flag based on the no gravity flag to prevent movement
setFlag(EntityFlag.NO_AI, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.NO_AI, entityMetadata.getPrimitiveValue());
} }
} }

View file

@ -53,7 +53,7 @@ public class FireworkEntity extends Entity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setFireworkItem(EntityMetadata<ItemStack> entityMetadata) { public void setFireworkItem(EntityMetadata<ItemStack, ?> entityMetadata) {
ItemStack item = entityMetadata.getValue(); ItemStack item = entityMetadata.getValue();
if (item == null) { if (item == null) {
return; return;
@ -135,7 +135,7 @@ public class FireworkEntity extends Entity {
dirtyMetadata.put(EntityData.DISPLAY_ITEM, builder.build()); dirtyMetadata.put(EntityData.DISPLAY_ITEM, builder.build());
} }
public void setPlayerGliding(EntityMetadata<OptionalInt> entityMetadata) { public void setPlayerGliding(EntityMetadata<OptionalInt, ?> entityMetadata) {
OptionalInt optional = entityMetadata.getValue(); OptionalInt optional = entityMetadata.getValue();
// Checks if the firework has an entity ID (used when a player is gliding) // Checks if the firework has an entity ID (used when a player is gliding)
// and checks to make sure the player that is gliding is the one getting sent the packet // and checks to make sure the player that is gliding is the one getting sent the packet

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -76,8 +75,8 @@ public class FishingHookEntity extends ThrowableEntity {
super.spawnEntity(); super.spawnEntity();
} }
public void setHookedEntity(EntityMetadata<Integer> entityMetadata) { public void setHookedEntity(IntEntityMetadata entityMetadata) {
int hookedEntityId = ((IntEntityMetadata) entityMetadata).getPrimitiveValue() - 1; int hookedEntityId = entityMetadata.getPrimitiveValue() - 1;
Entity entity; Entity entity;
if (session.getPlayerEntity().getEntityId() == hookedEntityId) { if (session.getPlayerEntity().getEntityId() == hookedEntityId) {
entity = session.getPlayerEntity(); entity = session.getPlayerEntity();

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,8 +40,8 @@ public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setHasFuel(EntityMetadata<Boolean> entityMetadata) { public void setHasFuel(BooleanEntityMetadata entityMetadata) {
hasFuel = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); hasFuel = entityMetadata.getPrimitiveValue();
updateDefaultBlockMetadata(); updateDefaultBlockMetadata();
} }

View file

@ -84,7 +84,7 @@ public class ItemEntity extends ThrowableEntity {
} }
} }
public void setItem(EntityMetadata<ItemStack> entityMetadata) { public void setItem(EntityMetadata<ItemStack, ?> entityMetadata) {
ItemData item = ItemTranslator.translateToBedrock(session, entityMetadata.getValue()); ItemData item = ItemTranslator.translateToBedrock(session, entityMetadata.getValue());
if (this.item == null) { if (this.item == null) {
this.item = item; this.item = item;

View file

@ -109,7 +109,7 @@ public class ItemFrameEntity extends Entity {
valid = true; valid = true;
} }
public void setItemInFrame(EntityMetadata<ItemStack> entityMetadata) { public void setItemInFrame(EntityMetadata<ItemStack, ?> entityMetadata) {
if (entityMetadata.getValue() != null) { if (entityMetadata.getValue() != null) {
this.heldItem = entityMetadata.getValue(); this.heldItem = entityMetadata.getValue();
ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem); ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem);
@ -134,8 +134,8 @@ public class ItemFrameEntity extends Entity {
} }
} }
public void setItemRotation(EntityMetadata<Integer> entityMetadata) { public void setItemRotation(IntEntityMetadata entityMetadata) {
rotation = ((IntEntityMetadata) entityMetadata).getPrimitiveValue() * 45; rotation = entityMetadata.getPrimitiveValue() * 45;
if (cachedTag == null) { if (cachedTag == null) {
return; return;
} }

View file

@ -31,6 +31,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.AttributeData; import com.nukkitx.protocol.bedrock.data.AttributeData;
@ -53,6 +54,7 @@ import org.geysermc.connector.utils.ChunkUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@Getter @Getter
@ -87,8 +89,8 @@ public class LivingEntity extends Entity {
dirtyMetadata.put(EntityData.HEALTH, 1); dirtyMetadata.put(EntityData.HEALTH, 1);
} }
public void setLivingEntityFlags(EntityMetadata<Byte> entityMetadata) { public void setLivingEntityFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
// Blocking gets triggered when using a bow, but if we set USING_ITEM for all items, it may look like // Blocking gets triggered when using a bow, but if we set USING_ITEM for all items, it may look like
// you're "mining" with ex. a shield. // you're "mining" with ex. a shield.
@ -102,8 +104,8 @@ public class LivingEntity extends Entity {
setFlag(EntityFlag.DAMAGE_NEARBY_MOBS, (xd & 0x04) == 0x04); setFlag(EntityFlag.DAMAGE_NEARBY_MOBS, (xd & 0x04) == 0x04);
} }
public void setHealth(EntityMetadata<Float> entityMetadata) { public void setHealth(FloatEntityMetadata entityMetadata) {
this.health = ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(); this.health = entityMetadata.getPrimitiveValue();
AttributeData healthData = createHealthAttribute(); AttributeData healthData = createHealthAttribute();
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
@ -112,9 +114,10 @@ public class LivingEntity extends Entity {
session.sendUpstreamPacket(attributesPacket); session.sendUpstreamPacket(attributesPacket);
} }
public Vector3i setBedPosition(EntityMetadata<Position> entityMetadata) { public Vector3i setBedPosition(EntityMetadata<Optional<Position>, ?> entityMetadata) {
Position bedPosition = entityMetadata.getValue(); Optional<Position> optionalPos = entityMetadata.getValue();
if (bedPosition != null) { if (optionalPos.isPresent()) {
Position bedPosition = optionalPos.get();
Vector3i vector = Vector3i.from(bedPosition.getX(), bedPosition.getY(), bedPosition.getZ()); Vector3i vector = Vector3i.from(bedPosition.getX(), bedPosition.getY(), bedPosition.getZ());
dirtyMetadata.put(EntityData.BED_POSITION, vector); dirtyMetadata.put(EntityData.BED_POSITION, vector);
int bed = session.getConnector().getWorldManager().getBlockAt(session, bedPosition); int bed = session.getConnector().getWorldManager().getBlockAt(session, bedPosition);
@ -148,7 +151,7 @@ public class LivingEntity extends Entity {
} }
@Override @Override
public float setFreezing(EntityMetadata<Integer> entityMetadata) { public float setFreezing(IntEntityMetadata entityMetadata) {
float freezingPercentage = super.setFreezing(entityMetadata); float freezingPercentage = super.setFreezing(entityMetadata);
this.isMaxFrozenState = freezingPercentage >= 1.0f; this.isMaxFrozenState = freezingPercentage >= 1.0f;
setFlag(EntityFlag.SHAKING, isShaking()); setFlag(EntityFlag.SHAKING, isShaking());

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -40,18 +39,18 @@ public class MinecartEntity extends Entity {
super(session, entityId, geyserId, uuid, definition, position.add(0d, definition.offset(), 0d), motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position.add(0d, definition.offset(), 0d), motion, yaw, pitch, headYaw);
} }
public void setCustomBlock(EntityMetadata<Integer> entityMetadata) { public void setCustomBlock(IntEntityMetadata entityMetadata) {
dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(((IntEntityMetadata) entityMetadata).getPrimitiveValue())); dirtyMetadata.put(EntityData.DISPLAY_ITEM, session.getBlockMappings().getBedrockBlockId(entityMetadata.getPrimitiveValue()));
} }
public void setCustomBlockOffset(EntityMetadata<Integer> entityMetadata) { public void setCustomBlockOffset(IntEntityMetadata entityMetadata) {
dirtyMetadata.put(EntityData.DISPLAY_OFFSET, entityMetadata.getValue()); dirtyMetadata.put(EntityData.DISPLAY_OFFSET, entityMetadata.getPrimitiveValue());
} }
public void setShowCustomBlock(EntityMetadata<Boolean> entityMetadata) { public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) {
// If the custom block should be enabled // If the custom block should be enabled
// Needs a byte based off of Java's boolean // Needs a byte based off of Java's boolean
dirtyMetadata.put(EntityData.CUSTOM_DISPLAY, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)); dirtyMetadata.put(EntityData.CUSTOM_DISPLAY, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0));
} }
@Override @Override

View file

@ -42,7 +42,7 @@ public class TNTEntity extends Entity implements Tickable {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setFuseLength(EntityMetadata<Integer> entityMetadata) { public void setFuseLength(IntEntityMetadata entityMetadata) {
currentTick = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); currentTick = ((IntEntityMetadata) entityMetadata).getPrimitiveValue();
setFlag(EntityFlag.IGNITED, true); setFlag(EntityFlag.IGNITED, true);
dirtyMetadata.put(EntityData.FUSE_LENGTH, currentTick); dirtyMetadata.put(EntityData.FUSE_LENGTH, currentTick);

View file

@ -47,7 +47,7 @@ public class ThrownPotionEntity extends ThrowableItemEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setPotion(EntityMetadata<ItemStack> entityMetadata) { public void setPotion(EntityMetadata<ItemStack, ?> entityMetadata) {
ItemStack itemStack = entityMetadata.getValue(); ItemStack itemStack = entityMetadata.getValue();
ItemMapping mapping = session.getItemMappings().getMapping(itemStack); ItemMapping mapping = session.getItemMappings().getMapping(itemStack);
if (mapping.getJavaIdentifier().endsWith("potion") && itemStack.getNbt() != null) { if (mapping.getJavaIdentifier().endsWith("potion") && itemStack.getNbt() != null) {

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -43,8 +42,8 @@ public class TippedArrowEntity extends AbstractArrowEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setPotionEffectColor(EntityMetadata<Integer> entityMetadata) { public void setPotionEffectColor(IntEntityMetadata entityMetadata) {
int potionColor = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int potionColor = entityMetadata.getPrimitiveValue();
// -1 means no color // -1 means no color
if (potionColor == -1) { if (potionColor == -1) {
dirtyMetadata.put(EntityData.CUSTOM_DISPLAY, 0); dirtyMetadata.put(EntityData.CUSTOM_DISPLAY, 0);

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
@ -41,8 +40,8 @@ public class WitherSkullEntity extends ItemedFireballEntity {
this.futureTicks = 1; this.futureTicks = 1;
} }
public void setDangerous(EntityMetadata<Boolean> entityMetadata) { public void setDangerous(BooleanEntityMetadata entityMetadata) {
boolean newDangerous = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); boolean newDangerous = entityMetadata.getPrimitiveValue();
if (newDangerous != isCharged) { if (newDangerous != isCharged) {
isCharged = newDangerous; isCharged = newDangerous;
// Is an entirely new entity in Bedrock but just a metadata type in Java // Is an entirely new entity in Bedrock but just a metadata type in Java

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living; package org.geysermc.connector.entity.living;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,8 +40,8 @@ public class AgeableEntity extends CreatureEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setBaby(EntityMetadata<Boolean> entityMetadata) { public void setBaby(BooleanEntityMetadata entityMetadata) {
boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); boolean isBaby = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.SCALE, isBaby ? getBabySize() : getAdultSize()); dirtyMetadata.put(EntityData.SCALE, isBaby ? getBabySize() : getAdultSize());
setFlag(EntityFlag.BABY, isBaby); setFlag(EntityFlag.BABY, isBaby);

View file

@ -40,6 +40,7 @@ import org.geysermc.connector.entity.EntityDefinitions;
import org.geysermc.connector.entity.LivingEntity; import org.geysermc.connector.entity.LivingEntity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class ArmorStandEntity extends LivingEntity { public class ArmorStandEntity extends LivingEntity {
@ -117,13 +118,13 @@ public class ArmorStandEntity extends LivingEntity {
} }
@Override @Override
public void setDisplayName(EntityMetadata<Component> entityMetadata) { public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
super.setDisplayName(entityMetadata); super.setDisplayName(entityMetadata);
updateSecondEntityStatus(false); updateSecondEntityStatus(false);
} }
public void setArmorStandFlags(EntityMetadata<Byte> entityMetadata) { public void setArmorStandFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
// isSmall // isSmall
boolean newIsSmall = (xd & 0x01) == 0x01; boolean newIsSmall = (xd & 0x01) == 0x01;
@ -161,27 +162,27 @@ public class ArmorStandEntity extends LivingEntity {
setFlag(EntityFlag.ADMIRING, (xd & 0x08) == 0x08); // Has no baseplate setFlag(EntityFlag.ADMIRING, (xd & 0x08) == 0x08); // Has no baseplate
} }
public void setHeadRotation(EntityMetadata<Rotation> entityMetadata) { public void setHeadRotation(EntityMetadata<Rotation, ?> entityMetadata) {
onRotationUpdate(EntityData.MARK_VARIANT, EntityFlag.INTERESTED, EntityFlag.CHARGED, EntityFlag.POWERED, entityMetadata.getValue()); onRotationUpdate(EntityData.MARK_VARIANT, EntityFlag.INTERESTED, EntityFlag.CHARGED, EntityFlag.POWERED, entityMetadata.getValue());
} }
public void setBodyRotation(EntityMetadata<Rotation> entityMetadata) { public void setBodyRotation(EntityMetadata<Rotation, ?> entityMetadata) {
onRotationUpdate(EntityData.VARIANT, EntityFlag.IN_LOVE, EntityFlag.CELEBRATING, EntityFlag.CELEBRATING_SPECIAL, entityMetadata.getValue()); onRotationUpdate(EntityData.VARIANT, EntityFlag.IN_LOVE, EntityFlag.CELEBRATING, EntityFlag.CELEBRATING_SPECIAL, entityMetadata.getValue());
} }
public void setLeftArmRotation(EntityMetadata<Rotation> entityMetadata) { public void setLeftArmRotation(EntityMetadata<Rotation, ?> entityMetadata) {
onRotationUpdate(EntityData.TRADE_TIER, EntityFlag.CHARGING, EntityFlag.CRITICAL, EntityFlag.DANCING, entityMetadata.getValue()); onRotationUpdate(EntityData.TRADE_TIER, EntityFlag.CHARGING, EntityFlag.CRITICAL, EntityFlag.DANCING, entityMetadata.getValue());
} }
public void setRightArmRotation(EntityMetadata<Rotation> entityMetadata) { public void setRightArmRotation(EntityMetadata<Rotation, ?> entityMetadata) {
onRotationUpdate(EntityData.MAX_TRADE_TIER, EntityFlag.ELDER, EntityFlag.EMOTING, EntityFlag.IDLING, entityMetadata.getValue()); onRotationUpdate(EntityData.MAX_TRADE_TIER, EntityFlag.ELDER, EntityFlag.EMOTING, EntityFlag.IDLING, entityMetadata.getValue());
} }
public void setLeftLegRotation(EntityMetadata<Rotation> entityMetadata) { public void setLeftLegRotation(EntityMetadata<Rotation, ?> entityMetadata) {
onRotationUpdate(EntityData.SKIN_ID, EntityFlag.IS_ILLAGER_CAPTAIN, EntityFlag.IS_IN_UI, EntityFlag.LINGERING, entityMetadata.getValue()); onRotationUpdate(EntityData.SKIN_ID, EntityFlag.IS_ILLAGER_CAPTAIN, EntityFlag.IS_IN_UI, EntityFlag.LINGERING, entityMetadata.getValue());
} }
public void setRightLegRotation(EntityMetadata<Rotation> entityMetadata) { public void setRightLegRotation(EntityMetadata<Rotation, ?> entityMetadata) {
onRotationUpdate(EntityData.HURT_DIRECTION, EntityFlag.IS_PREGNANT, EntityFlag.SHEARED, EntityFlag.STALKING, entityMetadata.getValue()); onRotationUpdate(EntityData.HURT_DIRECTION, EntityFlag.IS_PREGNANT, EntityFlag.SHEARED, EntityFlag.STALKING, entityMetadata.getValue());
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living; package org.geysermc.connector.entity.living;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -40,8 +39,8 @@ public class BatEntity extends AmbientEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setBatFlags(EntityMetadata<Byte> entityMetadata) { public void setBatFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.RESTING, (xd & 0x01) == 0x01); setFlag(EntityFlag.RESTING, (xd & 0x01) == 0x01);
} }
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living; package org.geysermc.connector.entity.living;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -54,8 +53,8 @@ public class MobEntity extends LivingEntity {
setLeashHolderBedrockId(-1); setLeashHolderBedrockId(-1);
} }
public void setMobFlags(EntityMetadata<Byte> entityMetadata) { public void setMobFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.NO_AI, (xd & 0x01) == 0x01); setFlag(EntityFlag.NO_AI, (xd & 0x01) == 0x01);
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living; package org.geysermc.connector.entity.living;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -40,7 +39,7 @@ public class SlimeEntity extends MobEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setScale(EntityMetadata<Integer> entityMetadata) { public void setScale(IntEntityMetadata entityMetadata) {
dirtyMetadata.put(EntityData.SCALE, 0.10f + ((IntEntityMetadata) entityMetadata).getPrimitiveValue()); dirtyMetadata.put(EntityData.SCALE, 0.10f + entityMetadata.getPrimitiveValue());
} }
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living; package org.geysermc.connector.entity.living;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -40,8 +39,8 @@ public class SnowGolemEntity extends GolemEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setSnowGolemFlags(EntityMetadata<Byte> entityMetadata) { public void setSnowGolemFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
// Handle the visibility of the pumpkin // Handle the visibility of the pumpkin
setFlag(EntityFlag.SHEARED, (xd & 0x10) != 0x10); setFlag(EntityFlag.SHEARED, (xd & 0x10) != 0x10);
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -42,8 +41,8 @@ public class AxolotlEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setVariant(EntityMetadata<Integer> entityMetadata) { public void setVariant(IntEntityMetadata entityMetadata) {
int variant = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int variant = entityMetadata.getPrimitiveValue();
switch (variant) { switch (variant) {
case 1 -> variant = 3; // Java - "Wild" (brown) case 1 -> variant = 3; // Java - "Wild" (brown)
case 3 -> variant = 1; // Java - cyan case 3 -> variant = 1; // Java - cyan
@ -51,8 +50,8 @@ public class AxolotlEntity extends AnimalEntity {
dirtyMetadata.put(EntityData.VARIANT, variant); dirtyMetadata.put(EntityData.VARIANT, variant);
} }
public void setPlayingDead(EntityMetadata<Boolean> entityMetadata) { public void setPlayingDead(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.PLAYING_DEAD, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.PLAYING_DEAD, entityMetadata.getPrimitiveValue());
} }
@Override @Override

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -45,8 +44,8 @@ public class BeeEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setBeeFlags(EntityMetadata<Byte> entityMetadata) { public void setBeeFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
// Bee is performing sting attack; trigger animation // Bee is performing sting attack; trigger animation
if ((xd & 0x02) == 0x02) { if ((xd & 0x02) == 0x02) {
EntityEventPacket packet = new EntityEventPacket(); EntityEventPacket packet = new EntityEventPacket();
@ -61,9 +60,9 @@ public class BeeEntity extends AnimalEntity {
setFlag(EntityFlag.POWERED, (xd & 0x08) == 0x08); setFlag(EntityFlag.POWERED, (xd & 0x08) == 0x08);
} }
public void setAngerTime(EntityMetadata<Integer> entityMetadata) { public void setAngerTime(IntEntityMetadata entityMetadata) {
// Converting "anger time" to a boolean // Converting "anger time" to a boolean
setFlag(EntityFlag.ANGRY, ((IntEntityMetadata) entityMetadata).getPrimitiveValue() > 0); setFlag(EntityFlag.ANGRY, entityMetadata.getPrimitiveValue() > 0);
} }
@Override @Override

View file

@ -25,8 +25,8 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -42,12 +42,12 @@ public class FoxEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setFoxVariant(EntityMetadata<Integer> entityMetadata) { public void setFoxVariant(IntEntityMetadata entityMetadata) {
dirtyMetadata.put(EntityData.VARIANT, entityMetadata.getValue()); dirtyMetadata.put(EntityData.VARIANT, entityMetadata.getPrimitiveValue());
} }
public void setFoxFlags(EntityMetadata<Byte> entityMetadata) { public void setFoxFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01);
setFlag(EntityFlag.SNEAKING, (xd & 0x04) == 0x04); setFlag(EntityFlag.SNEAKING, (xd & 0x04) == 0x04);
setFlag(EntityFlag.INTERESTED, (xd & 0x08) == 0x08); setFlag(EntityFlag.INTERESTED, (xd & 0x08) == 0x08);

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -46,9 +45,9 @@ public class GoatEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setScreamer(EntityMetadata<Boolean> entityMetadata) { public void setScreamer(BooleanEntityMetadata entityMetadata) {
// Metadata not used in Bedrock Edition // Metadata not used in Bedrock Edition
isScreamer = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); isScreamer = entityMetadata.getPrimitiveValue();
} }
@Override @Override

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -43,9 +42,9 @@ public class HoglinEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setImmuneToZombification(EntityMetadata<Boolean> entityMetadata) { public void setImmuneToZombification(BooleanEntityMetadata entityMetadata) {
// Apply shaking effect if not in the nether and zombification is possible // Apply shaking effect if not in the nether and zombification is possible
this.isImmuneToZombification = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); this.isImmuneToZombification = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.SHAKING, isShaking()); setFlag(EntityFlag.SHAKING, isShaking());
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -47,8 +46,8 @@ public class PandaEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setEatingCounter(EntityMetadata<Integer> entityMetadata) { public void setEatingCounter(IntEntityMetadata entityMetadata) {
int count = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int count = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.EATING, count > 0); setFlag(EntityFlag.EATING, count > 0);
dirtyMetadata.put(EntityData.EATING_COUNTER, count); dirtyMetadata.put(EntityData.EATING_COUNTER, count);
if (count != 0) { if (count != 0) {
@ -61,18 +60,18 @@ public class PandaEntity extends AnimalEntity {
} }
} }
public void setMainGene(EntityMetadata<Byte> entityMetadata) { public void setMainGene(ByteEntityMetadata entityMetadata) {
mainGene = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); mainGene = entityMetadata.getPrimitiveValue();
updateAppearance(); updateAppearance();
} }
public void setHiddenGene(EntityMetadata<Byte> entityMetadata) { public void setHiddenGene(ByteEntityMetadata entityMetadata) {
hiddenGene = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); hiddenGene = entityMetadata.getPrimitiveValue();
updateAppearance(); updateAppearance();
} }
public void setPandaFlags(EntityMetadata<Byte> entityMetadata) { public void setPandaFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.SNEEZING, (xd & 0x02) == 0x02); setFlag(EntityFlag.SNEEZING, (xd & 0x02) == 0x02);
setFlag(EntityFlag.ROLLING, (xd & 0x04) == 0x04); setFlag(EntityFlag.ROLLING, (xd & 0x04) == 0x04);
setFlag(EntityFlag.SITTING, (xd & 0x08) == 0x08); setFlag(EntityFlag.SITTING, (xd & 0x08) == 0x08);

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,8 +40,8 @@ public class PufferFishEntity extends AbstractFishEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setPufferfishSize(EntityMetadata<Integer> entityMetadata) { public void setPufferfishSize(IntEntityMetadata entityMetadata) {
int puffsize = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int puffsize = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.PUFFERFISH_SIZE, (byte) puffsize); dirtyMetadata.put(EntityData.PUFFERFISH_SIZE, (byte) puffsize);
dirtyMetadata.put(EntityData.VARIANT, puffsize); dirtyMetadata.put(EntityData.VARIANT, puffsize);
} }

View file

@ -25,7 +25,7 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -43,12 +43,12 @@ public class RabbitEntity extends AnimalEntity {
} }
@Override @Override
public void setBaby(EntityMetadata<Boolean> entityMetadata) { public void setBaby(BooleanEntityMetadata entityMetadata) {
super.setBaby(entityMetadata); super.setBaby(entityMetadata);
} }
public void setRabbitVariant(EntityMetadata<Integer> entityMetadata) { public void setRabbitVariant(IntEntityMetadata entityMetadata) {
int variant = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int variant = entityMetadata.getPrimitiveValue();
// Change the killer bunny to display as white since it only exists on Java Edition // Change the killer bunny to display as white since it only exists on Java Edition
boolean isKillerBunny = variant == 99; boolean isKillerBunny = variant == 99;

View file

@ -41,7 +41,7 @@ public class SheepEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setSheepFlags(EntityMetadata<Byte> entityMetadata) { public void setSheepFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue();
setFlag(EntityFlag.SHEARED, (xd & 0x10) == 0x10); setFlag(EntityFlag.SHEARED, (xd & 0x10) == 0x10);
dirtyMetadata.put(EntityData.COLOR, xd); dirtyMetadata.put(EntityData.COLOR, xd);

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -47,12 +46,12 @@ public class StriderEntity extends AnimalEntity {
setFlag(EntityFlag.BREATHING, true); setFlag(EntityFlag.BREATHING, true);
} }
public void setCold(EntityMetadata<Boolean> entityMetadata) { public void setCold(BooleanEntityMetadata entityMetadata) {
isCold = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); isCold = entityMetadata.getPrimitiveValue();
} }
public void setSaddled(EntityMetadata<Boolean> entityMetadata) { public void setSaddled(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.SADDLED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.SADDLED, entityMetadata.getPrimitiveValue());
} }
@Override @Override

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -53,8 +52,8 @@ public class TropicalFishEntity extends AbstractFishEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setFishVariant(EntityMetadata<Integer> entityMetadata) { public void setFishVariant(IntEntityMetadata entityMetadata) {
int varNumber = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int varNumber = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.VARIANT, getShape(varNumber)); // Shape 0-1 dirtyMetadata.put(EntityData.VARIANT, getShape(varNumber)); // Shape 0-1
dirtyMetadata.put(EntityData.MARK_VARIANT, getPattern(varNumber)); // Pattern 0-5 dirtyMetadata.put(EntityData.MARK_VARIANT, getPattern(varNumber)); // Pattern 0-5

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal; package org.geysermc.connector.entity.living.animal;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -41,12 +40,12 @@ public class TurtleEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setPregnant(EntityMetadata<Boolean> entityMetadata) { public void setPregnant(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.IS_PREGNANT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.IS_PREGNANT, entityMetadata.getPrimitiveValue());
} }
public void setLayingEgg(EntityMetadata<Boolean> entityMetadata) { public void setLayingEgg(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.LAYING_EGG, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.LAYING_EGG, entityMetadata.getPrimitiveValue());
} }
@Override @Override

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal.horse; package org.geysermc.connector.entity.living.animal.horse;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -79,8 +78,8 @@ public class AbstractHorseEntity extends AnimalEntity {
session.sendUpstreamPacket(attributesPacket); session.sendUpstreamPacket(attributesPacket);
} }
public void setHorseFlags(EntityMetadata<Byte> entityMetadata) { public void setHorseFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
boolean tamed = (xd & 0x02) == 0x02; boolean tamed = (xd & 0x02) == 0x02;
boolean saddled = (xd & 0x04) == 0x04; boolean saddled = (xd & 0x04) == 0x04;
setFlag(EntityFlag.TAMED, tamed); setFlag(EntityFlag.TAMED, tamed);

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal.horse; package org.geysermc.connector.entity.living.animal.horse;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -40,8 +39,8 @@ public class HorseEntity extends AbstractHorseEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setHorseVariant(EntityMetadata<Integer> entityMetadata) { public void setHorseVariant(IntEntityMetadata entityMetadata) {
int value = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int value = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.VARIANT, value & 255); dirtyMetadata.put(EntityData.VARIANT, value & 255);
dirtyMetadata.put(EntityData.MARK_VARIANT, (value >> 8) % 5); dirtyMetadata.put(EntityData.MARK_VARIANT, (value >> 8) % 5);
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal.horse; package org.geysermc.connector.entity.living.animal.horse;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -48,12 +47,12 @@ public class LlamaEntity extends ChestedHorseEntity {
/** /**
* Color equipped on the llama * Color equipped on the llama
*/ */
public void setCarpetedColor(EntityMetadata<Integer> entityMetadata) { public void setCarpetedColor(IntEntityMetadata entityMetadata) {
// Bedrock treats llama decoration as armor // Bedrock treats llama decoration as armor
MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket(); MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket();
equipmentPacket.setRuntimeEntityId(geyserId); equipmentPacket.setRuntimeEntityId(geyserId);
// -1 means no armor // -1 means no armor
int carpetIndex = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int carpetIndex = entityMetadata.getPrimitiveValue();
if (carpetIndex > -1 && carpetIndex <= 15) { if (carpetIndex > -1 && carpetIndex <= 15) {
// The damage value is the dye color that Java sends us, for pre-1.16.220 // The damage value is the dye color that Java sends us, for pre-1.16.220
// The item is always going to be a carpet // The item is always going to be a carpet

View file

@ -25,8 +25,8 @@
package org.geysermc.connector.entity.living.animal.tameable; package org.geysermc.connector.entity.living.animal.tameable;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -61,7 +61,7 @@ public class CatEntity extends TameableEntity {
} }
@Override @Override
public void setTameableFlags(EntityMetadata<Byte> entityMetadata) { public void setTameableFlags(ByteEntityMetadata entityMetadata) {
super.setTameableFlags(entityMetadata); super.setTameableFlags(entityMetadata);
// Update collar color if tamed // Update collar color if tamed
if (getFlag(EntityFlag.TAMED)) { if (getFlag(EntityFlag.TAMED)) {
@ -69,9 +69,9 @@ public class CatEntity extends TameableEntity {
} }
} }
public void setCatVariant(EntityMetadata<Integer> entityMetadata) { public void setCatVariant(IntEntityMetadata entityMetadata) {
// Different colors in Java and Bedrock for some reason // Different colors in Java and Bedrock for some reason
int metadataValue = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int metadataValue = entityMetadata.getPrimitiveValue();
int variantColor = switch (metadataValue) { int variantColor = switch (metadataValue) {
case 0 -> 8; case 0 -> 8;
case 8 -> 0; case 8 -> 0;
@ -82,12 +82,12 @@ public class CatEntity extends TameableEntity {
dirtyMetadata.put(EntityData.VARIANT, variantColor); dirtyMetadata.put(EntityData.VARIANT, variantColor);
} }
public void setResting(EntityMetadata<Boolean> entityMetadata) { public void setResting(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.RESTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.RESTING, entityMetadata.getPrimitiveValue());
} }
public void setCollarColor(EntityMetadata<Integer> entityMetadata) { public void setCollarColor(IntEntityMetadata entityMetadata) {
collarColor = (byte) ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); collarColor = (byte) entityMetadata.getPrimitiveValue();
// Needed or else wild cats are a red color // Needed or else wild cats are a red color
if (getFlag(EntityFlag.TAMED)) { if (getFlag(EntityFlag.TAMED)) {
dirtyMetadata.put(EntityData.COLOR, collarColor); dirtyMetadata.put(EntityData.COLOR, collarColor);

View file

@ -36,6 +36,7 @@ import org.geysermc.connector.entity.EntityDefinition;
import org.geysermc.connector.entity.living.animal.AnimalEntity; import org.geysermc.connector.entity.living.animal.AnimalEntity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class TameableEntity extends AnimalEntity { public class TameableEntity extends AnimalEntity {
@ -49,18 +50,18 @@ public class TameableEntity extends AnimalEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setTameableFlags(EntityMetadata<Byte> entityMetadata) { public void setTameableFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01);
setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02);
setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04); setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04);
} }
public void setOwner(EntityMetadata<UUID> entityMetadata) { public void setOwner(EntityMetadata<Optional<UUID>, ?> entityMetadata) {
// Note: Must be set for wolf collar color to work // Note: Must be set for wolf collar color to work
if (entityMetadata.getValue() != null) { if (entityMetadata.getValue().isPresent()) {
// Owner UUID of entity // Owner UUID of entity
Entity entity = session.getEntityCache().getPlayerEntity(entityMetadata.getValue()); Entity entity = session.getEntityCache().getPlayerEntity(entityMetadata.getValue().get());
// Used as both a check since the player isn't in the entity cache and a normal fallback // Used as both a check since the player isn't in the entity cache and a normal fallback
if (entity == null) { if (entity == null) {
entity = session.getPlayerEntity(); entity = session.getPlayerEntity();

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.animal.tameable; package org.geysermc.connector.entity.living.animal.tameable;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -55,18 +54,18 @@ public class WolfEntity extends TameableEntity {
} }
@Override @Override
public void setTameableFlags(EntityMetadata<Byte> entityMetadata) { public void setTameableFlags(ByteEntityMetadata entityMetadata) {
super.setTameableFlags(entityMetadata); super.setTameableFlags(entityMetadata);
// Reset wolf color // Reset wolf color
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
boolean angry = (xd & 0x02) == 0x02; boolean angry = (xd & 0x02) == 0x02;
if (angry) { if (angry) {
dirtyMetadata.put(EntityData.COLOR, (byte) 0); dirtyMetadata.put(EntityData.COLOR, (byte) 0);
} }
} }
public void setCollarColor(EntityMetadata<Integer> entityMetadata) { public void setCollarColor(IntEntityMetadata entityMetadata) {
collarColor = (byte) ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); collarColor = (byte) entityMetadata.getPrimitiveValue();
if (getFlag(EntityFlag.ANGRY)) { if (getFlag(EntityFlag.ANGRY)) {
return; return;
} }
@ -80,8 +79,8 @@ public class WolfEntity extends TameableEntity {
} }
// 1.16+ // 1.16+
public void setWolfAngerTime(EntityMetadata<Integer> entityMetadata) { public void setWolfAngerTime(IntEntityMetadata entityMetadata) {
int time = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int time = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.ANGRY, time != 0); setFlag(EntityFlag.ANGRY, time != 0);
dirtyMetadata.put(EntityData.COLOR, time != 0 ? (byte) 0 : collarColor); dirtyMetadata.put(EntityData.COLOR, time != 0 ? (byte) 0 : collarColor);
} }

View file

@ -40,6 +40,7 @@ import org.geysermc.connector.entity.EntityDefinition;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.registry.BlockRegistries; import org.geysermc.connector.registry.BlockRegistries;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class VillagerEntity extends AbstractMerchantEntity { public class VillagerEntity extends AbstractMerchantEntity {
@ -91,7 +92,7 @@ public class VillagerEntity extends AbstractMerchantEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setVillagerData(EntityMetadata<VillagerData> entityMetadata) { public void setVillagerData(EntityMetadata<VillagerData, ?> entityMetadata) {
VillagerData villagerData = entityMetadata.getValue(); VillagerData villagerData = entityMetadata.getValue();
// Profession // Profession
int profession = VILLAGER_PROFESSIONS.get(villagerData.getProfession()); int profession = VILLAGER_PROFESSIONS.get(villagerData.getProfession());
@ -105,7 +106,7 @@ public class VillagerEntity extends AbstractMerchantEntity {
} }
@Override @Override
public Vector3i setBedPosition(EntityMetadata<Position> entityMetadata) { public Vector3i setBedPosition(EntityMetadata<Optional<Position>, ?> entityMetadata) {
return bedPosition = super.setBedPosition(entityMetadata); return bedPosition = super.setBedPosition(entityMetadata);
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,9 +40,9 @@ public class AbstractSkeletonEntity extends MonsterEntity {
} }
@Override @Override
public void setMobFlags(EntityMetadata<Byte> entityMetadata) { public void setMobFlags(ByteEntityMetadata entityMetadata) {
super.setMobFlags(entityMetadata); super.setMobFlags(entityMetadata);
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
// A bit of a loophole so the hands get raised - set the target ID to its own ID // A bit of a loophole so the hands get raised - set the target ID to its own ID
dirtyMetadata.put(EntityData.TARGET_EID, ((xd & 4) == 4) ? geyserId : 0); dirtyMetadata.put(EntityData.TARGET_EID, ((xd & 4) == 4) ? geyserId : 0);
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -42,9 +41,9 @@ public class BasePiglinEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setImmuneToZombification(EntityMetadata<Boolean> entityMetadata) { public void setImmuneToZombification(BooleanEntityMetadata entityMetadata) {
// Apply shaking effect if not in the nether and zombification is possible // Apply shaking effect if not in the nether and zombification is possible
this.isImmuneToZombification = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); this.isImmuneToZombification = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.SHAKING, isShaking()); setFlag(EntityFlag.SHAKING, isShaking());
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -40,8 +39,8 @@ public class BlazeEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setBlazeFlags(EntityMetadata<Byte> entityMetadata) { public void setBlazeFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.ON_FIRE, (xd & 0x01) == 0x01); setFlag(EntityFlag.ON_FIRE, (xd & 0x01) == 0x01);
} }
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -37,8 +36,8 @@ import java.util.UUID;
public class CreeperEntity extends MonsterEntity { public class CreeperEntity extends MonsterEntity {
/** /**
* Whether the creeper has been ignited and is using {@link #setIgnited(EntityMetadata)}. * Whether the creeper has been ignited and is using {@link #setIgnited(BooleanEntityMetadata)}.
* In this instance we ignore {@link #setSwelling(EntityMetadata)} since it's sending us -1 which confuses poor Bedrock. * In this instance we ignore {@link #setSwelling(IntEntityMetadata)} since it's sending us -1 which confuses poor Bedrock.
*/ */
private boolean ignitedByFlintAndSteel = false; private boolean ignitedByFlintAndSteel = false;
@ -46,14 +45,14 @@ public class CreeperEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setSwelling(EntityMetadata<Integer> entityMetadata) { public void setSwelling(IntEntityMetadata entityMetadata) {
if (!ignitedByFlintAndSteel) { if (!ignitedByFlintAndSteel) {
setFlag(EntityFlag.IGNITED, ((IntEntityMetadata) entityMetadata).getPrimitiveValue() == 1); setFlag(EntityFlag.IGNITED, entityMetadata.getPrimitiveValue() == 1);
} }
} }
public void setIgnited(EntityMetadata<Boolean> entityMetadata) { public void setIgnited(BooleanEntityMetadata entityMetadata) {
ignitedByFlintAndSteel = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); ignitedByFlintAndSteel = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.IGNITED, ignitedByFlintAndSteel); setFlag(EntityFlag.IGNITED, ignitedByFlintAndSteel);
} }
} }

View file

@ -25,7 +25,7 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.LevelEventType;
@ -90,7 +90,7 @@ public class EnderDragonEntity extends MobEntity implements Tickable {
} }
@Override @Override
public void setHealth(EntityMetadata<Float> entityMetadata) { public void setHealth(FloatEntityMetadata entityMetadata) {
super.setHealth(entityMetadata); super.setHealth(entityMetadata);
if (phase == 9 && this.health <= 0) { // Dying phase if (phase == 9 && this.health <= 0) { // Dying phase
EntityEventPacket entityEventPacket = new EntityEventPacket(); EntityEventPacket entityEventPacket = new EntityEventPacket();
@ -101,8 +101,8 @@ public class EnderDragonEntity extends MobEntity implements Tickable {
} }
} }
public void setPhase(EntityMetadata<Integer> entityMetadata) { public void setPhase(IntEntityMetadata entityMetadata) {
phase = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); phase = entityMetadata.getPrimitiveValue();
phaseTicks = 0; phaseTicks = 0;
setFlag(EntityFlag.SITTING, isSitting()); setFlag(EntityFlag.SITTING, isSitting());
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
@ -44,17 +43,17 @@ public class EndermanEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setCarriedBlock(EntityMetadata<Integer> entityMetadata) { public void setCarriedBlock(IntEntityMetadata entityMetadata) {
dirtyMetadata.put(EntityData.CARRIED_BLOCK, session.getBlockMappings().getBedrockBlockId(((IntEntityMetadata) entityMetadata).getPrimitiveValue())); dirtyMetadata.put(EntityData.CARRIED_BLOCK, session.getBlockMappings().getBedrockBlockId(entityMetadata.getPrimitiveValue()));
} }
/** /**
* Controls the screaming sound * Controls the screaming sound
*/ */
public void setScreaming(EntityMetadata<Boolean> entityMetadata) { public void setScreaming(BooleanEntityMetadata entityMetadata) {
//TODO see if Bedrock controls this differently //TODO see if Bedrock controls this differently
// Java Edition this controls which ambient sound is used // Java Edition this controls which ambient sound is used
if (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()) { if (entityMetadata.getPrimitiveValue()) {
LevelSoundEvent2Packet packet = new LevelSoundEvent2Packet(); LevelSoundEvent2Packet packet = new LevelSoundEvent2Packet();
packet.setSound(SoundEvent.STARE); packet.setSound(SoundEvent.STARE);
packet.setPosition(this.position); packet.setPosition(this.position);
@ -64,8 +63,8 @@ public class EndermanEntity extends MonsterEntity {
} }
} }
public void setAngry(EntityMetadata<Boolean> entityMetadata) { public void setAngry(BooleanEntityMetadata entityMetadata) {
// "Is staring/provoked" - controls visuals // "Is staring/provoked" - controls visuals
setFlag(EntityFlag.ANGRY, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.ANGRY, entityMetadata.getPrimitiveValue());
} }
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,8 +40,8 @@ public class GhastEntity extends FlyingEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setGhastAttacking(EntityMetadata<Boolean> entityMetadata) { public void setGhastAttacking(BooleanEntityMetadata entityMetadata) {
// If the ghast is attacking // If the ghast is attacking
dirtyMetadata.put(EntityData.CHARGE_AMOUNT, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0)); dirtyMetadata.put(EntityData.CHARGE_AMOUNT, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0));
} }
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,8 +40,8 @@ public class GuardianEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setGuardianTarget(EntityMetadata<Integer> entityMetadata) { public void setGuardianTarget(IntEntityMetadata entityMetadata) {
int entityId = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int entityId = entityMetadata.getPrimitiveValue();
Entity entity; Entity entity;
if (session.getPlayerEntity().getEntityId() == entityId) { if (session.getPlayerEntity().getEntityId() == entityId) {
entity = session.getPlayerEntity(); entity = session.getPlayerEntity();

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -40,8 +39,8 @@ public class PhantomEntity extends FlyingEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setPhantomScale(EntityMetadata<Integer> entityMetadata) { public void setPhantomScale(IntEntityMetadata entityMetadata) {
int size = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int size = entityMetadata.getPrimitiveValue();
float modelScale = 1f + 0.15f * size; float modelScale = 1f + 0.15f * size;
float boundsScale = (1f + (0.2f * size) / definition.width()) / modelScale; float boundsScale = (1f + (0.2f * size) / definition.width()) / modelScale;

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,18 +40,18 @@ public class PiglinEntity extends BasePiglinEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setBaby(EntityMetadata<Boolean> entityMetadata) { public void setBaby(BooleanEntityMetadata entityMetadata) {
boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); boolean isBaby = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.SCALE, isBaby? .55f : 1f); dirtyMetadata.put(EntityData.SCALE, isBaby? .55f : 1f);
setFlag(EntityFlag.BABY, isBaby); setFlag(EntityFlag.BABY, isBaby);
} }
public void setChargingCrossbow(EntityMetadata<Boolean> entityMetadata) { public void setChargingCrossbow(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.CHARGING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.CHARGING, entityMetadata.getPrimitiveValue());
} }
public void setDancing(EntityMetadata<Boolean> entityMetadata) { public void setDancing(BooleanEntityMetadata entityMetadata) {
setFlag(EntityFlag.DANCING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()); setFlag(EntityFlag.DANCING, entityMetadata.getPrimitiveValue());
} }
@Override @Override

View file

@ -27,13 +27,13 @@ package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.EntityDefinition; import org.geysermc.connector.entity.EntityDefinition;
import org.geysermc.connector.entity.living.GolemEntity; import org.geysermc.connector.entity.living.GolemEntity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.Direction;
import java.util.UUID; import java.util.UUID;
@ -45,17 +45,17 @@ public class ShulkerEntity extends GolemEntity {
setFlag(EntityFlag.BRIBED, true); setFlag(EntityFlag.BRIBED, true);
} }
public void setAttachedFace(EntityMetadata<Direction> entityMetadata) { public void setAttachedFace(EntityMetadata<Direction, ?> entityMetadata) {
Direction direction = entityMetadata.getValue(); Direction direction = entityMetadata.getValue();
dirtyMetadata.put(EntityData.SHULKER_ATTACH_FACE, (byte) direction.ordinal()); dirtyMetadata.put(EntityData.SHULKER_ATTACH_FACE, (byte) direction.ordinal());
} }
public void setShulkerHeight(EntityMetadata<Byte> entityMetadata) { public void setShulkerHeight(ByteEntityMetadata entityMetadata) {
int height = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); int height = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.SHULKER_PEEK_ID, height); dirtyMetadata.put(EntityData.SHULKER_PEEK_ID, height);
} }
public void setShulkerColor(EntityMetadata<Byte> entityMetadata) { public void setShulkerColor(ByteEntityMetadata entityMetadata) {
byte color = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte color = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue();
if (color == 16) { if (color == 16) {
// 16 is default on both editions // 16 is default on both editions

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -41,8 +40,8 @@ public class SkeletonEntity extends AbstractSkeletonEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setConvertingToStray(EntityMetadata<Boolean> entityMetadata) { public void setConvertingToStray(BooleanEntityMetadata entityMetadata) {
this.convertingToStray = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); this.convertingToStray = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.SHAKING, isShaking()); setFlag(EntityFlag.SHAKING, isShaking());
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -40,8 +39,8 @@ public class SpiderEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setSpiderFlags(EntityMetadata<Byte> entityMetadata) { public void setSpiderFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.WALL_CLIMBING, (xd & 0x01) == 0x01); setFlag(EntityFlag.WALL_CLIMBING, (xd & 0x01) == 0x01);
} }
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -40,8 +39,8 @@ public class VexEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setVexFlags(EntityMetadata<Byte> entityMetadata) { public void setVexFlags(ByteEntityMetadata entityMetadata) {
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
// Set the target to the player to force the attack animation // Set the target to the player to force the attack animation
// even if the player isn't the target as we dont get the target on Java // even if the player isn't the target as we dont get the target on Java
dirtyMetadata.put(EntityData.TARGET_EID, (xd & 0x01) == 0x01 ? session.getPlayerEntity().getGeyserId() : 0); dirtyMetadata.put(EntityData.TARGET_EID, (xd & 0x01) == 0x01 ? session.getPlayerEntity().getGeyserId() : 0);

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -47,20 +46,20 @@ public class WitherEntity extends MonsterEntity {
dirtyMetadata.put(EntityData.WITHER_AERIAL_ATTACK, (short) 1); dirtyMetadata.put(EntityData.WITHER_AERIAL_ATTACK, (short) 1);
} }
public void setTarget1(EntityMetadata<Integer> entityMetadata) { public void setTarget1(IntEntityMetadata entityMetadata) {
setTargetId(EntityData.WITHER_TARGET_1, entityMetadata); setTargetId(EntityData.WITHER_TARGET_1, entityMetadata);
} }
public void setTarget2(EntityMetadata<Integer> entityMetadata) { public void setTarget2(IntEntityMetadata entityMetadata) {
setTargetId(EntityData.WITHER_TARGET_2, entityMetadata); setTargetId(EntityData.WITHER_TARGET_2, entityMetadata);
} }
public void setTarget3(EntityMetadata<Integer> entityMetadata) { public void setTarget3(IntEntityMetadata entityMetadata) {
setTargetId(EntityData.WITHER_TARGET_3, entityMetadata); setTargetId(EntityData.WITHER_TARGET_3, entityMetadata);
} }
private void setTargetId(EntityData entityData, EntityMetadata<Integer> entityMetadata) { private void setTargetId(EntityData entityData, IntEntityMetadata entityMetadata) {
int entityId = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int entityId = entityMetadata.getPrimitiveValue();
Entity entity; Entity entity;
if (session.getPlayerEntity().getEntityId() == entityId) { if (session.getPlayerEntity().getEntityId() == entityId) {
entity = session.getPlayerEntity(); entity = session.getPlayerEntity();
@ -73,8 +72,8 @@ public class WitherEntity extends MonsterEntity {
} }
} }
public void setInvulnerableTicks(EntityMetadata<Integer> entityMetadata) { public void setInvulnerableTicks(IntEntityMetadata entityMetadata) {
int value = ((IntEntityMetadata) entityMetadata).getPrimitiveValue(); int value = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.WITHER_INVULNERABLE_TICKS, value); dirtyMetadata.put(EntityData.WITHER_INVULNERABLE_TICKS, value);
// Show the shield for the first few seconds of spawning (like Java) // Show the shield for the first few seconds of spawning (like Java)

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -41,8 +40,8 @@ public class ZoglinEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setBaby(EntityMetadata<Boolean> entityMetadata) { public void setBaby(BooleanEntityMetadata entityMetadata) {
boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); boolean isBaby = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.SCALE, isBaby? .55f : 1f); dirtyMetadata.put(EntityData.SCALE, isBaby? .55f : 1f);
setFlag(EntityFlag.BABY, isBaby); setFlag(EntityFlag.BABY, isBaby);
} }

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster; package org.geysermc.connector.entity.living.monster;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -42,14 +41,14 @@ public class ZombieEntity extends MonsterEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setZombieBaby(EntityMetadata<Boolean> entityMetadata) { public void setZombieBaby(BooleanEntityMetadata entityMetadata) {
boolean isBaby = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); boolean isBaby = entityMetadata.getPrimitiveValue();
dirtyMetadata.put(EntityData.SCALE, isBaby ? .55f : 1.0f); dirtyMetadata.put(EntityData.SCALE, isBaby ? .55f : 1.0f);
setFlag(EntityFlag.BABY, isBaby); setFlag(EntityFlag.BABY, isBaby);
} }
public void setConvertingToDrowned(EntityMetadata<Boolean> entityMetadata) { public void setConvertingToDrowned(BooleanEntityMetadata entityMetadata) {
convertingToDrowned = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); convertingToDrowned = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.SHAKING, isShaking()); setFlag(EntityFlag.SHAKING, isShaking());
} }

View file

@ -44,13 +44,13 @@ public class ZombieVillagerEntity extends ZombieEntity {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
public void setTransforming(EntityMetadata<Boolean> entityMetadata) { public void setTransforming(BooleanEntityMetadata entityMetadata) {
isTransforming = ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue(); isTransforming = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.IS_TRANSFORMING, isTransforming); setFlag(EntityFlag.IS_TRANSFORMING, isTransforming);
setFlag(EntityFlag.SHAKING, isShaking()); setFlag(EntityFlag.SHAKING, isShaking());
} }
public void setZombieVillagerData(EntityMetadata<VillagerData> entityMetadata) { public void setZombieVillagerData(EntityMetadata<VillagerData, ?> entityMetadata) {
VillagerData villagerData = entityMetadata.getValue(); VillagerData villagerData = entityMetadata.getValue();
dirtyMetadata.put(EntityData.VARIANT, VillagerEntity.VILLAGER_PROFESSIONS.get(villagerData.getProfession())); // Actually works properly with the OptionalPack dirtyMetadata.put(EntityData.VARIANT, VillagerEntity.VILLAGER_PROFESSIONS.get(villagerData.getProfession())); // Actually works properly with the OptionalPack
dirtyMetadata.put(EntityData.MARK_VARIANT, VillagerEntity.VILLAGER_REGIONS.get(villagerData.getType())); dirtyMetadata.put(EntityData.MARK_VARIANT, VillagerEntity.VILLAGER_REGIONS.get(villagerData.getType()));

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster.raid; package org.geysermc.connector.entity.living.monster.raid;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
@ -47,8 +46,8 @@ public class SpellcasterIllagerEntity extends AbstractIllagerEntity {
setFlag(EntityFlag.BRIBED, this.definition == EntityDefinitions.ILLUSIONER); setFlag(EntityFlag.BRIBED, this.definition == EntityDefinitions.ILLUSIONER);
} }
public void setSpellType(EntityMetadata<Byte> entityMetadata) { public void setSpellType(ByteEntityMetadata entityMetadata) {
int spellType = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); int spellType = entityMetadata.getPrimitiveValue();
// Summon vex, attack, or wololo // Summon vex, attack, or wololo
setFlag(EntityFlag.CASTING, spellType == 1 || spellType == 2 || spellType == 3); setFlag(EntityFlag.CASTING, spellType == 1 || spellType == 2 || spellType == 3);
int rgbData = switch (spellType) { int rgbData = switch (spellType) {

View file

@ -25,7 +25,6 @@
package org.geysermc.connector.entity.living.monster.raid; package org.geysermc.connector.entity.living.monster.raid;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -41,10 +40,10 @@ public class VindicatorEntity extends AbstractIllagerEntity {
} }
@Override @Override
public void setMobFlags(EntityMetadata<Byte> entityMetadata) { public void setMobFlags(ByteEntityMetadata entityMetadata) {
super.setMobFlags(entityMetadata); super.setMobFlags(entityMetadata);
// Allow the axe to be shown if necessary // Allow the axe to be shown if necessary
byte xd = ((ByteEntityMetadata) entityMetadata).getPrimitiveValue(); byte xd = entityMetadata.getPrimitiveValue();
setFlag(EntityFlag.ANGRY, (xd & 4) == 4); setFlag(EntityFlag.ANGRY, (xd & 4) == 4);
} }
} }

View file

@ -29,6 +29,7 @@ import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardPosition; import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardPosition;
@ -60,6 +61,7 @@ import org.geysermc.connector.scoreboard.UpdateType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Getter @Setter @Getter @Setter
@ -255,33 +257,33 @@ public class PlayerEntity extends LivingEntity {
} }
@Override @Override
public Vector3i setBedPosition(EntityMetadata<Position> entityMetadata) { public Vector3i setBedPosition(EntityMetadata<Optional<Position>, ?> entityMetadata) {
return bedPosition = super.setBedPosition(entityMetadata); return bedPosition = super.setBedPosition(entityMetadata);
} }
public void setAbsorptionHearts(EntityMetadata<Float> entityMetadata) { public void setAbsorptionHearts(FloatEntityMetadata entityMetadata) {
// Extra hearts - is not metadata but an attribute on Bedrock // Extra hearts - is not metadata but an attribute on Bedrock
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(geyserId); attributesPacket.setRuntimeEntityId(geyserId);
// Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit // Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit
attributesPacket.setAttributes(Collections.singletonList( attributesPacket.setAttributes(Collections.singletonList(
new AttributeData("minecraft:absorption", 0.0f, 1024f, ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(), 0.0f))); new AttributeData("minecraft:absorption", 0.0f, 1024f, entityMetadata.getPrimitiveValue(), 0.0f)));
session.sendUpstreamPacket(attributesPacket); session.sendUpstreamPacket(attributesPacket);
} }
public void setSkinVisibility(EntityMetadata<Byte> entityMetadata) { public void setSkinVisibility(ByteEntityMetadata entityMetadata) {
// OptionalPack usage for toggling skin bits // OptionalPack usage for toggling skin bits
// In Java Edition, a bit being set means that part should be enabled // In Java Edition, a bit being set means that part should be enabled
// However, to ensure that the pack still works on other servers, we invert the bit so all values by default // However, to ensure that the pack still works on other servers, we invert the bit so all values by default
// are true (0). // are true (0).
dirtyMetadata.put(EntityData.MARK_VARIANT, ~((ByteEntityMetadata) entityMetadata).getPrimitiveValue() & 0xff); dirtyMetadata.put(EntityData.MARK_VARIANT, ~entityMetadata.getPrimitiveValue() & 0xff);
} }
public void setLeftParrot(EntityMetadata<CompoundTag> entityMetadata) { public void setLeftParrot(EntityMetadata<CompoundTag, ?> entityMetadata) {
setParrot(entityMetadata.getValue(), true); setParrot(entityMetadata.getValue(), true);
} }
public void setRightParrot(EntityMetadata<CompoundTag> entityMetadata) { public void setRightParrot(EntityMetadata<CompoundTag, ?> entityMetadata) {
setParrot(entityMetadata.getValue(), false); setParrot(entityMetadata.getValue(), false);
} }
@ -330,7 +332,7 @@ public class PlayerEntity extends LivingEntity {
} }
@Override @Override
public void setDisplayName(EntityMetadata<Component> entityMetadata) { public void setDisplayName(EntityMetadata<Optional<Component>, ?> entityMetadata) {
// Doesn't do anything for players // Doesn't do anything for players
} }
@ -385,7 +387,7 @@ public class PlayerEntity extends LivingEntity {
} }
@Override @Override
public void setDisplayNameVisible(EntityMetadata<Boolean> entityMetadata) { public void setDisplayNameVisible(BooleanEntityMetadata entityMetadata) {
// Doesn't do anything for players // Doesn't do anything for players
} }

View file

@ -110,14 +110,14 @@ public class SessionPlayerEntity extends PlayerEntity {
} }
@Override @Override
public void setFlags(EntityMetadata<Byte> entityMetadata) { public void setFlags(ByteEntityMetadata entityMetadata) {
super.setFlags(entityMetadata); super.setFlags(entityMetadata);
session.setSwimmingInWater((((ByteEntityMetadata) entityMetadata).getPrimitiveValue() & 0x10) == 0x10 && getFlag(EntityFlag.SPRINTING)); session.setSwimmingInWater((entityMetadata.getPrimitiveValue() & 0x10) == 0x10 && getFlag(EntityFlag.SPRINTING));
refreshSpeed = true; refreshSpeed = true;
} }
@Override @Override
public void setPose(EntityMetadata<Pose> entityMetadata) { public void setPose(EntityMetadata<Pose, ?> entityMetadata) {
super.setPose(entityMetadata); super.setPose(entityMetadata);
session.setPose(entityMetadata.getValue()); session.setPose(entityMetadata.getValue());
refreshSpeed = true; refreshSpeed = true;
@ -132,11 +132,11 @@ public class SessionPlayerEntity extends PlayerEntity {
} }
@Override @Override
protected void setAir(int amount) { protected void setAirSupply(int amount) {
if (amount == getMaxAir()) { if (amount == getMaxAir()) {
super.setAir(0); // Hide the bubble counter from the UI for the player super.setAirSupply(0); // Hide the bubble counter from the UI for the player
} else { } else {
super.setAir(amount); super.setAirSupply(amount);
} }
} }

View file

@ -26,8 +26,10 @@
package org.geysermc.connector.network.translators.java.entity; package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityDataPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityDataPacket;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.EntityDefinition;
import org.geysermc.connector.entity.EntityMetadataTranslator; import org.geysermc.connector.entity.EntityMetadataTranslator;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -39,6 +41,7 @@ import java.util.List;
@Translator(packet = ClientboundSetEntityDataPacket.class) @Translator(packet = ClientboundSetEntityDataPacket.class)
public class JavaSetEntityDataTranslator extends PacketTranslator<ClientboundSetEntityDataPacket> { public class JavaSetEntityDataTranslator extends PacketTranslator<ClientboundSetEntityDataPacket> {
@SuppressWarnings({"rawtypes", "unchecked"})
@Override @Override
public void translate(GeyserSession session, ClientboundSetEntityDataPacket packet) { public void translate(GeyserSession session, ClientboundSetEntityDataPacket packet) {
Entity entity; Entity entity;
@ -49,30 +52,17 @@ public class JavaSetEntityDataTranslator extends PacketTranslator<ClientboundSet
} }
if (entity == null) return; if (entity == null) return;
List<EntityMetadataTranslator<?, ?>> translators = (List<EntityMetadataTranslator<?, ?>>) entity.getDefinition().translators(); EntityDefinition<?> definition = entity.getDefinition();
for (EntityMetadata<?, ?> metadata : packet.getMetadata()) {
for (EntityMetadata<?> metadata : packet.getMetadata()) { if (metadata.getId() >= definition.translators().size()) {
if (metadata.getId() >= translators.size()) { session.getConnector().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getDefinition().entityType());
session.getConnector().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + translators.size() + " for entity type " + entity.getDefinition().entityType());
if (session.getConnector().getConfig().isDebugMode()) { if (session.getConnector().getConfig().isDebugMode()) {
session.getConnector().getLogger().debug(metadata.toString()); session.getConnector().getLogger().debug(metadata.toString());
} }
continue; continue;
} }
EntityMetadataTranslator<? super Entity, Object> translator = (EntityMetadataTranslator<? super Entity, Object>) translators.get(metadata.getId()); ((EntityDefinition) definition).translateMetadata(entity, metadata);
if (translator == null) {
// This can safely happen; it means we don't translate this entity metadata
continue;
}
if (translator.acceptedType() != metadata.getType()) {
session.getConnector().getLogger().warning("Metadata ID " + metadata.getId() + " was received with type " + metadata.getType() + " but we expected " + translator.acceptedType() + " for " + entity.getDefinition().entityType());
if (session.getConnector().getConfig().isDebugMode()) {
session.getConnector().getLogger().debug(metadata.toString());
}
continue;
}
translator.translateFunction().accept(entity, (EntityMetadata<Object>) metadata);
} }
entity.updateBedrockMetadata(); entity.updateBedrockMetadata();

View file

@ -39,6 +39,7 @@ import org.geysermc.connector.utils.FileUtils;
import java.io.InputStream; import java.io.InputStream;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;

View file

@ -32,6 +32,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.registry.type.ParticleMapping; import org.geysermc.connector.registry.type.ParticleMapping;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;