3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

Respect tool tier requirement for block breaking (#1837)

Dieser Commit ist enthalten in:
Camotoy 2021-05-23 22:32:42 -04:00
Ursprung 986701f06f
Commit 1f83a5ac9f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
3 geänderte Dateien mit 58 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -305,6 +305,7 @@
</replacement> </replacement>
<replacement> <replacement>
<token>String GIT_VERSION = ".*"</token> <token>String GIT_VERSION = ".*"</token>
<!--suppress UnresolvedMavenProperty -->
<value>String GIT_VERSION = "git-${git.branch}-${git.commit.id.abbrev}"</value> <value>String GIT_VERSION = "git-${git.branch}-${git.commit.id.abbrev}"</value>
</replacement> </replacement>
</replacements> </replacements>

Datei anzeigen

@ -47,6 +47,10 @@ public class TagCache {
private IntList pickaxeEffective; private IntList pickaxeEffective;
private IntList shovelEffective; private IntList shovelEffective;
private IntList requiresStoneTool;
private IntList requiresIronTool;
private IntList requiresDiamondTool;
/* Items */ /* Items */
private IntList flowers; private IntList flowers;
private IntList foxFood; private IntList foxFood;
@ -67,6 +71,10 @@ public class TagCache {
this.pickaxeEffective = IntList.of(blockTags.get("minecraft:mineable/pickaxe")); this.pickaxeEffective = IntList.of(blockTags.get("minecraft:mineable/pickaxe"));
this.shovelEffective = IntList.of(blockTags.get("minecraft:mineable/shovel")); this.shovelEffective = IntList.of(blockTags.get("minecraft:mineable/shovel"));
this.requiresStoneTool = IntList.of(blockTags.get("minecraft:needs_stone_tool"));
this.requiresIronTool = IntList.of(blockTags.get("minecraft:needs_iron_tool"));
this.requiresDiamondTool = IntList.of(blockTags.get("minecraft:needs_diamond_tool"));
Map<String, int[]> itemTags = packet.getTags().get("minecraft:item"); Map<String, int[]> itemTags = packet.getTags().get("minecraft:item");
this.flowers = IntList.of(itemTags.get("minecraft:flowers")); this.flowers = IntList.of(itemTags.get("minecraft:flowers"));
this.foxFood = IntList.of(itemTags.get("minecraft:fox_food")); this.foxFood = IntList.of(itemTags.get("minecraft:fox_food"));
@ -82,6 +90,10 @@ public class TagCache {
this.pickaxeEffective = IntLists.emptyList(); this.pickaxeEffective = IntLists.emptyList();
this.shovelEffective = IntLists.emptyList(); this.shovelEffective = IntLists.emptyList();
this.requiresStoneTool = IntLists.emptyList();
this.requiresIronTool = IntLists.emptyList();
this.requiresDiamondTool = IntLists.emptyList();
this.flowers = IntLists.emptyList(); this.flowers = IntLists.emptyList();
this.foxFood = IntLists.emptyList(); this.foxFood = IntLists.emptyList();
this.piglinLoved = IntLists.emptyList(); this.piglinLoved = IntLists.emptyList();
@ -119,4 +131,16 @@ public class TagCache {
int javaBlockId = blockMapping.getJavaBlockId(); int javaBlockId = blockMapping.getJavaBlockId();
return leaves.contains(javaBlockId) || wool.contains(javaBlockId); return leaves.contains(javaBlockId) || wool.contains(javaBlockId);
} }
public boolean requiresStoneTool(BlockMapping blockMapping) {
return requiresStoneTool.contains(blockMapping.getJavaBlockId());
}
public boolean requiresIronTool(BlockMapping blockMapping) {
return requiresIronTool.contains(blockMapping.getJavaBlockId());
}
public boolean requiresDiamondTool(BlockMapping blockMapping) {
return requiresDiamondTool.contains(blockMapping.getJavaBlockId());
}
} }

Datei anzeigen

@ -83,11 +83,36 @@ public class BlockUtils {
} }
} }
//http://minecraft.gamepedia.com/Breaking private static boolean canToolTierBreakBlock(GeyserSession session, BlockMapping blockMapping, String toolTier) {
private static double calculateBreakTime(double blockHardness, String toolTier, boolean canHarvestWithHand, boolean correctTool, if (toolTier.equals("netherite") || toolTier.equals("diamond")) {
// As of 1.17, these tiers can mine everything that is mineable
return true;
}
switch (toolTier) {
// Use intentional fall-throughs to check each tier with this block
default:
if (session.getTagCache().requiresStoneTool(blockMapping)) {
return false;
}
case "stone":
if (session.getTagCache().requiresIronTool(blockMapping)) {
return false;
}
case "iron":
if (session.getTagCache().requiresDiamondTool(blockMapping)) {
return false;
}
}
return true;
}
// https://minecraft.gamepedia.com/Breaking
private static double calculateBreakTime(double blockHardness, String toolTier, boolean canHarvestWithHand, boolean correctTool, boolean canTierMineBlock,
String toolType, boolean isShearsEffective, int toolEfficiencyLevel, int hasteLevel, int miningFatigueLevel, String toolType, boolean isShearsEffective, int toolEfficiencyLevel, int hasteLevel, int miningFatigueLevel,
boolean insideOfWaterWithoutAquaAffinity, boolean outOfWaterButNotOnGround, boolean insideWaterAndNotOnGround) { boolean insideOfWaterWithoutAquaAffinity, boolean outOfWaterButNotOnGround, boolean insideWaterAndNotOnGround) {
double baseTime = ((correctTool || canHarvestWithHand) ? 1.5 : 5.0) * blockHardness; double baseTime = (((correctTool && canTierMineBlock) || canHarvestWithHand) ? 1.5 : 5.0) * blockHardness;
double speed = 1.0 / baseTime; double speed = 1.0 / baseTime;
if (correctTool) { if (correctTool) {
@ -125,11 +150,13 @@ public class BlockUtils {
String toolType = ""; String toolType = "";
String toolTier = ""; String toolTier = "";
boolean correctTool = false; boolean correctTool = false;
boolean toolCanBreak = false;
if (item instanceof ToolItemEntry) { if (item instanceof ToolItemEntry) {
ToolItemEntry toolItem = (ToolItemEntry) item; ToolItemEntry toolItem = (ToolItemEntry) item;
toolType = toolItem.getToolType(); toolType = toolItem.getToolType();
toolTier = toolItem.getToolTier(); toolTier = toolItem.getToolTier();
correctTool = correctTool(session, blockMapping, toolType); correctTool = correctTool(session, blockMapping, toolType);
toolCanBreak = canToolTierBreakBlock(session, blockMapping, toolTier);
} }
int toolEfficiencyLevel = ItemUtils.getEnchantmentLevel(nbtData, "minecraft:efficiency"); int toolEfficiencyLevel = ItemUtils.getEnchantmentLevel(nbtData, "minecraft:efficiency");
int hasteLevel = 0; int hasteLevel = 0;
@ -137,12 +164,12 @@ public class BlockUtils {
if (!isSessionPlayer) { if (!isSessionPlayer) {
// Another entity is currently mining; we have all the information we know // Another entity is currently mining; we have all the information we know
return calculateBreakTime(blockMapping.getHardness(), toolTier, canHarvestWithHand, correctTool, toolType, isShearsEffective, return calculateBreakTime(blockMapping.getHardness(), toolTier, canHarvestWithHand, correctTool, toolCanBreak, toolType, isShearsEffective,
toolEfficiencyLevel, hasteLevel, miningFatigueLevel, false, toolEfficiencyLevel, hasteLevel, miningFatigueLevel, false,
false, false); false, false);
} }
hasteLevel = session.getEffectCache().getEffectLevel(Effect.FASTER_DIG); hasteLevel = Math.max(session.getEffectCache().getEffectLevel(Effect.FASTER_DIG), session.getEffectCache().getEffectLevel(Effect.CONDUIT_POWER));
miningFatigueLevel = session.getEffectCache().getEffectLevel(Effect.SLOWER_DIG); miningFatigueLevel = session.getEffectCache().getEffectLevel(Effect.SLOWER_DIG);
boolean isInWater = session.getCollisionManager().isPlayerInWater(); boolean isInWater = session.getCollisionManager().isPlayerInWater();
@ -152,7 +179,7 @@ public class BlockUtils {
boolean outOfWaterButNotOnGround = (!isInWater) && (!session.getPlayerEntity().isOnGround()); boolean outOfWaterButNotOnGround = (!isInWater) && (!session.getPlayerEntity().isOnGround());
boolean insideWaterNotOnGround = isInWater && !session.getPlayerEntity().isOnGround(); boolean insideWaterNotOnGround = isInWater && !session.getPlayerEntity().isOnGround();
return calculateBreakTime(blockMapping.getHardness(), toolTier, canHarvestWithHand, correctTool, toolType, isShearsEffective, return calculateBreakTime(blockMapping.getHardness(), toolTier, canHarvestWithHand, correctTool, toolCanBreak, toolType, isShearsEffective,
toolEfficiencyLevel, hasteLevel, miningFatigueLevel, insideOfWaterWithoutAquaAffinity, toolEfficiencyLevel, hasteLevel, miningFatigueLevel, insideOfWaterWithoutAquaAffinity,
outOfWaterButNotOnGround, insideWaterNotOnGround); outOfWaterButNotOnGround, insideWaterNotOnGround);
} }