Skip to content

Commit

Permalink
Fix runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 27, 2024
1 parent 1e2348e commit 710dbef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void setMetadata(EntityMetadata<?, ?> metadata) {
this.metadataStore.put(metadata.getId(), metadata);
}

public <V, T extends MetadataType<V>> void setMetadata(NamedEntityData namedEntityData, T metadataType, V value) {
this.metadataStore.put(namedEntityData.networkId(), metadataType.getMetadataFactory().create(namedEntityData.networkId(), metadataType, value));
public <V, T extends MetadataType<V>> void setMetadata(NamedEntityData namedEntityData, T metadataType, MetadataFactory<V, T> factory, V value) {
this.metadataStore.put(namedEntityData.networkId(), factory.create(namedEntityData.networkId(), metadataType, value));
}

public <T> T getMetadata(NamedEntityData namedEntityData, MetadataType<T> metadataType) {
Expand Down Expand Up @@ -83,4 +83,7 @@ public <T> Optional<T> getMetadata(int id, MetadataType<T> metadataType) {
return namedMap;
}

public interface MetadataFactory<V, T extends MetadataType<V>> {
EntityMetadata<V, ? extends MetadataType<V>> create(int id, T type, V value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.RotationOrigin;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.ObjectData;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PositionElement;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;
Expand Down Expand Up @@ -897,9 +899,9 @@ protected Vector3d maybeBackOffFromEdge(Vector3d vec, MoverType mover) {
protected void setSharedFlag(int flag, boolean set) {
byte b = this.metadataState.getMetadata(NamedEntityData.ENTITY__SHARED_FLAGS, MetadataType.BYTE);
if (set) {
this.metadataState.setMetadata(NamedEntityData.ENTITY__SHARED_FLAGS, MetadataType.BYTE, (byte) (b | 1 << flag));
this.metadataState.setMetadata(NamedEntityData.ENTITY__SHARED_FLAGS, MetadataType.BYTE, ByteEntityMetadata::new, (byte) (b | 1 << flag));
} else {
this.metadataState.setMetadata(NamedEntityData.ENTITY__SHARED_FLAGS, MetadataType.BYTE, (byte) (b & ~(1 << flag)));
this.metadataState.setMetadata(NamedEntityData.ENTITY__SHARED_FLAGS, MetadataType.BYTE, ByteEntityMetadata::new, (byte) (b & ~(1 << flag)));
}
}

Expand Down Expand Up @@ -931,7 +933,7 @@ public Pose getPose() {
}

public void setPose(Pose pose) {
this.metadataState.setMetadata(NamedEntityData.ENTITY__POSE, MetadataType.POSE, pose);
this.metadataState.setMetadata(NamedEntityData.ENTITY__POSE, MetadataType.POSE, ObjectEntityMetadata::new, pose);
}

public boolean hasPose(Pose pose) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;

Expand Down Expand Up @@ -495,7 +497,7 @@ protected void setLivingEntityFlag(int key, boolean value) {
currentFlags &= ~key;
}

this.metadataState.setMetadata(NamedEntityData.LIVING_ENTITY__LIVING_ENTITY_FLAGS, MetadataType.BYTE, (byte) currentFlags);
this.metadataState.setMetadata(NamedEntityData.LIVING_ENTITY__LIVING_ENTITY_FLAGS, MetadataType.BYTE, ByteEntityMetadata::new, (byte) currentFlags);
}

@Override
Expand Down Expand Up @@ -557,7 +559,7 @@ public float getHealth() {
}

public void setHealth(float health) {
this.metadataState.setMetadata(NamedEntityData.LIVING_ENTITY__HEALTH, MetadataType.FLOAT, MathHelper.clamp(health, 0.0F, this.getMaxHealth()));
this.metadataState.setMetadata(NamedEntityData.LIVING_ENTITY__HEALTH, MetadataType.FLOAT, FloatEntityMetadata::new, MathHelper.clamp(health, 0.0F, this.getMaxHealth()));
}

public boolean isDeadOrDying() {
Expand Down

0 comments on commit 710dbef

Please sign in to comment.