62 lines
2.4 KiB
Java
62 lines
2.4 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
import java.util.Optional;
|
|
import net.minecraft.world.item.crafting.RecipeManager;
|
|
import java.util.List;
|
|
import net.minecraft.nbt.ListTag;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.stats.Stat;
|
|
import net.minecraft.stats.Stats;
|
|
import java.util.Collection;
|
|
import net.minecraft.world.item.crafting.Recipe;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import com.google.common.collect.Lists;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.Level;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
public class KnowledgeBookItem extends Item {
|
|
private static final Logger LOGGER;
|
|
|
|
public KnowledgeBookItem(final Properties a) {
|
|
super(a);
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
|
|
final ItemStack bek5 = ayg.getItemInHand(ajh);
|
|
final CompoundTag jt6 = bek5.getTag();
|
|
if (!ayg.abilities.instabuild) {
|
|
ayg.setItemInHand(ajh, ItemStack.EMPTY);
|
|
}
|
|
if (jt6 == null || !jt6.contains("Recipes", 9)) {
|
|
KnowledgeBookItem.LOGGER.error("Tag not valid: {}", jt6);
|
|
return InteractionResultHolder.<ItemStack>fail(bek5);
|
|
}
|
|
if (!bjt.isClientSide) {
|
|
final ListTag jz7 = jt6.getList("Recipes", 8);
|
|
final List<Recipe<?>> list8 = Lists.newArrayList();
|
|
final RecipeManager bgu9 = bjt.getServer().getRecipeManager();
|
|
for (int integer10 = 0; integer10 < jz7.size(); ++integer10) {
|
|
final String string11 = jz7.getString(integer10);
|
|
final Optional<? extends Recipe<?>> optional12 = bgu9.byKey(new ResourceLocation(string11));
|
|
if (!optional12.isPresent()) {
|
|
KnowledgeBookItem.LOGGER.error("Invalid recipe: {}", string11);
|
|
return InteractionResultHolder.<ItemStack>fail(bek5);
|
|
}
|
|
list8.add(optional12.get());
|
|
}
|
|
ayg.awardRecipes(list8);
|
|
ayg.awardStat(Stats.ITEM_USED.get(this));
|
|
}
|
|
return InteractionResultHolder.<ItemStack>success(bek5);
|
|
}
|
|
|
|
static {
|
|
LOGGER = LogManager.getLogger();
|
|
}
|
|
}
|