Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-08 17:20:20 +01:00
Fix breaking animation while jumping (#2335)
* Update block break time after a CONTINUE_BREAK action * Fix breaking animation time for some blocks * Reuse Vector3f and add comment Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com>
Dieser Commit ist enthalten in:
Ursprung
1cc9c78305
Commit
566394f798
@ -29,7 +29,7 @@ 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.*;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.*;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
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;
|
||||||
@ -41,12 +41,10 @@ import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
|
|||||||
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
|
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.entity.ItemFrameEntity;
|
import org.geysermc.connector.entity.ItemFrameEntity;
|
||||||
import org.geysermc.connector.inventory.GeyserItemStack;
|
|
||||||
import org.geysermc.connector.inventory.PlayerInventory;
|
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.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.ItemRegistry;
|
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;
|
||||||
@ -166,18 +164,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
LevelEventPacket startBreak = new LevelEventPacket();
|
LevelEventPacket startBreak = new LevelEventPacket();
|
||||||
startBreak.setType(LevelEventType.BLOCK_START_BREAK);
|
startBreak.setType(LevelEventType.BLOCK_START_BREAK);
|
||||||
startBreak.setPosition(vector.toFloat());
|
startBreak.setPosition(vector.toFloat());
|
||||||
PlayerInventory inventory = session.getPlayerInventory();
|
double breakTime = BlockUtils.getSessionBreakTime(session, BlockTranslator.getBlockMapping(blockState)) * 20;
|
||||||
GeyserItemStack item = inventory.getItemInHand();
|
|
||||||
ItemEntry itemEntry;
|
|
||||||
CompoundTag nbtData;
|
|
||||||
if (item != null) {
|
|
||||||
itemEntry = item.getItemEntry();
|
|
||||||
nbtData = item.getNbt();
|
|
||||||
} else {
|
|
||||||
itemEntry = null;
|
|
||||||
nbtData = new CompoundTag("");
|
|
||||||
}
|
|
||||||
double breakTime = Math.ceil(BlockUtils.getBreakTime(session, BlockTranslator.getBlockMapping(blockState), itemEntry, nbtData, true) * 20);
|
|
||||||
startBreak.setData((int) (65535 / breakTime));
|
startBreak.setData((int) (65535 / breakTime));
|
||||||
session.setBreakingBlock(blockState);
|
session.setBreakingBlock(blockState);
|
||||||
session.sendUpstreamPacket(startBreak);
|
session.sendUpstreamPacket(startBreak);
|
||||||
@ -203,11 +190,20 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
if (session.getGameMode() == GameMode.CREATIVE) {
|
if (session.getGameMode() == GameMode.CREATIVE) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Vector3f vectorFloat = vector.toFloat();
|
||||||
LevelEventPacket continueBreakPacket = new LevelEventPacket();
|
LevelEventPacket continueBreakPacket = new LevelEventPacket();
|
||||||
continueBreakPacket.setType(LevelEventType.PARTICLE_CRACK_BLOCK);
|
continueBreakPacket.setType(LevelEventType.PARTICLE_CRACK_BLOCK);
|
||||||
continueBreakPacket.setData((session.getBlockTranslator().getBedrockBlockId(session.getBreakingBlock())) | (packet.getFace() << 24));
|
continueBreakPacket.setData((session.getBlockTranslator().getBedrockBlockId(session.getBreakingBlock())) | (packet.getFace() << 24));
|
||||||
continueBreakPacket.setPosition(vector.toFloat());
|
continueBreakPacket.setPosition(vectorFloat);
|
||||||
session.sendUpstreamPacket(continueBreakPacket);
|
session.sendUpstreamPacket(continueBreakPacket);
|
||||||
|
|
||||||
|
// Update the break time in the event that player conditions changed (jumping, effects applied)
|
||||||
|
LevelEventPacket updateBreak = new LevelEventPacket();
|
||||||
|
updateBreak.setType(LevelEventType.BLOCK_UPDATE_BREAK);
|
||||||
|
updateBreak.setPosition(vectorFloat);
|
||||||
|
double breakTime = BlockUtils.getSessionBreakTime(session, BlockTranslator.getBlockMapping(session.getBreakingBlock())) * 20;
|
||||||
|
updateBreak.setData((int) (65535 / breakTime));
|
||||||
|
session.sendUpstreamPacket(updateBreak);
|
||||||
break;
|
break;
|
||||||
case ABORT_BREAK:
|
case ABORT_BREAK:
|
||||||
if (session.getGameMode() != GameMode.CREATIVE) {
|
if (session.getGameMode() != GameMode.CREATIVE) {
|
||||||
@ -243,7 +239,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
session.getEntityCache().updateBossBars();
|
session.getEntityCache().updateBossBars();
|
||||||
break;
|
break;
|
||||||
case JUMP:
|
case JUMP:
|
||||||
// Leaving as a potential placeholder for an event or soul sand fixing
|
entity.setOnGround(false); // Increase block break time while jumping
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.Effect;
|
|||||||
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.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.inventory.GeyserItemStack;
|
||||||
|
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.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;
|
||||||
@ -184,6 +186,21 @@ public class BlockUtils {
|
|||||||
outOfWaterButNotOnGround, insideWaterNotOnGround);
|
outOfWaterButNotOnGround, insideWaterNotOnGround);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double getSessionBreakTime(GeyserSession session, BlockMapping blockMapping) {
|
||||||
|
PlayerInventory inventory = session.getPlayerInventory();
|
||||||
|
GeyserItemStack item = inventory.getItemInHand();
|
||||||
|
ItemEntry itemEntry;
|
||||||
|
CompoundTag nbtData;
|
||||||
|
if (item != null) {
|
||||||
|
itemEntry = item.getItemEntry();
|
||||||
|
nbtData = item.getNbt();
|
||||||
|
} else {
|
||||||
|
itemEntry = null;
|
||||||
|
nbtData = new CompoundTag("");
|
||||||
|
}
|
||||||
|
return getBreakTime(session, blockMapping, itemEntry, nbtData, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a position, return the position if a block were located on the specified block face.
|
* Given a position, return the position if a block were located on the specified block face.
|
||||||
* @param blockPos the block position
|
* @param blockPos the block position
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren