Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 22:40:18 +01:00
Fix block break speeds thanks to @Camotoy
Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
Dieser Commit ist enthalten in:
Ursprung
48c6f9446d
Commit
29835a1b76
@ -313,9 +313,8 @@ public class MappingsReader_v1 extends MappingsReader {
|
|||||||
builder.collisionBox(collisionBox);
|
builder.collisionBox(collisionBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ideally we would just be able to calculate the right value for this, but it seems that hardness value on bedrock does not follow Java
|
// We set this to max value by default so that we may dictate the correct destroy time ourselves
|
||||||
// As such this might as well just be configured for now if people so choose
|
float destructibleByMining = Float.MAX_VALUE;
|
||||||
float destructibleByMining = BlockRegistries.JAVA_BLOCKS.getOrDefault(id, BlockMapping.AIR).getHardness() * 3.25F;
|
|
||||||
if (node.has("destructible_by_mining")) {
|
if (node.has("destructible_by_mining")) {
|
||||||
destructibleByMining = node.get("destructible_by_mining").floatValue();
|
destructibleByMining = node.get("destructible_by_mining").floatValue();
|
||||||
}
|
}
|
||||||
|
@ -437,6 +437,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||||||
@Setter
|
@Setter
|
||||||
private long lastInteractionTime;
|
private long lastInteractionTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores when the player started to break a block. Used to allow correct break time for custom blocks.
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
private long blockBreakStartTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores whether the player intended to place a bucket.
|
* Stores whether the player intended to place a bucket.
|
||||||
*/
|
*/
|
||||||
|
@ -38,6 +38,7 @@ 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.data.entity.EntityFlag;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
|
import org.geysermc.geyser.api.block.custom.CustomBlockState;
|
||||||
import org.geysermc.geyser.entity.type.Entity;
|
import org.geysermc.geyser.entity.type.Entity;
|
||||||
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
||||||
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
||||||
@ -147,6 +148,11 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
startBreak.setType(LevelEventType.BLOCK_START_BREAK);
|
startBreak.setType(LevelEventType.BLOCK_START_BREAK);
|
||||||
startBreak.setPosition(vector.toFloat());
|
startBreak.setPosition(vector.toFloat());
|
||||||
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(blockState)) * 20;
|
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(blockState)) * 20;
|
||||||
|
CustomBlockState blockStateOverride = BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get(blockState);
|
||||||
|
// If the block is custom, we must keep track of when it should break ourselves
|
||||||
|
if (blockStateOverride != null) {
|
||||||
|
session.setBlockBreakStartTime(System.currentTimeMillis());
|
||||||
|
}
|
||||||
startBreak.setData((int) (65535 / breakTime));
|
startBreak.setData((int) (65535 / breakTime));
|
||||||
session.setBreakingBlock(blockState);
|
session.setBreakingBlock(blockState);
|
||||||
session.sendUpstreamPacket(startBreak);
|
session.sendUpstreamPacket(startBreak);
|
||||||
@ -190,6 +196,31 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
updateBreak.setType(LevelEventType.BLOCK_UPDATE_BREAK);
|
updateBreak.setType(LevelEventType.BLOCK_UPDATE_BREAK);
|
||||||
updateBreak.setPosition(vectorFloat);
|
updateBreak.setPosition(vectorFloat);
|
||||||
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(breakingBlock)) * 20;
|
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(breakingBlock)) * 20;
|
||||||
|
|
||||||
|
CustomBlockState blockStateOverride = BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get(breakingBlock);
|
||||||
|
if (blockStateOverride != null) {
|
||||||
|
// If the block is custom, we must keep track of when it should break ourselves
|
||||||
|
long blockBreakStartTime = session.getBlockBreakStartTime();
|
||||||
|
if (blockBreakStartTime != 0) {
|
||||||
|
long timeSinceStart = System.currentTimeMillis() - blockBreakStartTime;
|
||||||
|
if (timeSinceStart >= breakTime * 50) {
|
||||||
|
// Play break sound and particle
|
||||||
|
LevelEventPacket effectPacket = new LevelEventPacket();
|
||||||
|
effectPacket.setPosition(vectorFloat);
|
||||||
|
effectPacket.setType(LevelEventType.PARTICLE_DESTROY_BLOCK);
|
||||||
|
effectPacket.setData(session.getBlockMappings().getBedrockBlockId(breakingBlock));
|
||||||
|
session.sendUpstreamPacket(effectPacket);
|
||||||
|
|
||||||
|
// Break the block
|
||||||
|
ServerboundPlayerActionPacket finishBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.FINISH_DIGGING,
|
||||||
|
vector, Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());
|
||||||
|
session.sendDownstreamPacket(finishBreakingPacket);
|
||||||
|
session.setBlockBreakStartTime(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateBreak.setData((int) (65535 / breakTime));
|
updateBreak.setData((int) (65535 / breakTime));
|
||||||
session.sendUpstreamPacket(updateBreak);
|
session.sendUpstreamPacket(updateBreak);
|
||||||
break;
|
break;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren