mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-11-23 23:38:41 +01:00
Fix fire being punched in all directions (#1370)
Apply the fix we have for fire but for all block faces.
This commit is contained in:
parent
16eb2a491a
commit
4514167835
3 changed files with 37 additions and 31 deletions
|
@ -58,6 +58,7 @@ import org.geysermc.connector.network.translators.item.ItemEntry;
|
|||
import org.geysermc.connector.network.translators.item.ItemRegistry;
|
||||
import org.geysermc.connector.network.translators.sound.EntitySoundInteractionHandler;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||
import org.geysermc.connector.utils.BlockUtils;
|
||||
import org.geysermc.connector.utils.InventoryUtils;
|
||||
|
||||
@Translator(packet = InventoryTransactionPacket.class)
|
||||
|
@ -151,28 +152,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
|||
}
|
||||
}
|
||||
|
||||
Vector3i blockPos = packet.getBlockPosition();
|
||||
// TODO: Find a better way to do this?
|
||||
switch (packet.getBlockFace()) {
|
||||
case 0:
|
||||
blockPos = blockPos.sub(0, 1, 0);
|
||||
break;
|
||||
case 1:
|
||||
blockPos = blockPos.add(0, 1, 0);
|
||||
break;
|
||||
case 2:
|
||||
blockPos = blockPos.sub(0, 0, 1);
|
||||
break;
|
||||
case 3:
|
||||
blockPos = blockPos.add(0, 0, 1);
|
||||
break;
|
||||
case 4:
|
||||
blockPos = blockPos.sub(1, 0, 0);
|
||||
break;
|
||||
case 5:
|
||||
blockPos = blockPos.add(1, 0, 0);
|
||||
break;
|
||||
}
|
||||
Vector3i blockPos = BlockUtils.getBlockPosition(packet.getBlockPosition(), packet.getBlockFace());
|
||||
ItemEntry handItem = ItemRegistry.getItem(packet.getItemInHand());
|
||||
if (handItem.isBlock()) {
|
||||
session.setLastBlockPlacePosition(blockPos);
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.geysermc.connector.network.session.GeyserSession;
|
|||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.Translator;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||
import org.geysermc.connector.utils.BlockUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -117,17 +118,17 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||
break;
|
||||
case START_BREAK:
|
||||
if (session.getConnector().getConfig().isCacheChunks()) {
|
||||
if (packet.getFace() == BlockFace.UP.ordinal()) {
|
||||
int blockUp = session.getConnector().getWorldManager().getBlockAt(session, packet.getBlockPosition().add(0, 1, 0));
|
||||
// Account for fire - the client likes to hit the block behind.
|
||||
Vector3i fireBlockPos = BlockUtils.getBlockPosition(packet.getBlockPosition(), packet.getFace());
|
||||
int blockUp = session.getConnector().getWorldManager().getBlockAt(session, fireBlockPos);
|
||||
String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(blockUp);
|
||||
if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) {
|
||||
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),
|
||||
packet.getBlockPosition().getY() + 1, packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
|
||||
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(fireBlockPos.getX(),
|
||||
fireBlockPos.getY(), fireBlockPos.getZ()), BlockFace.values()[packet.getFace()]);
|
||||
session.sendDownstreamPacket(startBreakingPacket);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),
|
||||
packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
|
||||
session.sendDownstreamPacket(startBreakingPacket);
|
||||
|
|
|
@ -28,6 +28,7 @@ package org.geysermc.connector.utils;
|
|||
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.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||
import org.geysermc.connector.network.translators.item.ItemEntry;
|
||||
|
@ -138,4 +139,28 @@ public class BlockUtils {
|
|||
return calculateBreakTime(blockHardness, toolTier, canHarvestWithHand, correctTool, toolType, isWoolBlock, isCobweb, toolEfficiencyLevel, hasteLevel, miningFatigueLevel, insideOfWaterWithoutAquaAffinity, outOfWaterButNotOnGround, insideWaterNotOnGround);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a position, return the position if a block were located on the specified block face.
|
||||
* @param blockPos the block position
|
||||
* @param face the face of the block - see {@link com.github.steveice10.mc.protocol.data.game.world.block.BlockFace}
|
||||
* @return the block position with the block face accounted for
|
||||
*/
|
||||
public static Vector3i getBlockPosition(Vector3i blockPos, int face) {
|
||||
switch (face) {
|
||||
case 0:
|
||||
return blockPos.sub(0, 1, 0);
|
||||
case 1:
|
||||
return blockPos.add(0, 1, 0);
|
||||
case 2:
|
||||
return blockPos.sub(0, 0, 1);
|
||||
case 3:
|
||||
return blockPos.add(0, 0, 1);
|
||||
case 4:
|
||||
return blockPos.sub(1, 0, 0);
|
||||
case 5:
|
||||
return blockPos.add(1, 0, 0);
|
||||
}
|
||||
return blockPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue