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:
Camotoy 2020-10-08 18:44:15 -04:00 committed by GitHub
parent 16eb2a491a
commit 4514167835
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 31 deletions

View file

@ -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.item.ItemRegistry;
import org.geysermc.connector.network.translators.sound.EntitySoundInteractionHandler; import org.geysermc.connector.network.translators.sound.EntitySoundInteractionHandler;
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.InventoryUtils; import org.geysermc.connector.utils.InventoryUtils;
@Translator(packet = InventoryTransactionPacket.class) @Translator(packet = InventoryTransactionPacket.class)
@ -151,28 +152,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
} }
} }
Vector3i blockPos = packet.getBlockPosition(); Vector3i blockPos = BlockUtils.getBlockPosition(packet.getBlockPosition(), packet.getBlockFace());
// 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;
}
ItemEntry handItem = ItemRegistry.getItem(packet.getItemInHand()); ItemEntry handItem = ItemRegistry.getItem(packet.getItemInHand());
if (handItem.isBlock()) { if (handItem.isBlock()) {
session.setLastBlockPlacePosition(blockPos); session.setLastBlockPlacePosition(blockPos);

View file

@ -44,6 +44,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.world.block.BlockTranslator; import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.utils.BlockUtils;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -117,15 +118,15 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
break; break;
case START_BREAK: case START_BREAK:
if (session.getConnector().getConfig().isCacheChunks()) { if (session.getConnector().getConfig().isCacheChunks()) {
if (packet.getFace() == BlockFace.UP.ordinal()) { // Account for fire - the client likes to hit the block behind.
int blockUp = session.getConnector().getWorldManager().getBlockAt(session, packet.getBlockPosition().add(0, 1, 0)); Vector3i fireBlockPos = BlockUtils.getBlockPosition(packet.getBlockPosition(), packet.getFace());
String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(blockUp); int blockUp = session.getConnector().getWorldManager().getBlockAt(session, fireBlockPos);
if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) { String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(blockUp);
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(), if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) {
packet.getBlockPosition().getY() + 1, packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]); ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(fireBlockPos.getX(),
session.sendDownstreamPacket(startBreakingPacket); fireBlockPos.getY(), fireBlockPos.getZ()), BlockFace.values()[packet.getFace()]);
break; session.sendDownstreamPacket(startBreakingPacket);
} break;
} }
} }
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(), ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),

View file

@ -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.Effect;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; 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.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator; 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;
@ -138,4 +139,28 @@ public class BlockUtils {
return calculateBreakTime(blockHardness, toolTier, canHarvestWithHand, correctTool, toolType, isWoolBlock, isCobweb, toolEfficiencyLevel, hasteLevel, miningFatigueLevel, insideOfWaterWithoutAquaAffinity, outOfWaterButNotOnGround, insideWaterNotOnGround); 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;
}
} }