2021-05-03 01:47:11 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2021-05-03 01:47:11 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.session.cache;
|
2021-05-03 01:47:11 +00:00
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundUpdateTagsPacket;
|
2021-05-03 01:47:11 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.IntList;
|
|
|
|
import it.unimi.dsi.fastutil.ints.IntLists;
|
2022-07-10 03:02:19 +00:00
|
|
|
import org.geysermc.geyser.GeyserLogger;
|
2022-02-25 03:49:10 +00:00
|
|
|
import org.geysermc.geyser.inventory.GeyserItemStack;
|
2022-12-29 20:10:40 +00:00
|
|
|
import org.geysermc.geyser.item.type.Item;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.type.BlockMapping;
|
2022-02-11 01:14:52 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2021-05-03 01:47:11 +00:00
|
|
|
|
2022-02-25 03:49:10 +00:00
|
|
|
import javax.annotation.ParametersAreNonnullByDefault;
|
2021-05-03 01:47:11 +00:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
2021-11-13 03:44:15 +00:00
|
|
|
* Manages information sent from the {@link ClientboundUpdateTagsPacket}. If that packet is not sent, all lists here
|
2021-05-03 01:47:11 +00:00
|
|
|
* will remain empty, matching Java Edition behavior.
|
|
|
|
*/
|
2022-02-25 03:49:10 +00:00
|
|
|
@ParametersAreNonnullByDefault
|
2021-05-03 01:47:11 +00:00
|
|
|
public class TagCache {
|
|
|
|
/* Blocks */
|
2021-05-20 02:24:11 +00:00
|
|
|
private IntList leaves;
|
|
|
|
private IntList wool;
|
|
|
|
|
|
|
|
private IntList axeEffective;
|
|
|
|
private IntList hoeEffective;
|
|
|
|
private IntList pickaxeEffective;
|
|
|
|
private IntList shovelEffective;
|
|
|
|
|
2021-05-24 02:32:42 +00:00
|
|
|
private IntList requiresStoneTool;
|
|
|
|
private IntList requiresIronTool;
|
|
|
|
private IntList requiresDiamondTool;
|
|
|
|
|
2021-05-03 01:47:11 +00:00
|
|
|
/* Items */
|
2022-02-11 18:37:19 +00:00
|
|
|
private IntList axolotlTemptItems;
|
2022-12-31 00:38:47 +00:00
|
|
|
private IntList creeperIgniters;
|
2022-02-25 03:49:10 +00:00
|
|
|
private IntList fishes;
|
2021-05-20 02:24:11 +00:00
|
|
|
private IntList flowers;
|
|
|
|
private IntList foxFood;
|
|
|
|
private IntList piglinLoved;
|
2022-02-25 03:49:10 +00:00
|
|
|
private IntList smallFlowers;
|
2023-05-17 20:06:28 +00:00
|
|
|
private IntList snifferFood;
|
2021-05-20 02:24:11 +00:00
|
|
|
|
|
|
|
public TagCache() {
|
|
|
|
// Ensure all lists are non-null
|
|
|
|
clear();
|
|
|
|
}
|
2021-05-03 01:47:11 +00:00
|
|
|
|
2022-02-11 01:14:52 +00:00
|
|
|
public void loadPacket(GeyserSession session, ClientboundUpdateTagsPacket packet) {
|
2021-05-20 02:24:11 +00:00
|
|
|
Map<String, int[]> blockTags = packet.getTags().get("minecraft:block");
|
|
|
|
this.leaves = IntList.of(blockTags.get("minecraft:leaves"));
|
2021-05-03 01:47:11 +00:00
|
|
|
this.wool = IntList.of(blockTags.get("minecraft:wool"));
|
|
|
|
|
2021-05-20 02:24:11 +00:00
|
|
|
this.axeEffective = IntList.of(blockTags.get("minecraft:mineable/axe"));
|
|
|
|
this.hoeEffective = IntList.of(blockTags.get("minecraft:mineable/hoe"));
|
|
|
|
this.pickaxeEffective = IntList.of(blockTags.get("minecraft:mineable/pickaxe"));
|
|
|
|
this.shovelEffective = IntList.of(blockTags.get("minecraft:mineable/shovel"));
|
|
|
|
|
2021-05-24 02:32:42 +00:00
|
|
|
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"));
|
|
|
|
|
2022-07-10 03:02:19 +00:00
|
|
|
// Hack btw
|
|
|
|
GeyserLogger logger = session.getGeyser().getLogger();
|
|
|
|
int[] convertableToMud = blockTags.get("minecraft:convertable_to_mud");
|
|
|
|
boolean emulatePost1_18Logic = convertableToMud != null && convertableToMud.length != 0;
|
|
|
|
session.setEmulatePost1_18Logic(emulatePost1_18Logic);
|
|
|
|
if (logger.isDebug()) {
|
2022-08-09 18:06:53 +00:00
|
|
|
logger.debug("Emulating post 1.18 block predication logic for " + session.bedrockUsername() + "? " + emulatePost1_18Logic);
|
2022-07-10 03:02:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 02:24:11 +00:00
|
|
|
Map<String, int[]> itemTags = packet.getTags().get("minecraft:item");
|
2022-02-11 18:37:19 +00:00
|
|
|
this.axolotlTemptItems = IntList.of(itemTags.get("minecraft:axolotl_tempt_items"));
|
2022-12-31 00:38:47 +00:00
|
|
|
this.creeperIgniters = load(itemTags.get("minecraft:creeper_igniters"));
|
2022-02-25 03:49:10 +00:00
|
|
|
this.fishes = IntList.of(itemTags.get("minecraft:fishes"));
|
2021-05-03 01:47:11 +00:00
|
|
|
this.flowers = IntList.of(itemTags.get("minecraft:flowers"));
|
2021-05-20 02:24:11 +00:00
|
|
|
this.foxFood = IntList.of(itemTags.get("minecraft:fox_food"));
|
2021-05-03 01:47:11 +00:00
|
|
|
this.piglinLoved = IntList.of(itemTags.get("minecraft:piglin_loved"));
|
2022-02-25 03:49:10 +00:00
|
|
|
this.smallFlowers = IntList.of(itemTags.get("minecraft:small_flowers"));
|
2023-05-17 20:06:28 +00:00
|
|
|
this.snifferFood = IntList.of(itemTags.get("minecraft:sniffer_food"));
|
2022-02-11 01:14:52 +00:00
|
|
|
|
|
|
|
// Hack btw
|
2022-07-14 01:31:10 +00:00
|
|
|
boolean emulatePost1_13Logic = itemTags.get("minecraft:signs").length > 1;
|
|
|
|
session.setEmulatePost1_13Logic(emulatePost1_13Logic);
|
2022-07-10 03:02:19 +00:00
|
|
|
if (logger.isDebug()) {
|
2022-08-09 18:06:53 +00:00
|
|
|
logger.debug("Emulating post 1.13 villager logic for " + session.bedrockUsername() + "? " + emulatePost1_13Logic);
|
2022-02-11 01:14:52 +00:00
|
|
|
}
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-31 00:38:47 +00:00
|
|
|
private IntList load(int[] tags) {
|
|
|
|
if (tags == null) {
|
|
|
|
return IntLists.EMPTY_LIST;
|
|
|
|
}
|
|
|
|
return IntList.of(tags);
|
|
|
|
}
|
|
|
|
|
2021-05-03 01:47:11 +00:00
|
|
|
public void clear() {
|
2021-05-20 02:24:11 +00:00
|
|
|
this.leaves = IntLists.emptyList();
|
2021-05-03 01:47:11 +00:00
|
|
|
this.wool = IntLists.emptyList();
|
|
|
|
|
2021-05-20 02:24:11 +00:00
|
|
|
this.axeEffective = IntLists.emptyList();
|
|
|
|
this.hoeEffective = IntLists.emptyList();
|
|
|
|
this.pickaxeEffective = IntLists.emptyList();
|
|
|
|
this.shovelEffective = IntLists.emptyList();
|
|
|
|
|
2021-05-24 02:32:42 +00:00
|
|
|
this.requiresStoneTool = IntLists.emptyList();
|
|
|
|
this.requiresIronTool = IntLists.emptyList();
|
|
|
|
this.requiresDiamondTool = IntLists.emptyList();
|
|
|
|
|
2022-02-11 18:37:19 +00:00
|
|
|
this.axolotlTemptItems = IntLists.emptyList();
|
2022-12-31 00:38:47 +00:00
|
|
|
this.creeperIgniters = IntLists.emptyList();
|
2022-02-25 03:49:10 +00:00
|
|
|
this.fishes = IntLists.emptyList();
|
2021-05-03 01:47:11 +00:00
|
|
|
this.flowers = IntLists.emptyList();
|
2021-05-20 02:24:11 +00:00
|
|
|
this.foxFood = IntLists.emptyList();
|
2021-05-03 01:47:11 +00:00
|
|
|
this.piglinLoved = IntLists.emptyList();
|
2022-02-25 03:49:10 +00:00
|
|
|
this.smallFlowers = IntLists.emptyList();
|
2023-05-17 20:06:28 +00:00
|
|
|
this.snifferFood = IntLists.emptyList();
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 20:10:40 +00:00
|
|
|
public boolean isAxolotlTemptItem(Item item) {
|
|
|
|
return axolotlTemptItems.contains(item.javaId());
|
2022-02-11 18:37:19 +00:00
|
|
|
}
|
|
|
|
|
2022-12-31 00:38:47 +00:00
|
|
|
public boolean isCreeperIgniter(Item item) {
|
|
|
|
return creeperIgniters.contains(item.javaId());
|
|
|
|
}
|
|
|
|
|
2022-02-25 03:49:10 +00:00
|
|
|
public boolean isFish(GeyserItemStack itemStack) {
|
|
|
|
return fishes.contains(itemStack.getJavaId());
|
|
|
|
}
|
|
|
|
|
2022-12-29 20:10:40 +00:00
|
|
|
public boolean isFlower(Item item) {
|
|
|
|
return flowers.contains(item.javaId());
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 20:10:40 +00:00
|
|
|
public boolean isFoxFood(Item item) {
|
|
|
|
return foxFood.contains(item.javaId());
|
2021-05-20 02:24:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 20:10:40 +00:00
|
|
|
public boolean shouldPiglinAdmire(Item item) {
|
|
|
|
return piglinLoved.contains(item.javaId());
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 03:49:10 +00:00
|
|
|
public boolean isSmallFlower(GeyserItemStack itemStack) {
|
|
|
|
return smallFlowers.contains(itemStack.getJavaId());
|
|
|
|
}
|
|
|
|
|
2023-05-17 20:06:28 +00:00
|
|
|
public boolean isSnifferFood(Item item) {
|
|
|
|
return snifferFood.contains(item.javaId());
|
|
|
|
}
|
|
|
|
|
2021-05-20 02:24:11 +00:00
|
|
|
public boolean isAxeEffective(BlockMapping blockMapping) {
|
|
|
|
return axeEffective.contains(blockMapping.getJavaBlockId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isHoeEffective(BlockMapping blockMapping) {
|
|
|
|
return hoeEffective.contains(blockMapping.getJavaBlockId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPickaxeEffective(BlockMapping blockMapping) {
|
|
|
|
return pickaxeEffective.contains(blockMapping.getJavaBlockId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShovelEffective(BlockMapping blockMapping) {
|
|
|
|
return shovelEffective.contains(blockMapping.getJavaBlockId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShearsEffective(BlockMapping blockMapping) {
|
|
|
|
int javaBlockId = blockMapping.getJavaBlockId();
|
|
|
|
return leaves.contains(javaBlockId) || wool.contains(javaBlockId);
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|
2021-05-24 02:32:42 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|