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

Implement chest boat

Dieser Commit ist enthalten in:
Camotoy 2022-05-26 13:11:39 -04:00
Ursprung 66a7efaa96
Commit 9183897d52
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
8 geänderte Dateien mit 24 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -63,6 +63,7 @@ public final class EntityDefinitions {
public static final EntityDefinition<SpiderEntity> CAVE_SPIDER; public static final EntityDefinition<SpiderEntity> CAVE_SPIDER;
public static final EntityDefinition<MinecartEntity> CHEST_MINECART; public static final EntityDefinition<MinecartEntity> CHEST_MINECART;
public static final EntityDefinition<ChickenEntity> CHICKEN; public static final EntityDefinition<ChickenEntity> CHICKEN;
public static final EntityDefinition<BoatEntity> CHEST_BOAT;
public static final EntityDefinition<AbstractFishEntity> COD; public static final EntityDefinition<AbstractFishEntity> COD;
public static final EntityDefinition<CommandBlockMinecartEntity> COMMAND_BLOCK_MINECART; public static final EntityDefinition<CommandBlockMinecartEntity> COMMAND_BLOCK_MINECART;
public static final EntityDefinition<CowEntity> COW; public static final EntityDefinition<CowEntity> COW;
@ -209,6 +210,9 @@ public final class EntityDefinitions {
.addTranslator(MetadataType.BOOLEAN, BoatEntity::setPaddlingRight) .addTranslator(MetadataType.BOOLEAN, BoatEntity::setPaddlingRight)
.addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.BOAT_BUBBLE_TIME, entityMetadata.getValue())) // May not actually do anything .addTranslator(MetadataType.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityData.BOAT_BUBBLE_TIME, entityMetadata.getValue())) // May not actually do anything
.build(); .build();
CHEST_BOAT = EntityDefinition.inherited(BOAT.factory(), BOAT)
.type(EntityType.CHEST_BOAT)
.build();
DRAGON_FIREBALL = EntityDefinition.inherited(FireballEntity::new, entityBase) DRAGON_FIREBALL = EntityDefinition.inherited(FireballEntity::new, entityBase)
.type(EntityType.DRAGON_FIREBALL) .type(EntityType.DRAGON_FIREBALL)
.heightAndWidth(1.0f) .heightAndWidth(1.0f)

Datei anzeigen

@ -52,7 +52,7 @@ public class BedrockEntityPickRequestTranslator extends PacketTranslator<EntityP
// Get the corresponding item // Get the corresponding item
String itemName; String itemName;
switch (entity.getDefinition().entityType()) { switch (entity.getDefinition().entityType()) {
case BOAT -> { case BOAT, CHEST_BOAT -> {
// Include type of boat in the name // Include type of boat in the name
int variant = ((BoatEntity) entity).getVariant(); int variant = ((BoatEntity) entity).getVariant();
String typeOfBoat = switch (variant) { String typeOfBoat = switch (variant) {
@ -61,9 +61,10 @@ public class BedrockEntityPickRequestTranslator extends PacketTranslator<EntityP
case 3 -> "jungle"; case 3 -> "jungle";
case 4 -> "acacia"; case 4 -> "acacia";
case 5 -> "dark_oak"; case 5 -> "dark_oak";
case 6 -> "mangrove";
default -> "oak"; default -> "oak";
}; };
itemName = typeOfBoat + "_boat"; itemName = typeOfBoat + "_" + entity.getDefinition().entityType().name().toLowerCase(Locale.ROOT);
} }
case LEASH_KNOT -> itemName = "lead"; case LEASH_KNOT -> itemName = "lead";
case CHEST_MINECART, COMMAND_BLOCK_MINECART, FURNACE_MINECART, HOPPER_MINECART, TNT_MINECART -> case CHEST_MINECART, COMMAND_BLOCK_MINECART, FURNACE_MINECART, HOPPER_MINECART, TNT_MINECART ->

Datei anzeigen

@ -28,10 +28,10 @@ package org.geysermc.geyser.translator.protocol.bedrock.entity.player;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;
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.inventory.ContainerType; import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket; import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
import com.nukkitx.protocol.bedrock.packet.InteractPacket; import com.nukkitx.protocol.bedrock.packet.InteractPacket;
@ -96,12 +96,10 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
case OPEN_INVENTORY: case OPEN_INVENTORY:
if (session.getOpenInventory() == null) { if (session.getOpenInventory() == null) {
Entity ridingEntity = session.getPlayerEntity().getVehicle(); Entity ridingEntity = session.getPlayerEntity().getVehicle();
if (ridingEntity instanceof AbstractHorseEntity) { if (ridingEntity instanceof AbstractHorseEntity || (ridingEntity != null && ridingEntity.getDefinition().entityType() == EntityType.CHEST_BOAT)) {
if (ridingEntity.getFlag(EntityFlag.TAMED)) { // This mob has an inventory of its own that we should open instead.
// We should request to open the horse inventory instead ServerboundPlayerCommandPacket openVehicleWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_VEHICLE_INVENTORY);
ServerboundPlayerCommandPacket openHorseWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_HORSE_INVENTORY); session.sendDownstreamPacket(openVehicleWindowPacket);
session.sendDownstreamPacket(openHorseWindowPacket);
}
} else { } else {
session.setOpenInventory(session.getPlayerInventory()); session.setOpenInventory(session.getPlayerInventory());

Datei anzeigen

@ -31,7 +31,7 @@ import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
@Translator(packet = ClientboundBlockChangedAckPacket.class) @Translator(packet = ClientboundBlockChangedAckPacket.class)
public class JavaBlockBreakAckTranslator extends PacketTranslator<ClientboundBlockChangedAckPacket> { public class JavaBlockChangedAckTranslator extends PacketTranslator<ClientboundBlockChangedAckPacket> {
@Override @Override
public void translate(GeyserSession session, ClientboundBlockChangedAckPacket packet) { public void translate(GeyserSession session, ClientboundBlockChangedAckPacket packet) {

Datei anzeigen

@ -27,14 +27,13 @@ package org.geysermc.geyser.translator.protocol.java.level;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockDestructionPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockDestructionPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.util.BlockUtils; import org.geysermc.geyser.util.BlockUtils;
@Translator(packet = ClientboundBlockDestructionPacket.class) @Translator(packet = ClientboundBlockDestructionPacket.class)
@ -45,11 +44,7 @@ public class JavaBlockDestructionTranslator extends PacketTranslator<Clientbound
int state = session.getGeyser().getWorldManager().getBlockAt(session, packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()); int state = session.getGeyser().getWorldManager().getBlockAt(session, packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
int breakTime = (int) (65535 / Math.ceil(BlockUtils.getBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(state), ItemMapping.AIR, new CompoundTag(""), false) * 20)); int breakTime = (int) (65535 / Math.ceil(BlockUtils.getBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(state), ItemMapping.AIR, new CompoundTag(""), false) * 20));
LevelEventPacket levelEventPacket = new LevelEventPacket(); LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(Vector3f.from( levelEventPacket.setPosition(packet.getPosition().toFloat());
packet.getPosition().getX(),
packet.getPosition().getY(),
packet.getPosition().getZ()
));
levelEventPacket.setType(LevelEventType.BLOCK_START_BREAK); levelEventPacket.setType(LevelEventType.BLOCK_START_BREAK);
switch (packet.getStage()) { switch (packet.getStage()) {

Datei anzeigen

@ -54,7 +54,8 @@ public class JavaLevelEventTranslator extends PacketTranslator<ClientboundLevelE
if (packet.getEvent() == com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent.RECORD) { if (packet.getEvent() == com.github.steveice10.mc.protocol.data.game.level.event.SoundEvent.RECORD) {
RecordEventData recordEventData = (RecordEventData) packet.getData(); RecordEventData recordEventData = (RecordEventData) packet.getData();
SoundEvent soundEvent = Registries.RECORDS.getOrDefault(recordEventData.getRecordId(), SoundEvent.STOP_RECORD); SoundEvent soundEvent = Registries.RECORDS.getOrDefault(recordEventData.getRecordId(), SoundEvent.STOP_RECORD);
Vector3f pos = Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f); Vector3i origin = packet.getPosition();
Vector3f pos = Vector3f.from(origin.getX() + 0.5f, origin.getY() + 0.5f, origin.getZ() + 0.5f);
LevelSoundEventPacket levelSoundEvent = new LevelSoundEventPacket(); LevelSoundEventPacket levelSoundEvent = new LevelSoundEventPacket();
levelSoundEvent.setIdentifier(""); levelSoundEvent.setIdentifier("");

Datei anzeigen

@ -32,6 +32,7 @@ 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.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.entity.type.BoatEntity;
import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.living.ArmorStandEntity; import org.geysermc.geyser.entity.type.living.ArmorStandEntity;
import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
@ -85,7 +86,7 @@ public final class EntityUtils {
case TRADER_LLAMA, LLAMA -> mountedHeightOffset = height * 0.6f; case TRADER_LLAMA, LLAMA -> mountedHeightOffset = height * 0.6f;
case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
COMMAND_BLOCK_MINECART -> mountedHeightOffset = 0; COMMAND_BLOCK_MINECART -> mountedHeightOffset = 0;
case BOAT -> mountedHeightOffset = -0.1f; case BOAT, CHEST_BOAT -> mountedHeightOffset = -0.1f;
case HOGLIN, ZOGLIN -> { case HOGLIN, ZOGLIN -> {
boolean isBaby = mount.getFlag(EntityFlag.BABY); boolean isBaby = mount.getFlag(EntityFlag.BABY);
mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f); mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f);
@ -160,13 +161,14 @@ public final class EntityUtils {
xOffset = -0.6f; xOffset = -0.6f;
} }
} }
case CHEST_BOAT -> xOffset = 0.15F;
case CHICKEN -> zOffset = -0.1f; case CHICKEN -> zOffset = -0.1f;
case TRADER_LLAMA, LLAMA -> zOffset = -0.3f; case TRADER_LLAMA, LLAMA -> zOffset = -0.3f;
} }
if (passenger.getDefinition().entityType() == EntityType.SHULKER) { if (passenger.getDefinition().entityType() == EntityType.SHULKER) {
switch (mount.getDefinition().entityType()) { switch (mount.getDefinition().entityType()) {
case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
COMMAND_BLOCK_MINECART, BOAT -> yOffset = 0.1875f; COMMAND_BLOCK_MINECART, BOAT, CHEST_BOAT -> yOffset = 0.1875f;
} }
} }
/* /*
@ -182,7 +184,7 @@ public final class EntityUtils {
} }
switch (mount.getDefinition().entityType()) { switch (mount.getDefinition().entityType()) {
case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART,
COMMAND_BLOCK_MINECART, BOAT -> yOffset -= mount.getDefinition().height() * 0.5f; COMMAND_BLOCK_MINECART, BOAT, CHEST_BOAT -> yOffset -= mount.getDefinition().height() * 0.5f;
} }
Vector3f offset = Vector3f.from(xOffset, yOffset, zOffset); Vector3f offset = Vector3f.from(xOffset, yOffset, zOffset);
passenger.setRiderSeatPosition(offset); passenger.setRiderSeatPosition(offset);
@ -190,7 +192,7 @@ public final class EntityUtils {
} }
public static void updateRiderRotationLock(Entity passenger, Entity mount, boolean isRiding) { public static void updateRiderRotationLock(Entity passenger, Entity mount, boolean isRiding) {
if (isRiding && mount.getDefinition() == EntityDefinitions.BOAT) { if (isRiding && mount instanceof BoatEntity) {
// Head rotation is locked while riding in a boat // Head rotation is locked while riding in a boat
passenger.getDirtyMetadata().put(EntityData.RIDER_ROTATION_LOCKED, (byte) 1); passenger.getDirtyMetadata().put(EntityData.RIDER_ROTATION_LOCKED, (byte) 1);
passenger.getDirtyMetadata().put(EntityData.RIDER_MAX_ROTATION, 90f); passenger.getDirtyMetadata().put(EntityData.RIDER_MAX_ROTATION, 90f);