3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Add falling blocks

Dieser Commit ist enthalten in:
William Johnstone 2020-04-07 20:45:59 +01:00
Ursprung 16388a1f85
Commit 8cab3cce26
4 geänderte Dateien mit 40 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,17 @@
package org.geysermc.connector.entity;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.translators.block.BlockTranslator;
public class FallingBlockEntity extends Entity {
public FallingBlockEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, int javaId) {
super(entityId, geyserId, entityType, position, motion, rotation);
int bedrockId = BlockTranslator.getBedrockBlockId(javaId);
this.metadata.put(EntityData.VARIANT, bedrockId);
}
}

Datei anzeigen

@ -103,7 +103,7 @@ public enum EntityType {
PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f), PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f),
ITEM(ItemEntity.class, 64, 0.25f, 0.25f), ITEM(ItemEntity.class, 64, 0.25f, 0.25f),
TNT(Entity.class, 65, 0.98f, 0.98f), TNT(Entity.class, 65, 0.98f, 0.98f),
FALLING_BLOCK(Entity.class, 66, 0.98f, 0.98f), FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f),
MOVING_BLOCK(Entity.class, 67, 0f), MOVING_BLOCK(Entity.class, 67, 0f),
EXPERIENCE_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f), EXPERIENCE_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f),
EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f), EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f),

Datei anzeigen

@ -177,6 +177,10 @@ public class BlockTranslator {
return JAVA_TO_BEDROCK_BLOCK_MAP.get(state.getId()); return JAVA_TO_BEDROCK_BLOCK_MAP.get(state.getId());
} }
public static int getBedrockBlockId(int javaId) {
return JAVA_TO_BEDROCK_BLOCK_MAP.get(javaId);
}
public static BlockState getJavaBlockState(int bedrockId) { public static BlockState getJavaBlockState(int bedrockId) {
return BEDROCK_TO_JAVA_BLOCK_MAP.get(bedrockId); return BEDROCK_TO_JAVA_BLOCK_MAP.get(bedrockId);
} }

Datei anzeigen

@ -28,7 +28,9 @@ package org.geysermc.connector.network.translators.java.entity.spawn;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.FallingBlockData;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.FallingBlockEntity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
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;
@ -47,6 +49,11 @@ public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjec
if (packet.getType() == ObjectType.ITEM_FRAME) if (packet.getType() == ObjectType.ITEM_FRAME)
return; return;
int javaId = -1;
if (packet.getType() == ObjectType.FALLING_BLOCK) {
javaId = ((FallingBlockData) packet.getData()).getId();
}
Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ()); Vector3f motion = Vector3f.from(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
Vector3f rotation = Vector3f.from(packet.getYaw(), packet.getPitch(), 0); Vector3f rotation = Vector3f.from(packet.getYaw(), packet.getPitch(), 0);
@ -59,12 +66,18 @@ public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjec
Class<? extends Entity> entityClass = type.getEntityClass(); Class<? extends Entity> entityClass = type.getEntityClass();
try { try {
Constructor<? extends Entity> entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class, Entity entity;
Vector3f.class, Vector3f.class, Vector3f.class); if (packet.getType() == ObjectType.FALLING_BLOCK) {
entity = new FallingBlockEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation, javaId);
} else {
Constructor<? extends Entity> entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class,
Vector3f.class, Vector3f.class, Vector3f.class);
Entity entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation type, position, motion, rotation
); );
}
session.getEntityCache().spawnEntity(entity); session.getEntityCache().spawnEntity(entity);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace(); ex.printStackTrace();