Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-08 20:43:04 +02:00
More smoothed out shield code (#2051)
- Shield code is now down as the player is sneaking - it doesn't wait for the server to update our sneaking status - Shield is now applied correctly when sneaking and then moving to the shield item
Dieser Commit ist enthalten in:
Ursprung
b176fc7a2f
Commit
f827b28852
@ -28,12 +28,6 @@ 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.EntityMetadata;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
||||||
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.player.Hand;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.AttributeData;
|
import com.nukkitx.protocol.bedrock.data.AttributeData;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||||
@ -50,11 +44,9 @@ import org.geysermc.connector.entity.attribute.AttributeType;
|
|||||||
import org.geysermc.connector.entity.living.ArmorStandEntity;
|
import org.geysermc.connector.entity.living.ArmorStandEntity;
|
||||||
import org.geysermc.connector.entity.player.PlayerEntity;
|
import org.geysermc.connector.entity.player.PlayerEntity;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
import org.geysermc.connector.inventory.PlayerInventory;
|
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
|
||||||
import org.geysermc.connector.utils.AttributeUtils;
|
|
||||||
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||||
|
import org.geysermc.connector.utils.AttributeUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -278,29 +270,6 @@ public class Entity {
|
|||||||
if (!this.is(ArmorStandEntity.class)) {
|
if (!this.is(ArmorStandEntity.class)) {
|
||||||
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20);
|
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shield code
|
|
||||||
if (session.getPlayerEntity().getEntityId() == entityId && metadata.getFlags().getFlag(EntityFlag.SNEAKING)) {
|
|
||||||
PlayerInventory playerInv = session.getPlayerInventory();
|
|
||||||
if ((playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) ||
|
|
||||||
(playerInv.getOffhand().getJavaId() == ItemRegistry.SHIELD.getJavaId())) {
|
|
||||||
ClientPlayerUseItemPacket useItemPacket;
|
|
||||||
metadata.getFlags().setFlag(EntityFlag.BLOCKING, true);
|
|
||||||
if (playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
|
|
||||||
useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
|
||||||
}
|
|
||||||
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent
|
|
||||||
else {
|
|
||||||
useItemPacket = new ClientPlayerUseItemPacket(Hand.OFF_HAND);
|
|
||||||
}
|
|
||||||
session.sendDownstreamPacket(useItemPacket);
|
|
||||||
}
|
|
||||||
} else if (session.getPlayerEntity().getEntityId() == entityId && !metadata.getFlags().getFlag(EntityFlag.SNEAKING) && metadata.getFlags().getFlag(EntityFlag.BLOCKING)) {
|
|
||||||
metadata.getFlags().setFlag(EntityFlag.BLOCKING, false);
|
|
||||||
metadata.getFlags().setFlag(EntityFlag.IS_AVOIDING_BLOCK, true);
|
|
||||||
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, new Position(0, 0, 0), BlockFace.DOWN);
|
|
||||||
session.sendDownstreamPacket(releaseItemPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: // Air/bubbles
|
case 1: // Air/bubbles
|
||||||
|
@ -94,7 +94,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||||||
boolean dropAll = worldAction.getToItem().getCount() > 1;
|
boolean dropAll = worldAction.getToItem().getCount() > 1;
|
||||||
ClientPlayerActionPacket dropAllPacket = new ClientPlayerActionPacket(
|
ClientPlayerActionPacket dropAllPacket = new ClientPlayerActionPacket(
|
||||||
dropAll ? PlayerAction.DROP_ITEM_STACK : PlayerAction.DROP_ITEM,
|
dropAll ? PlayerAction.DROP_ITEM_STACK : PlayerAction.DROP_ITEM,
|
||||||
new Position(0, 0, 0),
|
BlockUtils.POSITION_ZERO,
|
||||||
BlockFace.DOWN
|
BlockFace.DOWN
|
||||||
);
|
);
|
||||||
session.sendDownstreamPacket(dropAllPacket);
|
session.sendDownstreamPacket(dropAllPacket);
|
||||||
@ -292,7 +292,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||||||
case ITEM_RELEASE:
|
case ITEM_RELEASE:
|
||||||
if (packet.getActionType() == 0) {
|
if (packet.getActionType() == 0) {
|
||||||
// Followed to the Minecraft Protocol specification outlined at wiki.vg
|
// Followed to the Minecraft Protocol specification outlined at wiki.vg
|
||||||
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, new Position(0,0,0),
|
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, BlockUtils.POSITION_ZERO,
|
||||||
BlockFace.DOWN);
|
BlockFace.DOWN);
|
||||||
session.sendDownstreamPacket(releaseItemPacket);
|
session.sendDownstreamPacket(releaseItemPacket);
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,19 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.bedrock;
|
package org.geysermc.connector.network.translators.bedrock;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerChangeHeldItemPacket;
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;
|
||||||
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;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
|
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerChangeHeldItemPacket;
|
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;
|
|
||||||
import org.geysermc.connector.utils.CooldownUtils;
|
import org.geysermc.connector.utils.CooldownUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Translator(packet = MobEquipmentPacket.class)
|
@Translator(packet = MobEquipmentPacket.class)
|
||||||
public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipmentPacket> {
|
public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipmentPacket> {
|
||||||
|
|
||||||
@ -53,6 +57,14 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipment
|
|||||||
ClientPlayerChangeHeldItemPacket changeHeldItemPacket = new ClientPlayerChangeHeldItemPacket(packet.getHotbarSlot());
|
ClientPlayerChangeHeldItemPacket changeHeldItemPacket = new ClientPlayerChangeHeldItemPacket(packet.getHotbarSlot());
|
||||||
session.sendDownstreamPacket(changeHeldItemPacket);
|
session.sendDownstreamPacket(changeHeldItemPacket);
|
||||||
|
|
||||||
|
if (session.isSneaking() && session.getPlayerInventory().getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
|
||||||
|
// Activate shield since we are already sneaking
|
||||||
|
// (No need to send a release item packet - Java doesn't do this when swapping items)
|
||||||
|
// Required to do it a tick later or else it doesn't register
|
||||||
|
session.getConnector().getGeneralThreadPool().schedule(() -> session.sendDownstreamPacket(new ClientPlayerUseItemPacket(Hand.MAIN_HAND)),
|
||||||
|
50, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
// Java sends a cooldown indicator whenever you switch an item
|
// Java sends a cooldown indicator whenever you switch an item
|
||||||
CooldownUtils.sendCooldown(session);
|
CooldownUtils.sendCooldown(session);
|
||||||
}
|
}
|
||||||
|
@ -28,15 +28,13 @@ package org.geysermc.connector.network.translators.bedrock.entity.player;
|
|||||||
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.player.*;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.*;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerAbilitiesPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.*;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
import com.nukkitx.protocol.bedrock.data.PlayerActionType;
|
import com.nukkitx.protocol.bedrock.data.PlayerActionType;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||||
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
|
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
|
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
|
||||||
@ -49,6 +47,7 @@ import org.geysermc.connector.network.session.GeyserSession;
|
|||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||||
|
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
import org.geysermc.connector.utils.BlockUtils;
|
import org.geysermc.connector.utils.BlockUtils;
|
||||||
|
|
||||||
@ -101,11 +100,37 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
case START_SNEAK:
|
case START_SNEAK:
|
||||||
ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
|
ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
|
||||||
session.sendDownstreamPacket(startSneakPacket);
|
session.sendDownstreamPacket(startSneakPacket);
|
||||||
|
|
||||||
|
// Toggle the shield, if relevant
|
||||||
|
PlayerInventory playerInv = session.getPlayerInventory();
|
||||||
|
if ((playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) ||
|
||||||
|
(playerInv.getOffhand().getJavaId() == ItemRegistry.SHIELD.getJavaId())) {
|
||||||
|
ClientPlayerUseItemPacket useItemPacket;
|
||||||
|
if (playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
|
||||||
|
useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
||||||
|
} else {
|
||||||
|
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent
|
||||||
|
useItemPacket = new ClientPlayerUseItemPacket(Hand.OFF_HAND);
|
||||||
|
}
|
||||||
|
session.sendDownstreamPacket(useItemPacket);
|
||||||
|
session.getPlayerEntity().getMetadata().getFlags().setFlag(EntityFlag.BLOCKING, true);
|
||||||
|
session.getPlayerEntity().updateBedrockMetadata(session);
|
||||||
|
}
|
||||||
|
|
||||||
session.setSneaking(true);
|
session.setSneaking(true);
|
||||||
break;
|
break;
|
||||||
case STOP_SNEAK:
|
case STOP_SNEAK:
|
||||||
ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SNEAKING);
|
ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SNEAKING);
|
||||||
session.sendDownstreamPacket(stopSneakPacket);
|
session.sendDownstreamPacket(stopSneakPacket);
|
||||||
|
|
||||||
|
// Stop shield, if necessary
|
||||||
|
if (session.getPlayerEntity().getMetadata().getFlags().getFlag(EntityFlag.BLOCKING)) {
|
||||||
|
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, BlockUtils.POSITION_ZERO, BlockFace.DOWN);
|
||||||
|
session.sendDownstreamPacket(releaseItemPacket);
|
||||||
|
session.getPlayerEntity().getMetadata().getFlags().setFlag(EntityFlag.BLOCKING, false);
|
||||||
|
session.getPlayerEntity().updateBedrockMetadata(session);
|
||||||
|
}
|
||||||
|
|
||||||
session.setSneaking(false);
|
session.setSneaking(false);
|
||||||
break;
|
break;
|
||||||
case START_SPRINT:
|
case START_SPRINT:
|
||||||
|
@ -26,17 +26,19 @@
|
|||||||
package org.geysermc.connector.utils;
|
package org.geysermc.connector.utils;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
|
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
|
||||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||||
import org.geysermc.connector.network.translators.item.ToolItemEntry;
|
import org.geysermc.connector.network.translators.item.ToolItemEntry;
|
||||||
|
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class BlockUtils {
|
public class BlockUtils {
|
||||||
|
/**
|
||||||
|
* A static constant of {@link Position} with all values being zero.
|
||||||
|
*/
|
||||||
|
public static final Position POSITION_ZERO = new Position(0, 0, 0);
|
||||||
|
|
||||||
private static boolean correctTool(String blockToolType, String itemToolType) {
|
private static boolean correctTool(String blockToolType, String itemToolType) {
|
||||||
return (blockToolType.equals("sword") && itemToolType.equals("sword")) ||
|
return (blockToolType.equals("sword") && itemToolType.equals("sword")) ||
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren