3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Merge remote-tracking branch 'origin/feature/1.20.5' into feature/1.20.5

Dieser Commit ist enthalten in:
Camotoy 2024-04-26 21:46:38 -04:00
Commit 9217414c8c
21 geänderte Dateien mit 429 neuen und 50 gelöschten Zeilen

Datei anzeigen

@ -32,6 +32,9 @@ import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.event.connection.ConnectionEvent; import org.geysermc.geyser.api.event.connection.ConnectionEvent;
import org.geysermc.geyser.api.network.RemoteServer; import org.geysermc.geyser.api.network.RemoteServer;
import java.util.Map;
import java.util.Objects;
/** /**
* Called when a session has logged in, and is about to connect to a remote java server. * Called when a session has logged in, and is about to connect to a remote java server.
* This event is cancellable, and can be used to prevent the player from connecting to the remote server. * This event is cancellable, and can be used to prevent the player from connecting to the remote server.
@ -40,10 +43,16 @@ public final class SessionLoginEvent extends ConnectionEvent implements Cancella
private RemoteServer remoteServer; private RemoteServer remoteServer;
private boolean cancelled; private boolean cancelled;
private String disconnectReason; private String disconnectReason;
private Map<String, byte[]> cookies;
private boolean transferring;
public SessionLoginEvent(@NonNull GeyserConnection connection, @NonNull RemoteServer remoteServer) { public SessionLoginEvent(@NonNull GeyserConnection connection,
@NonNull RemoteServer remoteServer,
@NonNull Map<String, byte[]> cookies) {
super(connection); super(connection);
this.remoteServer = remoteServer; this.remoteServer = remoteServer;
this.cookies = cookies;
this.transferring = false;
} }
/** /**
@ -106,4 +115,36 @@ public final class SessionLoginEvent extends ConnectionEvent implements Cancella
public void remoteServer(@NonNull RemoteServer remoteServer) { public void remoteServer(@NonNull RemoteServer remoteServer) {
this.remoteServer = remoteServer; this.remoteServer = remoteServer;
} }
/**
* Sets a map of cookies from a possible previous session. The Java server can send and request these
* to store information on the client across server transfers.
*/
public void cookies(@NonNull Map<String, byte[]> cookies) {
Objects.requireNonNull(cookies);
this.cookies = cookies;
}
/**
* Gets a map of the sessions cookies, if set.
* @return the connections cookies
*/
public @NonNull Map<String, byte[]> cookies() {
return cookies;
}
/**
* Determines the connection intent of the connection
*/
public void transferring(boolean transferring) {
this.transferring = transferring;
}
/**
* Gets whether this login attempt to the Java server
* has the transfer intent
*/
public boolean transferring() {
return this.transferring;
}
} }

Datei anzeigen

@ -0,0 +1,123 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.event.java;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.common.value.qual.IntRange;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.event.connection.ConnectionEvent;
import java.util.Map;
/**
* Fired when the Java server sends a transfer request to a different Java server.
* Geyser Extensions can listen to this event and set a target server ip/port for Bedrock players to be transferred to.
*/
public class ServerTransferEvent extends ConnectionEvent {
private final String host;
private final int port;
private String bedrockHost;
private int bedrockPort;
private final Map<String, byte[]> cookies;
public ServerTransferEvent(@NonNull GeyserConnection connection, String host, int port, Map<String, byte[]> cookies) {
super(connection);
this.host = host;
this.port = port;
this.cookies = cookies;
this.bedrockHost = null;
this.bedrockPort = -1;
}
/**
* The host that the Java server requests a transfer to.
*
* @return the host
*/
public String host() {
return this.host;
}
/**
* The port that the Java server requests a transfer to.
*
* @return the port
*/
public int port() {
return this.port;
}
/**
* The host that the Bedrock player should try and connect to.
* If this is not set, the Bedrock player will just be disconnected.
*
* @return the host where the Bedrock client will be transferred to, or null if not set.
*/
public String bedrockHost() {
return this.bedrockHost;
}
/**
* The port that the Bedrock player should try and connect to.
* If this is not set, the Bedrock player will just be disconnected.
*
* @return the port where the Bedrock client will be transferred to, or -1 if not set.
*/
public int bedrockPort() {
return this.bedrockPort;
}
/**
* Sets the host for the Bedrock player to be transferred to
*/
public void bedrockHost(@NonNull String host) {
if (host == null || host.isBlank()) {
throw new IllegalArgumentException("Server address cannot be null or blank");
}
this.bedrockHost = host;
}
/**
* Sets the port for the Bedrock player to be transferred to
*/
public void bedrockPort(@IntRange(from = 0, to = 65535) int port) {
if (port < 0 || port > 65535) {
throw new IllegalArgumentException("Server port must be between 0 and 65535, was " + port);
}
this.bedrockPort = port;
}
/**
* Gets a map of the sessions current cookies.
*
* @return the connections cookies
*/
public @NonNull Map<String, byte[]> cookies() {
return cookies;
}
}

