add creative unlocker

This commit is contained in:
gamma-delta 2022-05-25 17:13:19 -05:00
parent 02c7b1c421
commit 18383927d7
7 changed files with 117 additions and 6 deletions

View file

@ -207,6 +207,7 @@ df940dd798240fac6fde700c57f8ae6aa43d1c9e assets/hexcasting/models/item/artifact.
1a66f279c030ebd5ed6a596f63205094b2529819 assets/hexcasting/models/item/artifact_filled.json
1b3a4bd9dd3c2af2894e0acc1d9d3c74d16c7625 assets/hexcasting/models/item/battery.json
dc72e3345c4375b37f3624040c9a8df435c958d1 assets/hexcasting/models/item/charged_amethyst.json
1dd6767c74cd7ce5fed8e66476af1358db3cf7ce assets/hexcasting/models/item/creative_unlocker.json
b9916a82d647db5d3c505de2eb5f0a528169e1db assets/hexcasting/models/item/cypher.json
5082df8eee8f56f8c0d74db71ccda37a165bc76f assets/hexcasting/models/item/cypher_filled.json
81c0a8098b595f9704e3b7b65f240bdd48457289 assets/hexcasting/models/item/directrix_redstone.json

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "hexcasting:item/creative_unlocker"
}
}

View file

@ -0,0 +1,95 @@
package at.petrak.hexcasting.common.items.magic;
import at.petrak.hexcasting.api.item.ManaHolderItem;
import net.minecraft.advancements.Advancement;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
public ItemCreativeUnlocker(Properties properties) {
super(properties);
}
@Override
public int getMana(ItemStack stack) {
return Integer.MAX_VALUE;
}
@Override
public int getMaxMana(ItemStack stack) {
return Integer.MAX_VALUE;
}
@Override
public void setMana(ItemStack stack, int mana) {
}
@Override
public boolean manaProvider(ItemStack stack) {
return true;
}
@Override
public boolean canRecharge(ItemStack stack) {
return true;
}
@Override
public int withdrawMana(ItemStack stack, int cost, boolean simulate) {
return cost < 0 ? 1 : cost;
}
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
if (level instanceof ServerLevel slevel) {
var rootAdv = slevel.getServer().getAdvancements().getAdvancement(modLoc("root"));
if (rootAdv != null) {
var children = new ArrayList<Advancement>();
children.add(rootAdv);
addChildren(rootAdv, children);
var adman = ((ServerPlayer) player).getAdvancements();
for (var kid : children) {
var progress = adman.getOrStartProgress(kid);
if (!progress.isDone()) {
for (String crit : progress.getRemainingCriteria()) {
adman.award(kid, crit);
}
}
}
}
}
return InteractionResultHolder.success(player.getItemInHand(usedHand));
}
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents,
TooltipFlag isAdvanced) {
tooltipComponents.add(new TranslatableComponent("item.hexcasting.creative_unlocker.tooltip.0"));
tooltipComponents.add(new TranslatableComponent("item.hexcasting.creative_unlocker.tooltip.1"));
}
private static void addChildren(Advancement root, List<Advancement> out) {
for (Advancement kiddo : root.getChildren()) {
out.add(kiddo);
addChildren(kiddo, out);
}
}
}

View file

@ -4,15 +4,15 @@ import at.petrak.hexcasting.common.items.*;
import at.petrak.hexcasting.common.items.colorizer.ItemDyeColorizer;
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
import at.petrak.hexcasting.common.items.colorizer.ItemUUIDColorizer;
import at.petrak.hexcasting.common.items.magic.ItemArtifact;
import at.petrak.hexcasting.common.items.magic.ItemCypher;
import at.petrak.hexcasting.common.items.magic.ItemManaBattery;
import at.petrak.hexcasting.common.items.magic.ItemTrinket;
import at.petrak.hexcasting.common.items.magic.*;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.*;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tiers;
import java.util.EnumMap;
import java.util.LinkedHashMap;
@ -57,7 +57,8 @@ public class HexItems {
public static final ItemTrinket TRINKET = make("trinket", new ItemTrinket(unstackable()));
public static final ItemArtifact ARTIFACT = make("artifact", new ItemArtifact(unstackable()));
public static final ItemJewelerHammer JEWELER_HAMMER = make("jeweler_hammer", new ItemJewelerHammer(Tiers.IRON, 0, -2.8F, props().stacksTo(1)));
public static final ItemJewelerHammer JEWELER_HAMMER = make("jeweler_hammer",
new ItemJewelerHammer(Tiers.IRON, 0, -2.8F, props().stacksTo(1)));
public static final ItemScroll SCROLL = make("scroll", new ItemScroll(props()));
@ -85,6 +86,9 @@ public class HexItems {
public static final Item SUBMARINE_SANDWICH = make("sub_sandwich",
new Item(props().food(new FoodProperties.Builder().nutrition(14).saturationMod(1.2f).build())));
public static final ItemCreativeUnlocker CREATIVE_UNLOCKER = make("creative_unlocker",
new ItemCreativeUnlocker(props()));
//
public static Item.Properties props() {

View file

@ -57,6 +57,10 @@
"item.hexcasting.pride_colorizer_12": "Intersex Pigment",
"item.hexcasting.pride_colorizer_13": "Aroace Pigment",
"item.hexcasting.uuid_colorizer": "Soulglimmer Pigment",
"item.hexcasting.creative_unlocker": "Creative Unlocker",
"item.hexcasting.creative_unlocker.tooltip.0": "Contains INFINITE MEDIA.",
"item.hexcasting.creative_unlocker.tooltip.1": "Right-click to unlock all Hexcasting advancements and abilities.",
"block.hexcasting.conjured": "Conjured Block",
"block.hexcasting.slate.blank": "Blank Slate",

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

View file

@ -33,6 +33,7 @@ public class HexItemModels extends PaucalItemModelProvider {
simpleItem(HexItems.SUBMARINE_SANDWICH);
simpleItem(HexItems.ABACUS);
brandishedItem(HexItems.JEWELER_HAMMER);
simpleItem(HexItems.CREATIVE_UNLOCKER);
simpleItem(modLoc("scroll_pristine"));
simpleItem(modLoc("scroll_ancient"));