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;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.type.BlockMapping;
|
|
|
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
2022-02-11 01:14:52 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
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.
|
|
|
|
*/
|
|
|
|
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 */
|
2021-05-20 02:24:11 +00:00
|
|
|
private IntList flowers;
|
|
|
|
private IntList foxFood;
|
|
|
|
private IntList piglinLoved;
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
2021-05-20 02:24:11 +00:00
|
|
|
Map<String, int[]> itemTags = packet.getTags().get("minecraft:item");
|
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-11 01:14:52 +00:00
|
|
|
|
|
|
|
// Hack btw
|
|
|
|
boolean emulatePost1_14Logic = itemTags.get("minecraft:signs").length > 1;
|
|
|
|
session.setEmulatePost1_14Logic(emulatePost1_14Logic);
|
|
|
|
if (session.getGeyser().getLogger().isDebug()) {
|
|
|
|
session.getGeyser().getLogger().debug("Emulating post 1.14 villager logic for " + session.name() + "? " + emulatePost1_14Logic);
|
|
|
|
}
|
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();
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
public boolean isFlower(ItemMapping mapping) {
|
|
|
|
return flowers.contains(mapping.getJavaId());
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
public boolean isFoxFood(ItemMapping mapping) {
|
|
|
|
return foxFood.contains(mapping.getJavaId());
|
2021-05-20 02:24:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
public boolean shouldPiglinAdmire(ItemMapping mapping) {
|
|
|
|
return piglinLoved.contains(mapping.getJavaId());
|
2021-05-03 01:47:11 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|