From 18383927d7849a2e2b7a7bb7334c74e3ed4a9885 Mon Sep 17 00:00:00 2001 From: gamma-delta <29877714+gamma-delta@users.noreply.github.com> Date: Wed, 25 May 2022 17:13:19 -0500 Subject: [PATCH] add creative unlocker --- Common/src/generated/resources/.cache/cache | 1 + .../models/item/creative_unlocker.json | 6 ++ .../items/magic/ItemCreativeUnlocker.java | 95 ++++++++++++++++++ .../hexcasting/common/lib/HexItems.java | 16 +-- .../assets/hexcasting/lang/en_us.json | 4 + .../textures/item/creative_unlocker.png | Bin 0 -> 250 bytes .../forge/datagen/xplat/HexItemModels.java | 1 + 7 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 Common/src/generated/resources/assets/hexcasting/models/item/creative_unlocker.json create mode 100644 Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java create mode 100644 Common/src/main/resources/assets/hexcasting/textures/item/creative_unlocker.png diff --git a/Common/src/generated/resources/.cache/cache b/Common/src/generated/resources/.cache/cache index f30c6ab7..1377a109 100644 --- a/Common/src/generated/resources/.cache/cache +++ b/Common/src/generated/resources/.cache/cache @@ -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 diff --git a/Common/src/generated/resources/assets/hexcasting/models/item/creative_unlocker.json b/Common/src/generated/resources/assets/hexcasting/models/item/creative_unlocker.json new file mode 100644 index 00000000..452b44f6 --- /dev/null +++ b/Common/src/generated/resources/assets/hexcasting/models/item/creative_unlocker.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "hexcasting:item/creative_unlocker" + } +} \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java new file mode 100644 index 00000000..7ae5db81 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/items/magic/ItemCreativeUnlocker.java @@ -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 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(); + 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 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 out) { + for (Advancement kiddo : root.getChildren()) { + out.add(kiddo); + addChildren(kiddo, out); + } + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java index 1387d0ca..9c7ac96e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexItems.java @@ -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() { diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.json b/Common/src/main/resources/assets/hexcasting/lang/en_us.json index acb223ed..fb88990a 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.json @@ -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", diff --git a/Common/src/main/resources/assets/hexcasting/textures/item/creative_unlocker.png b/Common/src/main/resources/assets/hexcasting/textures/item/creative_unlocker.png new file mode 100644 index 0000000000000000000000000000000000000000..d8ef75a7bc5126c8beb41ceed568a29707228de5 GIT binary patch literal 250 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`2R&UJLo5W(PTI(O$Uwk#Grw?v z5hHK#g$<5u4o$8alFU(I35{10z9`wgbbjMu(&4eZ`~9DPwbAc(#n;S!x=$ef?5(x_ zM=RpqwIMuV*!s# yM@d32Pef~NV%Lj?trv7wH24Xfx%dC?eujU?D^7$@oE-`D41=eupUXO@geCxBR%D|9 literal 0 HcmV?d00001 diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/xplat/HexItemModels.java b/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/xplat/HexItemModels.java index a5491f63..d7beba78 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/xplat/HexItemModels.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/xplat/HexItemModels.java @@ -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"));