Datei anzeigen

@ -175,8 +175,9 @@ public class GeyserSpigotInjector extends GeyserInjector {
MinecraftProtocol protocol = new MinecraftProtocol(); MinecraftProtocol protocol = new MinecraftProtocol();
LocalSession session = new LocalSession(bootstrap.getGeyserConfig().getRemote().address(), LocalSession session = new LocalSession(bootstrap.getGeyserConfig().getRemote().address(),
bootstrap.getGeyserConfig().getRemote().port(), this.serverSocketAddress, bootstrap.getGeyserConfig().getRemote().port(), this.serverSocketAddress,
InetAddress.getLoopbackAddress().getHostAddress(), protocol, protocol.createHelper()); InetAddress.getLoopbackAddress().getHostAddress(), protocol, protocol.createHelper(), false);
session.connect(); session.connect();
session.disconnect("");
} }
@Override @Override

Datei anzeigen

@ -50,7 +50,7 @@ public class EnumProperty implements PropertyType {
public NbtMap nbtMap() { public NbtMap nbtMap() {
return NbtMap.builder() return NbtMap.builder()
.putString("name", name) .putString("name", name)
.putList("values", NbtType.STRING, values) .putList("enum", NbtType.STRING, values)
.putInt("type", 3) .putInt("type", 3)
.build(); .build();
} }

Datei anzeigen

@ -45,6 +45,7 @@ import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.item.ItemTranslator;
import org.geysermc.geyser.util.AttributeUtils; import org.geysermc.geyser.util.AttributeUtils;
import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractionResult;
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.Attribute; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.Attribute;
@ -55,6 +56,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEn
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import java.util.*; import java.util.*;
@ -68,7 +70,7 @@ public class LivingEntity extends Entity {
protected ItemData leggings = ItemData.AIR; protected ItemData leggings = ItemData.AIR;
protected ItemData boots = ItemData.AIR; protected ItemData boots = ItemData.AIR;
protected ItemData hand = ItemData.AIR; protected ItemData hand = ItemData.AIR;
protected ItemData offHand = ItemData.AIR; protected ItemData offhand = ItemData.AIR;
@Getter(value = AccessLevel.NONE) @Getter(value = AccessLevel.NONE)
protected float health = 1f; // The default value in Java Edition before any entity metadata is sent protected float health = 1f; // The default value in Java Edition before any entity metadata is sent
@ -84,6 +86,36 @@ public class LivingEntity 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 setHelmet(ItemStack stack) {
this.helmet = ItemTranslator.translateToBedrock(session, stack);
}
public void setChestplate(ItemStack stack) {
this.chestplate = ItemTranslator.translateToBedrock(session, stack);
}
public void setLeggings(ItemStack stack) {
this.leggings = ItemTranslator.translateToBedrock(session, stack);
}
public void setBoots(ItemStack stack) {
this.boots = ItemTranslator.translateToBedrock(session, stack);
}
public void setHand(ItemStack stack) {
this.hand = ItemTranslator.translateToBedrock(session, stack);
}
public void setOffhand(ItemStack stack) {
this.offhand = ItemTranslator.translateToBedrock(session, stack);
}
public void switchHands() {
ItemData offhand = this.offhand;
this.offhand = this.hand;
this.hand = offhand;
}
@Override @Override
protected void initializeMetadata() { protected void initializeMetadata() {
super.initializeMetadata(); super.initializeMetadata();
@ -134,7 +166,7 @@ public class LivingEntity extends Entity {
protected boolean hasShield(boolean offhand) { protected boolean hasShield(boolean offhand) {
ItemMapping shieldMapping = session.getItemMappings().getStoredItems().shield(); ItemMapping shieldMapping = session.getItemMappings().getStoredItems().shield();
if (offhand) { if (offhand) {
return offHand.getDefinition().equals(shieldMapping.getBedrockDefinition()); return this.offhand.getDefinition().equals(shieldMapping.getBedrockDefinition());
} else { } else {
return hand.getDefinition().equals(shieldMapping.getBedrockDefinition()); return hand.getDefinition().equals(shieldMapping.getBedrockDefinition());
} }
@ -246,7 +278,7 @@ public class LivingEntity extends Entity {
MobEquipmentPacket offHandPacket = new MobEquipmentPacket(); MobEquipmentPacket offHandPacket = new MobEquipmentPacket();
offHandPacket.setRuntimeEntityId(geyserId); offHandPacket.setRuntimeEntityId(geyserId);
offHandPacket.setItem(offHand); offHandPacket.setItem(offhand);
offHandPacket.setHotbarSlot(-1); offHandPacket.setHotbarSlot(-1);
offHandPacket.setInventorySlot(0); offHandPacket.setInventorySlot(0);
offHandPacket.setContainerId(ContainerId.OFFHAND); offHandPacket.setContainerId(ContainerId.OFFHAND);

Datei anzeigen

@ -43,6 +43,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetad
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -257,38 +258,38 @@ public class ArmorStandEntity extends LivingEntity {
} }
@Override @Override
public void setHelmet(ItemData helmet) { public void setHelmet(ItemStack helmet) {
super.setHelmet(helmet); super.setHelmet(helmet);
updateSecondEntityStatus(true); updateSecondEntityStatus(true);
} }
@Override @Override
public void setChestplate(ItemData chestplate) { public void setChestplate(ItemStack chestplate) {
super.setChestplate(chestplate); super.setChestplate(chestplate);
updateSecondEntityStatus(true); updateSecondEntityStatus(true);
} }
@Override @Override
public void setLeggings(ItemData leggings) { public void setLeggings(ItemStack leggings) {
super.setLeggings(leggings); super.setLeggings(leggings);
updateSecondEntityStatus(true); updateSecondEntityStatus(true);
} }
@Override @Override
public void setBoots(ItemData boots) { public void setBoots(ItemStack boots) {
super.setBoots(boots); super.setBoots(boots);
updateSecondEntityStatus(true); updateSecondEntityStatus(true);
} }
@Override @Override
public void setHand(ItemData hand) { public void setHand(ItemStack hand) {
super.setHand(hand); super.setHand(hand);
updateSecondEntityStatus(true); updateSecondEntityStatus(true);
} }
@Override @Override
public void setOffHand(ItemData offHand) { public void setOffhand(ItemStack offHand) {
super.setOffHand(offHand); super.setOffhand(offHand);
updateSecondEntityStatus(true); updateSecondEntityStatus(true);
} }
@ -324,7 +325,7 @@ public class ArmorStandEntity extends LivingEntity {
} }
boolean isNametagEmpty = nametag.isEmpty(); boolean isNametagEmpty = nametag.isEmpty();
if (!isNametagEmpty && (!helmet.equals(ItemData.AIR) || !chestplate.equals(ItemData.AIR) || !leggings.equals(ItemData.AIR) if (!isNametagEmpty && (!helmet.equals(ItemData.AIR) || !chestplate.equals(ItemData.AIR) || !leggings.equals(ItemData.AIR)
|| !boots.equals(ItemData.AIR) || !hand.equals(ItemData.AIR) || !offHand.equals(ItemData.AIR))) { || !boots.equals(ItemData.AIR) || !hand.equals(ItemData.AIR) || !offhand.equals(ItemData.AIR))) {
// Reset scale of the proper armor stand // Reset scale of the proper armor stand
this.dirtyMetadata.put(EntityDataTypes.SCALE, getScale()); this.dirtyMetadata.put(EntityDataTypes.SCALE, getScale());
// Set the proper armor stand to invisible to show armor // Set the proper armor stand to invisible to show armor

Datei anzeigen

@ -32,23 +32,42 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.ArmadilloSt
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class ArmadilloEntity extends AnimalEntity { public class ArmadilloEntity extends AnimalEntity {
private ArmadilloState armadilloState = ArmadilloState.IDLE;
public ArmadilloEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, public ArmadilloEntity(GeyserSession session, int entityId, long geyserId, UUID uuid,
EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
// TODO: This is completely wrong; probably need to store the previous IDLE/ROLLING/SCARED state and check for transitions (pain)
public void setArmadilloState(ObjectEntityMetadata<ArmadilloState> entityMetadata) { public void setArmadilloState(ObjectEntityMetadata<ArmadilloState> entityMetadata) {
ArmadilloState armadilloState = entityMetadata.getValue(); armadilloState = entityMetadata.getValue();
switch (armadilloState) { switch (armadilloState) {
case IDLE -> propertyManager.add("minecraft:armadillo_state", "unrolled"); case IDLE -> propertyManager.add("minecraft:armadillo_state", "unrolled");
case ROLLING -> propertyManager.add("minecraft:armadillo_state", "rolled_up"); case ROLLING -> propertyManager.add("minecraft:armadillo_state", "rolled_up");
case SCARED -> propertyManager.add("minecraft:armadillo_state", "rolled_up_peeking"); case SCARED -> propertyManager.add("minecraft:armadillo_state", "rolled_up_relaxing");
case UNROLLING -> propertyManager.add("minecraft:armadillo_state", "rolled_up_unrolling");
} }
updateBedrockEntityProperties(); updateBedrockEntityProperties();
} }
public void onPeeking() {
// Technically we should wait if not currently scared
if (armadilloState == ArmadilloState.SCARED) {
propertyManager.add("minecraft:armadillo_state", "rolled_up_peeking");
updateBedrockEntityProperties();
// Needed for consecutive peeks
session.scheduleInEventLoop(() -> {
if (armadilloState == ArmadilloState.SCARED) {
propertyManager.add("minecraft:armadillo_state", "rolled_up_relaxing");
updateBedrockEntityProperties();
}
}, 250, TimeUnit.MILLISECONDS);
}
}
} }

Datei anzeigen

@ -33,15 +33,19 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.inventory.item.Enchantment;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.DyeItem; import org.geysermc.geyser.item.type.DyeItem;
import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractionResult;
import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.geyser.util.InteractiveTag;
import org.geysermc.geyser.util.ItemUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import java.util.Collections; import java.util.Collections;
import java.util.Locale; import java.util.Locale;
@ -60,6 +64,8 @@ public class WolfEntity extends TameableEntity {
private byte collarColor = 14; // Red - default private byte collarColor = 14; // Red - default
private boolean isCurseOfBinding = false;
public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
} }
@ -119,6 +125,12 @@ public class WolfEntity extends TameableEntity {
return WOLF_FOODS.contains(item) && !isBaby(); return WOLF_FOODS.contains(item) && !isBaby();
} }
@Override
public void setChestplate(ItemStack stack) {
super.setChestplate(stack);
isCurseOfBinding = ItemUtils.getEnchantmentLevel(stack.getDataComponents(), Enchantment.JavaEnchantment.BINDING_CURSE) > 0;
}
@Override @Override
protected boolean canBeLeashed() { protected boolean canBeLeashed() {
return !getFlag(EntityFlag.ANGRY) && super.canBeLeashed(); return !getFlag(EntityFlag.ANGRY) && super.canBeLeashed();
@ -146,7 +158,8 @@ public class WolfEntity extends TameableEntity {
if (itemInHand.asItem() == Items.WOLF_ARMOR && !this.chestplate.isValid() && !getFlag(EntityFlag.BABY)) { if (itemInHand.asItem() == Items.WOLF_ARMOR && !this.chestplate.isValid() && !getFlag(EntityFlag.BABY)) {
return InteractiveTag.EQUIP_WOLF_ARMOR; return InteractiveTag.EQUIP_WOLF_ARMOR;
} }
if (itemInHand.asItem() == Items.SHEARS && this.chestplate.isValid()) { // TODO: check curse of binding if (itemInHand.asItem() == Items.SHEARS && this.chestplate.isValid()
&& (!isCurseOfBinding || session.getGameMode().equals(GameMode.CREATIVE))) {
return InteractiveTag.REMOVE_WOLF_ARMOR; return InteractiveTag.REMOVE_WOLF_ARMOR;
} }
if (Items.WOLF_ARMOR.isValidRepairItem(itemInHand.asItem()) && getFlag(EntityFlag.SITTING) && if (Items.WOLF_ARMOR.isValidRepairItem(itemInHand.asItem()) && getFlag(EntityFlag.SITTING) &&

Datei anzeigen

@ -66,7 +66,7 @@ public class PiglinEntity extends BasePiglinEntity {
@Override @Override
public void updateOffHand(GeyserSession session) { public void updateOffHand(GeyserSession session) {
// Check if the Piglin is holding Gold and set the ADMIRING flag accordingly so its pose updates // Check if the Piglin is holding Gold and set the ADMIRING flag accordingly so its pose updates
setFlag(EntityFlag.ADMIRING, session.getTagCache().is(ItemTag.PIGLIN_LOVED, session.getItemMappings().getMapping(this.offHand).getJavaItem())); setFlag(EntityFlag.ADMIRING, session.getTagCache().is(ItemTag.PIGLIN_LOVED, session.getItemMappings().getMapping(this.offhand).getJavaItem()));
super.updateBedrockMetadata(); super.updateBedrockMetadata();
super.updateOffHand(session); super.updateOffHand(session);

Datei anzeigen

@ -59,7 +59,7 @@ public class PillagerEntity extends AbstractIllagerEntity {
protected void checkForCrossbow() { protected void checkForCrossbow() {
ItemMapping crossbow = session.getItemMappings().getStoredItems().crossbow(); ItemMapping crossbow = session.getItemMappings().getStoredItems().crossbow();
boolean hasCrossbow = this.hand.getDefinition() == crossbow.getBedrockDefinition() boolean hasCrossbow = this.hand.getDefinition() == crossbow.getBedrockDefinition()
|| this.offHand.getDefinition() == crossbow.getBedrockDefinition(); || this.offhand.getDefinition() == crossbow.getBedrockDefinition();
setFlag(EntityFlag.USING_ITEM, hasCrossbow); setFlag(EntityFlag.USING_ITEM, hasCrossbow);
setFlag(EntityFlag.CHARGED, hasCrossbow); setFlag(EntityFlag.CHARGED, hasCrossbow);

Datei anzeigen

@ -54,11 +54,14 @@ public final class LocalSession extends TcpSession {
private final String clientIp; private final String clientIp;
private final PacketCodecHelper codecHelper; private final PacketCodecHelper codecHelper;
public LocalSession(String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol, MinecraftCodecHelper codecHelper) { private final boolean transferring;
public LocalSession(String host, int port, SocketAddress targetAddress, String clientIp, PacketProtocol protocol, MinecraftCodecHelper codecHelper, boolean transferring) {
super(host, port, protocol); super(host, port, protocol);
this.targetAddress = targetAddress; this.targetAddress = targetAddress;
this.clientIp = clientIp; this.clientIp = clientIp;
this.codecHelper = codecHelper; this.codecHelper = codecHelper;
this.transferring = transferring;
} }
@Override @Override
@ -79,7 +82,7 @@ public final class LocalSession extends TcpSession {
public void initChannel(@NonNull LocalChannelWithRemoteAddress channel) { public void initChannel(@NonNull LocalChannelWithRemoteAddress channel) {
channel.spoofedRemoteAddress(new InetSocketAddress(clientIp, 0)); channel.spoofedRemoteAddress(new InetSocketAddress(clientIp, 0));
PacketProtocol protocol = getPacketProtocol(); PacketProtocol protocol = getPacketProtocol();
protocol.newClientSession(LocalSession.this, false); protocol.newClientSession(LocalSession.this, transferring);
refreshReadTimeoutHandler(channel); refreshReadTimeoutHandler(channel);
refreshWriteTimeoutHandler(channel); refreshWriteTimeoutHandler(channel);

Datei anzeigen

@ -569,6 +569,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Setter @Setter
private @Nullable ItemData currentBook = null; private @Nullable ItemData currentBook = null;
/**
* Stores cookies sent by the Java server.
*/
@Setter @Getter
private Map<String, byte[]> cookies = new Object2ObjectOpenHashMap<>();
private final GeyserCameraData cameraData; private final GeyserCameraData cameraData;
private final GeyserEntityData entityData; private final GeyserEntityData entityData;
@ -853,7 +859,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
* After getting whatever credentials needed, we attempt to join the Java server. * After getting whatever credentials needed, we attempt to join the Java server.
*/ */
private void connectDownstream() { private void connectDownstream() {
SessionLoginEvent loginEvent = new SessionLoginEvent(this, remoteServer); SessionLoginEvent loginEvent = new SessionLoginEvent(this, remoteServer, new Object2ObjectOpenHashMap<>());
GeyserImpl.getInstance().eventBus().fire(loginEvent); GeyserImpl.getInstance().eventBus().fire(loginEvent);
if (loginEvent.isCancelled()) { if (loginEvent.isCancelled()) {
String disconnectReason = loginEvent.disconnectReason() == null ? String disconnectReason = loginEvent.disconnectReason() == null ?
@ -862,6 +868,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return; return;
} }
this.cookies = loginEvent.cookies();
this.remoteServer = loginEvent.remoteServer(); this.remoteServer = loginEvent.remoteServer();
boolean floodgate = this.remoteServer.authType() == AuthType.FLOODGATE; boolean floodgate = this.remoteServer.authType() == AuthType.FLOODGATE;
@ -873,7 +880,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
// We're going to connect through the JVM and not through TCP // We're going to connect through the JVM and not through TCP
downstream = new LocalSession(this.remoteServer.address(), this.remoteServer.port(), downstream = new LocalSession(this.remoteServer.address(), this.remoteServer.port(),
geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(), geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(),
this.protocol, this.protocol.createHelper()); this.protocol, this.protocol.createHelper(), loginEvent.transferring());
this.downstream = new DownstreamSession(downstream); this.downstream = new DownstreamSession(downstream);
} else { } else {
downstream = new TcpClientSession(this.remoteServer.address(), this.remoteServer.port(), this.protocol); downstream = new TcpClientSession(this.remoteServer.address(), this.remoteServer.port(), this.protocol);

Datei anzeigen

@ -357,7 +357,7 @@ public final class ItemTranslator {
} }
if (mapping.getJavaItem().equals(Items.PLAYER_HEAD)) { if (mapping.getJavaItem().equals(Items.PLAYER_HEAD)) {
CustomSkull customSkull = getCustomSkull(session, itemStack.getComponents()); CustomSkull customSkull = getCustomSkull(itemStack.getComponents());
if (customSkull != null) { if (customSkull != null) {
itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customSkull.getCustomBlockData()); itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customSkull.getCustomBlockData());
} }
@ -430,7 +430,7 @@ public final class ItemTranslator {
builder.blockDefinition(blockDefinition); builder.blockDefinition(blockDefinition);
} }
private static @Nullable CustomSkull getCustomSkull(GeyserSession session, DataComponents components) { private static @Nullable CustomSkull getCustomSkull(DataComponents components) {
if (components == null) { if (components == null) {
return null; return null;
} }
@ -441,7 +441,7 @@ public final class ItemTranslator {
try { try {
textures = profile.getTextures(false); textures = profile.getTextures(false);
} catch (PropertyException e) { } catch (PropertyException e) {
session.getGeyser().getLogger().debug("Failed to get textures from GameProfile: " + e); GeyserImpl.getInstance().getLogger().debug("Failed to get textures from GameProfile: " + e);
} }
if (textures == null || textures.isEmpty()) { if (textures == null || textures.isEmpty()) {
@ -461,7 +461,7 @@ public final class ItemTranslator {
} }
private static void translatePlayerHead(GeyserSession session, DataComponents components, ItemData.Builder builder) { private static void translatePlayerHead(GeyserSession session, DataComponents components, ItemData.Builder builder) {
CustomSkull customSkull = getCustomSkull(session, components); CustomSkull customSkull = getCustomSkull(components);
if (customSkull != null) { if (customSkull != null) {
CustomBlockData customBlockData = customSkull.getCustomBlockData(); CustomBlockData customBlockData = customSkull.getCustomBlockData();
ItemDefinition itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customBlockData); ItemDefinition itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customBlockData);

Datei anzeigen

@ -25,12 +25,10 @@
package org.geysermc.geyser.translator.protocol.java.entity; package org.geysermc.geyser.translator.protocol.java.entity;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
import org.cloudburstmc.protocol.bedrock.data.ParticleType; import org.cloudburstmc.protocol.bedrock.data.ParticleType;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType;
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEvent2Packet; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEvent2Packet;
@ -42,10 +40,12 @@ import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.EvokerFangsEntity; import org.geysermc.geyser.entity.type.EvokerFangsEntity;
import org.geysermc.geyser.entity.type.FishingHookEntity; import org.geysermc.geyser.entity.type.FishingHookEntity;
import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.entity.type.LivingEntity;
import org.geysermc.geyser.entity.type.living.animal.ArmadilloEntity;
import org.geysermc.geyser.entity.type.living.monster.WardenEntity; import org.geysermc.geyser.entity.type.living.monster.WardenEntity;
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.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -223,9 +223,7 @@ public class JavaEntityEventTranslator extends PacketTranslator<ClientboundEntit
return; return;
case PLAYER_SWAP_SAME_ITEM: // Not just used for players case PLAYER_SWAP_SAME_ITEM: // Not just used for players
if (entity instanceof LivingEntity livingEntity) { if (entity instanceof LivingEntity livingEntity) {
ItemData newMainHand = livingEntity.getOffHand(); livingEntity.switchHands();
livingEntity.setOffHand(livingEntity.getHand());
livingEntity.setHand(newMainHand);
livingEntity.updateMainHand(session); livingEntity.updateMainHand(session);
livingEntity.updateOffHand(session); livingEntity.updateOffHand(session);
@ -260,6 +258,11 @@ public class JavaEntityEventTranslator extends PacketTranslator<ClientboundEntit
wardenEntity.onSonicBoom(); wardenEntity.onSonicBoom();
} }
break; break;
case ARMADILLO_PEEKING:
if (entity instanceof ArmadilloEntity armadilloEntity) {
armadilloEntity.onPeeking();
}
break;
} }
if (entityEventPacket.getType() != null) { if (entityEventPacket.getType() != null) {

Datei anzeigen

@ -25,19 +25,17 @@
package org.geysermc.geyser.translator.protocol.java.entity; package org.geysermc.geyser.translator.protocol.java.entity;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Equipment;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundSetEquipmentPacket;
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.entity.type.LivingEntity;
import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.skin.FakeHeadProvider; import org.geysermc.geyser.skin.FakeHeadProvider;
import org.geysermc.geyser.translator.item.ItemTranslator;
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.mcprotocollib.protocol.data.game.entity.metadata.Equipment;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundSetEquipmentPacket;
@Translator(packet = ClientboundSetEquipmentPacket.class) @Translator(packet = ClientboundSetEquipmentPacket.class)
public class JavaSetEquipmentTranslator extends PacketTranslator<ClientboundSetEquipmentPacket> { public class JavaSetEquipmentTranslator extends PacketTranslator<ClientboundSetEquipmentPacket> {
@ -58,7 +56,7 @@ public class JavaSetEquipmentTranslator extends PacketTranslator<ClientboundSetE
boolean mainHandUpdated = false; boolean mainHandUpdated = false;
boolean offHandUpdated = false; boolean offHandUpdated = false;
for (Equipment equipment : packet.getEquipment()) { for (Equipment equipment : packet.getEquipment()) {
ItemData item = ItemTranslator.translateToBedrock(session, equipment.getItem()); ItemStack stack = equipment.getItem();
switch (equipment.getSlot()) { switch (equipment.getSlot()) {
case HELMET -> { case HELMET -> {
ItemStack javaItem = equipment.getItem(); ItemStack javaItem = equipment.getItem();
@ -71,28 +69,28 @@ public class JavaSetEquipmentTranslator extends PacketTranslator<ClientboundSetE
FakeHeadProvider.restoreOriginalSkin(session, livingEntity); FakeHeadProvider.restoreOriginalSkin(session, livingEntity);
} }
livingEntity.setHelmet(item); livingEntity.setHelmet(stack);
armorUpdated = true; armorUpdated = true;
} }
case CHESTPLATE, BODY -> { case CHESTPLATE, BODY -> {
// BODY is sent for llamas with a carpet equipped, as of 1.20.5 // BODY is sent for llamas with a carpet equipped, as of 1.20.5
livingEntity.setChestplate(item); livingEntity.setChestplate(stack);
armorUpdated = true; armorUpdated = true;
} }
case LEGGINGS -> { case LEGGINGS -> {
livingEntity.setLeggings(item); livingEntity.setLeggings(stack);
armorUpdated = true; armorUpdated = true;
} }
case BOOTS -> { case BOOTS -> {
livingEntity.setBoots(item); livingEntity.setBoots(stack);
armorUpdated = true; armorUpdated = true;
} }
case MAIN_HAND -> { case MAIN_HAND -> {
livingEntity.setHand(item); livingEntity.setHand(stack);
mainHandUpdated = true; mainHandUpdated = true;
} }
case OFF_HAND -> { case OFF_HAND -> {
livingEntity.setOffHand(item); livingEntity.setOffhand(stack);
offHandUpdated = true; offHandUpdated = true;
} }
} }

Datei anzeigen

@ -0,0 +1,44 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.translator.protocol.java.entity.player;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundCookieRequestPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ServerboundCookieResponsePacket;
@Translator(packet = ClientboundCookieRequestPacket.class)
public class JavaCookieRequestTranslator extends PacketTranslator<ClientboundCookieRequestPacket> {
@Override
public void translate(GeyserSession session, ClientboundCookieRequestPacket packet) {
ServerboundCookieResponsePacket responsePacket = new ServerboundCookieResponsePacket(
packet.getKey(),
session.getCookies().get(packet.getKey())
);
session.sendDownstreamPacket(responsePacket);
}
}

Datei anzeigen

@ -0,0 +1,39 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.translator.protocol.java.entity.player;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundStoreCookiePacket;
@Translator(packet = ClientboundStoreCookiePacket.class)
public class JavaStoreCookieTranslator extends PacketTranslator<ClientboundStoreCookiePacket> {
@Override
public void translate(GeyserSession session, ClientboundStoreCookiePacket packet) {
session.getCookies().put(packet.getKey(), packet.getPayload());
}
}

Datei anzeigen

@ -0,0 +1,54 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.translator.protocol.java.entity.player;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.java.ServerTransferEvent;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundTransferPacket;
@Translator(packet = ClientboundTransferPacket.class)
public class JavaTransferPacketTranslator extends PacketTranslator<ClientboundTransferPacket> {
@Override
public void translate(GeyserSession session, ClientboundTransferPacket packet) {
ServerTransferEvent event = new ServerTransferEvent(
session,
packet.getHost(),
packet.getPort(),
session.getCookies());
GeyserImpl.getInstance().eventBus().fire(event);
if (event.bedrockHost() != null && !event.bedrockHost().isBlank() && event.bedrockPort() != -1) {
session.transfer(event.bedrockHost(), event.bedrockPort());
} else {
session.disconnect(MinecraftLocale.getLocaleString("disconnect.transfer", session.locale()));
}
}
}

Datei anzeigen

@ -145,7 +145,7 @@ public final class BlockUtils {
toolCanBreak = canToolTierBreakBlock(session, blockMapping, toolTier); toolCanBreak = canToolTierBreakBlock(session, blockMapping, toolTier);
} }
int toolEfficiencyLevel = ItemUtils.getEnchantmentLevel(components, Enchantment.JavaEnchantment.EFFICIENCY.ordinal()); int toolEfficiencyLevel = ItemUtils.getEnchantmentLevel(components, Enchantment.JavaEnchantment.EFFICIENCY);
int hasteLevel = 0; int hasteLevel = 0;
int miningFatigueLevel = 0; int miningFatigueLevel = 0;
@ -160,7 +160,7 @@ public final class BlockUtils {
boolean waterInEyes = session.getCollisionManager().isWaterInEyes(); boolean waterInEyes = session.getCollisionManager().isWaterInEyes();
boolean insideOfWaterWithoutAquaAffinity = waterInEyes && boolean insideOfWaterWithoutAquaAffinity = waterInEyes &&
ItemUtils.getEnchantmentLevel(session.getPlayerInventory().getItem(5).getComponents(), Enchantment.JavaEnchantment.AQUA_AFFINITY.ordinal()) < 1; ItemUtils.getEnchantmentLevel(session.getPlayerInventory().getItem(5).getComponents(), Enchantment.JavaEnchantment.AQUA_AFFINITY) < 1;
return calculateBreakTime(blockMapping.getHardness(), toolTier, canHarvestWithHand, correctTool, toolCanBreak, toolType, isShearsEffective, return calculateBreakTime(blockMapping.getHardness(), toolTier, canHarvestWithHand, correctTool, toolCanBreak, toolType, isShearsEffective,
toolEfficiencyLevel, hasteLevel, miningFatigueLevel, insideOfWaterWithoutAquaAffinity, session.getPlayerEntity().isOnGround()); toolEfficiencyLevel, hasteLevel, miningFatigueLevel, insideOfWaterWithoutAquaAffinity, session.getPlayerEntity().isOnGround());

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.geyser.util;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.inventory.item.Enchantment;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.FishingRodItem; import org.geysermc.geyser.item.type.FishingRodItem;
import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.item.type.Item;
@ -36,7 +37,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemEnchantm
public class ItemUtils { public class ItemUtils {
public static int getEnchantmentLevel(@Nullable DataComponents components, int enchantmentId) { public static int getEnchantmentLevel(@Nullable DataComponents components, Enchantment.JavaEnchantment enchantment) {
if (components == null) { if (components == null) {
return 0; return 0;
} }
@ -46,7 +47,7 @@ public class ItemUtils {
return 0; return 0;
} }
return enchantmentData.getEnchantments().getOrDefault(enchantmentId, 0); return enchantmentData.getEnchantments().getOrDefault(enchantment.ordinal(), 0);
} }
/** /**

Datei anzeigen

@ -7,5 +7,5 @@ org.gradle.vfs.watch=false
group=org.geysermc group=org.geysermc
id=geyser id=geyser
version=2.2.3-SNAPSHOT version=2.3.0-SNAPSHOT
description=Allows for players from Minecraft: Bedrock Edition to join Minecraft: Java Edition servers. description=Allows for players from Minecraft: Bedrock Edition to join Minecraft: Java Edition servers.