From 9313735323f19138769719e7354a711657c53d77 Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Mon, 30 Dec 2024 10:06:06 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Added=20the=20Smithing=20Up?= =?UTF-8?q?grade.=20It=20functions=20like=20a=20Smithing=20Table=20but=20i?= =?UTF-8?q?n=20an=20upgrade=20slot.=20Unlike=20the=20Smithing=20Table,=20t?= =?UTF-8?q?his=20upgrade=20retains=20its=20contents=20if=20you=20exit=20wi?= =?UTF-8?q?thout=20completing=20the=20crafting.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 4 +- .../recipes/misc/smithing_upgrade.json | 35 +++ .../recipes/smithing_upgrade.json | 31 +++ .../data/SBPRecipeProvider.java | 11 + .../sophisticatedbackpacks/init/ModItems.java | 8 + .../smithing/SmithingUpgradeContainer.java | 159 ++++++++++++++ .../smithing/SmithingUpgradeItem.java | 24 +++ .../upgrades/smithing/SmithingUpgradeTab.java | 202 ++++++++++++++++++ .../smithing/SmithingUpgradeWrapper.java | 44 ++++ .../upgrades/smithing/package-info.java | 8 + .../resources/META-INF/accesstransformer.cfg | 4 + .../sophisticatedbackpacks/lang/en_us.json | 8 +- .../models/item/smithing_upgrade.json | 6 + .../textures/item/smithing_upgrade.png | Bin 0 -> 261 bytes 14 files changed, 540 insertions(+), 4 deletions(-) create mode 100644 src/generated/resources/data/sophisticatedbackpacks/advancements/recipes/misc/smithing_upgrade.json create mode 100644 src/generated/resources/data/sophisticatedbackpacks/recipes/smithing_upgrade.json create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeContainer.java create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeItem.java create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeTab.java create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeWrapper.java create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/package-info.java create mode 100644 src/main/resources/assets/sophisticatedbackpacks/models/item/smithing_upgrade.json create mode 100644 src/main/resources/assets/sophisticatedbackpacks/textures/item/smithing_upgrade.png diff --git a/gradle.properties b/gradle.properties index 5cc94ff6..d1da6eb7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false mod_id=sophisticatedbackpacks mod_group_id=sophisticatedbackpacks -mod_version=3.20.17 +mod_version=3.21.0 sonar_project_key=sophisticatedbackpacks:SophisticatedBackpacks github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedBackpacks @@ -31,5 +31,5 @@ crafting_tweaks_cf_file_id=4596466 chipped_cf_file_id=5077656 resourcefullib_cf_file_id=5070629 athena_cf_file_id=4764357 -sc_version=[1.20.1-0.7.8,1.20.4) +sc_version=[1.20.1-1.0.3,1.20.4) parchment_version=2023.09.03-1.20.1 \ No newline at end of file diff --git a/src/generated/resources/data/sophisticatedbackpacks/advancements/recipes/misc/smithing_upgrade.json b/src/generated/resources/data/sophisticatedbackpacks/advancements/recipes/misc/smithing_upgrade.json new file mode 100644 index 00000000..cab80b88 --- /dev/null +++ b/src/generated/resources/data/sophisticatedbackpacks/advancements/recipes/misc/smithing_upgrade.json @@ -0,0 +1,35 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_the_recipe": { + "conditions": { + "recipe": "sophisticatedbackpacks:smithing_upgrade" + }, + "trigger": "minecraft:recipe_unlocked" + }, + "has_upgrade_base": { + "conditions": { + "items": [ + { + "items": [ + "sophisticatedbackpacks:upgrade_base" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + } + }, + "requirements": [ + [ + "has_upgrade_base", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "sophisticatedbackpacks:smithing_upgrade" + ] + }, + "sends_telemetry_event": true +} \ No newline at end of file diff --git a/src/generated/resources/data/sophisticatedbackpacks/recipes/smithing_upgrade.json b/src/generated/resources/data/sophisticatedbackpacks/recipes/smithing_upgrade.json new file mode 100644 index 00000000..76a10f24 --- /dev/null +++ b/src/generated/resources/data/sophisticatedbackpacks/recipes/smithing_upgrade.json @@ -0,0 +1,31 @@ +{ + "type": "minecraft:crafting_shaped", + "conditions": [ + { + "type": "sophisticatedcore:item_enabled", + "itemRegistryName": "sophisticatedbackpacks:smithing_upgrade" + } + ], + "key": { + "B": { + "item": "sophisticatedbackpacks:upgrade_base" + }, + "C": { + "tag": "forge:chests/wooden" + }, + "I": { + "tag": "forge:ingots/iron" + }, + "S": { + "item": "minecraft:smithing_table" + } + }, + "pattern": [ + " S ", + "IBI", + " C " + ], + "result": { + "item": "sophisticatedbackpacks:smithing_upgrade" + } +} \ No newline at end of file diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/data/SBPRecipeProvider.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/data/SBPRecipeProvider.java index b24813ed..a6c9134e 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/data/SBPRecipeProvider.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/data/SBPRecipeProvider.java @@ -618,6 +618,17 @@ protected void buildRecipes(Consumer consumer) { .unlockedBy(HAS_UPGRADE_BASE, has(ModItems.UPGRADE_BASE.get())) .save(consumer); + ShapeBasedRecipeBuilder.shaped(ModItems.SMITHING_UPGRADE.get()) + .pattern(" S ") + .pattern("IBI") + .pattern(" C ") + .define('S', Items.SMITHING_TABLE) + .define('I', Tags.Items.INGOTS_IRON) + .define('B', ModItems.UPGRADE_BASE.get()) + .define('C', Tags.Items.CHESTS_WOODEN) + .unlockedBy(HAS_UPGRADE_BASE, has(ModItems.UPGRADE_BASE.get())) + .save(consumer); + new SmithingTransformRecipeBuilder(ModItems.SMITHING_BACKPACK_UPGRADE_RECIPE_SERIALIZER.get(), Ingredient.of(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE), Ingredient.of(ModItems.DIAMOND_BACKPACK.get()), Ingredient.of(Items.NETHERITE_INGOT), RecipeCategory.MISC, ModItems.NETHERITE_BACKPACK.get()) .unlocks("has_diamond_backpack", has(ModItems.DIAMOND_BACKPACK.get())) diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItems.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItems.java index a001e77c..7cf453ae 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItems.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItems.java @@ -78,6 +78,10 @@ import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.restock.RestockUpgradeItem; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.restock.RestockUpgradeTab; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.restock.RestockUpgradeWrapper; +import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing.SmithingUpgradeContainer; +import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing.SmithingUpgradeItem; +import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing.SmithingUpgradeTab; +import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing.SmithingUpgradeWrapper; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper.ToolSwapperUpgradeContainer; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper.ToolSwapperUpgradeItem; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper.ToolSwapperUpgradeTab; @@ -241,6 +245,7 @@ private ModItems() { public static final RegistryObject ADVANCED_PUMP_UPGRADE = ITEMS.register("advanced_pump_upgrade", () -> new PumpUpgradeItem(true, true, Config.SERVER.pumpUpgrade, Config.SERVER.maxUpgradesPerStorage)); public static final RegistryObject XP_PUMP_UPGRADE = ITEMS.register("xp_pump_upgrade", () -> new XpPumpUpgradeItem(Config.SERVER.xpPumpUpgrade, Config.SERVER.maxUpgradesPerStorage)); public static final RegistryObject ANVIL_UPGRADE = ITEMS.register("anvil_upgrade", AnvilUpgradeItem::new); + public static final RegistryObject SMITHING_UPGRADE = ITEMS.register("smithing_upgrade", SmithingUpgradeItem::new); public static final RegistryObject UPGRADE_BASE = ITEMS.register("upgrade_base", () -> new ItemBase(new Item.Properties().stacksTo(16))); @@ -323,6 +328,7 @@ private static void onResourceReload(AddReloadListenerEvent event) { private static final UpgradeContainerType ADVANCED_PUMP_TYPE = new UpgradeContainerType<>(PumpUpgradeContainer::new); private static final UpgradeContainerType XP_PUMP_TYPE = new UpgradeContainerType<>(XpPumpUpgradeContainer::new); private static final UpgradeContainerType ANVIL_TYPE = new UpgradeContainerType<>(AnvilUpgradeContainer::new); + public static final UpgradeContainerType SMITHING_TYPE = new UpgradeContainerType<>(SmithingUpgradeContainer::new); public static void registerContainers(RegisterEvent event) { if (!event.getRegistryKey().equals(ForgeRegistries.Keys.MENU_TYPES)) { @@ -364,6 +370,7 @@ public static void registerContainers(RegisterEvent event) { UpgradeContainerRegistry.register(ADVANCED_PUMP_UPGRADE.getId(), ADVANCED_PUMP_TYPE); UpgradeContainerRegistry.register(XP_PUMP_UPGRADE.getId(), XP_PUMP_TYPE); UpgradeContainerRegistry.register(ANVIL_UPGRADE.getId(), ANVIL_TYPE); + UpgradeContainerRegistry.register(SMITHING_UPGRADE.getId(), SMITHING_TYPE); DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { MenuScreens.register(BACKPACK_CONTAINER_TYPE.get(), BackpackScreen::constructScreen); @@ -428,6 +435,7 @@ public static void registerContainers(RegisterEvent event) { UpgradeGuiManager.registerTab(XP_PUMP_TYPE, (XpPumpUpgradeContainer upgradeContainer, Position position, StorageScreenBase screen) -> new XpPumpUpgradeTab(upgradeContainer, position, screen, Config.SERVER.xpPumpUpgrade.mendingOn.get())); UpgradeGuiManager.registerTab(ANVIL_TYPE, AnvilUpgradeTab::new); + UpgradeGuiManager.registerTab(ModItems.SMITHING_TYPE, SmithingUpgradeTab::new); }); } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeContainer.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeContainer.java new file mode 100644 index 00000000..c8aec7f8 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeContainer.java @@ -0,0 +1,159 @@ +package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.*; +import net.minecraft.world.item.ItemStack; +import net.p3pp3rf1y.sophisticatedcore.common.gui.SlotSuppliedHandler; +import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerBase; +import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerType; +import net.p3pp3rf1y.sophisticatedcore.upgrades.IUpgradeWrapper; +import net.p3pp3rf1y.sophisticatedcore.util.NBTHelper; + +public class SmithingUpgradeContainer extends UpgradeContainerBase { + private static final String DATA_SHIFT_CLICK_INTO_STORAGE = "shiftClickIntoStorage"; + private final Slot resultSlot; + private Runnable onResultChanged = () -> {}; + + private final PersistableSmithingMenu smithingMenuDelegate; + public SmithingUpgradeContainer(Player player, int upgradeContainerId, SmithingUpgradeWrapper upgradeWrapper, UpgradeContainerType type) { + super(player, upgradeContainerId, upgradeWrapper, type); + smithingMenuDelegate = new PersistableSmithingMenu(new Inventory(player)); + + slots.add(smithingMenuDelegate.getSlot(SmithingMenu.TEMPLATE_SLOT)); + slots.add(smithingMenuDelegate.getSlot(SmithingMenu.BASE_SLOT)); + slots.add(smithingMenuDelegate.getSlot(SmithingMenu.ADDITIONAL_SLOT)); + resultSlot = smithingMenuDelegate.getSlot(SmithingMenu.RESULT_SLOT); + slots.add(resultSlot); + smithingMenuDelegate.createResult(); + } + + public void setOnResultChangedHandler(Runnable onResultChanged) { + this.onResultChanged = onResultChanged; + } + + @Override + public void handleMessage(CompoundTag data) { + if (data.contains(DATA_SHIFT_CLICK_INTO_STORAGE)) { + setShiftClickIntoStorage(data.getBoolean(DATA_SHIFT_CLICK_INTO_STORAGE)); + } + } + + @Override + public void setUpgradeWrapper(IUpgradeWrapper updatedUpgradeWrapper) { + super.setUpgradeWrapper(updatedUpgradeWrapper); + smithingMenuDelegate.createResult(); + } + + public boolean shouldShiftClickIntoStorage() { + return upgradeWrapper.shouldShiftClickIntoStorage(); + } + + public void setShiftClickIntoStorage(boolean shiftClickIntoStorage) { + upgradeWrapper.setShiftClickIntoStorage(shiftClickIntoStorage); + sendDataToServer(() -> NBTHelper.putBoolean(new CompoundTag(), DATA_SHIFT_CLICK_INTO_STORAGE, shiftClickIntoStorage)); + } + + @Override + public boolean mergeIntoStorageFirst(Slot slot) { + return !(slot instanceof ResultSlot) || shouldShiftClickIntoStorage(); + } + + @Override + public boolean allowsPickupAll(Slot slot) { + return slot != resultSlot; + } + + public Slot getTemplateSlot() { + return smithingMenuDelegate.getSlot(SmithingMenu.TEMPLATE_SLOT); + } + + public Slot getBaseSlot() { + return smithingMenuDelegate.getSlot(SmithingMenu.BASE_SLOT); + } + + public Slot getAdditionalSlot() { + return smithingMenuDelegate.getSlot(SmithingMenu.ADDITIONAL_SLOT); + } + + public Slot getResultSlot() { + return smithingMenuDelegate.getSlot(SmithingMenu.RESULT_SLOT); + } + + private class PersistableSmithingMenu extends SmithingMenu { + + public PersistableSmithingMenu(Inventory playerInventory) { + super(0, playerInventory, ContainerLevelAccess.create(playerInventory.player.level(), playerInventory.player.blockPosition())); + } + + @Override + protected void createInputSlots(ItemCombinerMenuSlotDefinition itemCombinerMenuSlotDefinition) { + for(final ItemCombinerMenuSlotDefinition.SlotDefinition slotDefinition : itemCombinerMenuSlotDefinition.getSlots()) { + this.addSlot(new SlotSuppliedHandler(upgradeWrapper::getInventory, slotDefinition.slotIndex(), 0, 0) { + @Override + public void setChanged() { + super.setChanged(); + slotsChanged(inputSlots); + } + + @Override + public boolean mayPlace(ItemStack p_267156_) { + return slotDefinition.mayPlace().test(p_267156_); + } + }); + } + } + + @Override + protected SimpleContainer createContainer(int size) { + return new SimpleContainer(size) { + public void setChanged() { + super.setChanged(); + slotsChanged(this); + } + + @Override + public ItemStack getItem(int pIndex) { + return upgradeWrapper.getInventory().getStackInSlot(pIndex); + } + + @Override + public void setItem(int pIndex, ItemStack pStack) { + upgradeWrapper.getInventory().setStackInSlot(pIndex, pStack); + } + }; + } + + @Override + protected void createResultSlot(ItemCombinerMenuSlotDefinition slotDefinition) { + this.addSlot(new Slot(this.resultSlots, slotDefinition.getResultSlot().slotIndex(), slotDefinition.getResultSlot().x(), slotDefinition.getResultSlot().y()) { + public boolean mayPlace(ItemStack stack) { + return false; + } + + public boolean mayPickup(Player player) { + return PersistableSmithingMenu.this.mayPickup(player, this.hasItem()); + } + + public void onTake(Player player, ItemStack stack) { + PersistableSmithingMenu.this.onTake(player, stack); + } + + @Override + public void setChanged() { + super.setChanged(); + onResultChanged.run(); + } + }); + } + + @Override + public void slotsChanged(Container pInventory) { + createResult(); + onResultChanged.run(); + } + } +} diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeItem.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeItem.java new file mode 100644 index 00000000..cddfb631 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeItem.java @@ -0,0 +1,24 @@ +package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing; + +import net.p3pp3rf1y.sophisticatedbackpacks.Config; +import net.p3pp3rf1y.sophisticatedcore.upgrades.UpgradeItemBase; +import net.p3pp3rf1y.sophisticatedcore.upgrades.UpgradeType; + +import java.util.List; + +public class SmithingUpgradeItem extends UpgradeItemBase { + private static final UpgradeType TYPE = new UpgradeType<>(SmithingUpgradeWrapper::new); + public SmithingUpgradeItem() { + super(Config.SERVER.maxUpgradesPerStorage); + } + + @Override + public UpgradeType getType() { + return TYPE; + } + + @Override + public List getUpgradeConflicts() { + return List.of(); + } +} diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeTab.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeTab.java new file mode 100644 index 00000000..75a24478 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeTab.java @@ -0,0 +1,202 @@ +package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.CyclingSlotBackground; +import net.minecraft.client.gui.screens.inventory.InventoryScreen; +import net.minecraft.client.gui.screens.inventory.SmithingScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ArmorItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SmithingTemplateItem; +import net.p3pp3rf1y.sophisticatedbackpacks.client.gui.SBPTranslationHelper; +import net.p3pp3rf1y.sophisticatedcore.client.gui.StorageScreenBase; +import net.p3pp3rf1y.sophisticatedcore.client.gui.UpgradeSettingsTab; +import net.p3pp3rf1y.sophisticatedcore.client.gui.utils.*; + +import java.util.List; + +public class SmithingUpgradeTab extends UpgradeSettingsTab { + + public static final TextureBlitData ARROW = new TextureBlitData(GuiHelper.GUI_CONTROLS, Dimension.SQUARE_256, new UV(56, 221), new Dimension(14, 15)); + public static final TextureBlitData RED_CROSS = new TextureBlitData(GuiHelper.GUI_CONTROLS, Dimension.SQUARE_256, new UV(113, 216), new Dimension(15, 15)); + private final CyclingSlotBackground templateIcon; + private final CyclingSlotBackground baseIcon; + private final CyclingSlotBackground additionalIcon; + private final ArmorStand armorStandPreview; + + public SmithingUpgradeTab(SmithingUpgradeContainer upgradeContainer, Position position, StorageScreenBase screen) { + super(upgradeContainer, position, screen, SBPTranslationHelper.INSTANCE.translUpgrade("smithing"), SBPTranslationHelper.INSTANCE.translUpgradeTooltip("smithing")); + openTabDimension = new Dimension(103, 100); + + armorStandPreview = new ArmorStand(minecraft.level, 0.0, 0.0, 0.0); + armorStandPreview.setNoBasePlate(true); + armorStandPreview.setShowArms(true); + armorStandPreview.yBodyRot = 210.0F; + armorStandPreview.setXRot(25.0F); + armorStandPreview.yHeadRot = armorStandPreview.getYRot(); + armorStandPreview.yHeadRotO = armorStandPreview.getYRot(); + updateArmorStandPreview(); + + templateIcon = new CyclingSlotBackground(getContainer().getTemplateSlot().index); + baseIcon = new CyclingSlotBackground(getContainer().getBaseSlot().index); + additionalIcon = new CyclingSlotBackground(getContainer().getAdditionalSlot().index); + + getContainer().setOnResultChangedHandler(this::updateArmorStandPreview); + } + + private void updateArmorStandPreview() { + ItemStack stack = getContainer().getResultSlot().getItem(); + if (this.armorStandPreview != null) { + for (EquipmentSlot equipmentslot : EquipmentSlot.values()) { + armorStandPreview.setItemSlot(equipmentslot, ItemStack.EMPTY); + } + + if (!stack.isEmpty()) { + ItemStack itemstack = stack.copy(); + if (stack.getItem() instanceof ArmorItem armoritem) { + armorStandPreview.setItemSlot(armoritem.getEquipmentSlot(), itemstack); + } else { + armorStandPreview.setItemSlot(EquipmentSlot.OFFHAND, itemstack); + } + } + } + } + + @Override + protected void renderBg(GuiGraphics guiGraphics, Minecraft minecraft, int mouseX, int mouseY) { + super.renderBg(guiGraphics, minecraft, mouseX, mouseY); + + if (getContainer().isOpen()) { + renderSlotBg(guiGraphics, getContainer().getTemplateSlot()); + renderSlotBg(guiGraphics, getContainer().getBaseSlot()); + renderSlotBg(guiGraphics, getContainer().getAdditionalSlot()); + renderSlotBg(guiGraphics, getContainer().getResultSlot()); + + templateIcon.render(screen.getMenu(), guiGraphics, 0, screen.getLeftX(), screen.getTopY()); + baseIcon.render(screen.getMenu(), guiGraphics, 0, screen.getLeftX(), screen.getTopY()); + additionalIcon.render(screen.getMenu(), guiGraphics, 0, screen.getLeftX(), screen.getTopY()); + } + } + + private void renderSlotBg(GuiGraphics guiGraphics, Slot slot) { + GuiHelper.renderSlotsBackground(guiGraphics, slot.x + screen.getGuiLeft() - 1, slot.y + screen.getGuiTop() - 1, 1, 1); + } + + @Override + public void renderTooltip(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY) { + super.renderTooltip(screen, guiGraphics, mouseX, mouseY); + renderOnboardingTooltips(guiGraphics, mouseX, mouseY); + } + + @Override + protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks); + + if (!isOpen) { + return; + } + + Slot resultSlot = getContainer().getResultSlot(); + int inputSlotsY = resultSlot.y + screen.getGuiTop(); + int additionalSlotX = getContainer().getAdditionalSlot().x + screen.getGuiLeft(); + int resultSlotX = resultSlot.x + screen.getGuiLeft(); + + int arrowX = getArrowX(additionalSlotX, resultSlotX); + int arrowY = getArrowY(inputSlotsY); + GuiHelper.blit(guiGraphics, arrowX, arrowY, ARROW); + + if (hasRecipeError()) { + GuiHelper.blit(guiGraphics, arrowX, arrowY, RED_CROSS); + } + + InventoryScreen.renderEntityInInventory(guiGraphics, getX() + getWidth() / 2, getTopY() + getHeight() - 10, 25, + SmithingScreen.ARMOR_STAND_ANGLE, null, armorStandPreview); + } + + private int getArrowY(int inputSlotsY) { + return inputSlotsY + 1; + } + + private int getArrowX(int additionalSlotX, int resultSlotX) { + return additionalSlotX + 18 + (resultSlotX - (additionalSlotX + 18)) / 2 - ARROW.getWidth() / 2 - 1; + } + + @Override + public void tick() { + super.tick(); + this.templateIcon.tick(SmithingScreen.EMPTY_SLOT_SMITHING_TEMPLATES); + ItemStack templateItem = getContainer().getTemplateSlot().getItem(); + if (templateItem.getItem() instanceof SmithingTemplateItem smithingTemplate) { + this.baseIcon.tick(smithingTemplate.getBaseSlotEmptyIcons()); + this.additionalIcon.tick(smithingTemplate.getAdditionalSlotEmptyIcons()); + } else { + baseIcon.tick(List.of()); + additionalIcon.tick(List.of()); + } + } + + @Override + protected void moveSlotsToTab() { + Slot templateSlot = getContainer().getTemplateSlot(); + templateSlot.x = x - screen.getGuiLeft() + 4; + templateSlot.y = y - screen.getGuiTop() + 1 + 24; + + Slot baseSlot = getContainer().getBaseSlot(); + baseSlot.x = templateSlot.x + 18; + baseSlot.y = y - screen.getGuiTop() + 1 + 24; + + Slot additionalSlot = getContainer().getAdditionalSlot(); + additionalSlot.x = baseSlot.x + 18; + additionalSlot.y = y - screen.getGuiTop() + 1 + 24; + + Slot resultSlot = getContainer().getResultSlot(); + resultSlot.x = x - screen.getGuiLeft() + getWidth() - 2 - 3 - 18; + resultSlot.y = y - screen.getGuiTop() + 1 + 24; + } + + private boolean isHoveringRedCross(int mouseX, int mouseY) { + Slot additionalSlot = getContainer().getAdditionalSlot(); + int arrowX = getArrowX(additionalSlot.x + screen.getGuiLeft(), getContainer().getResultSlot().x + screen.getGuiLeft()); + int arrowY = getArrowY(additionalSlot.y + screen.getGuiTop()); + return mouseX >= arrowX && mouseX < arrowX + RED_CROSS.getWidth() && mouseY >= arrowY && mouseY < arrowY + RED_CROSS.getHeight(); + } + + private boolean isHoveringEmptySlot(Slot slot, int mouseX, int mouseY) { + return mouseX >= slot.x + screen.getGuiLeft() && mouseX < slot.x + screen.getGuiLeft() + 16 && mouseY >= slot.y + screen.getGuiTop() && mouseY < slot.y + screen.getGuiTop() + 16 && slot.getItem().isEmpty(); + } + + private void renderOnboardingTooltips(GuiGraphics guiGraphics, int mouseX, int mouseY) { + if (this.hasRecipeError() && isHoveringRedCross(mouseX, mouseY)) { + Component tooltip = SmithingScreen.ERROR_TOOLTIP; + renderOnboardingTooltip(guiGraphics, mouseX, mouseY, tooltip); + } else { + if (isHoveringEmptySlot(getContainer().getTemplateSlot(), mouseX, mouseY)) { + renderOnboardingTooltip(guiGraphics, mouseX, mouseY, SmithingScreen.MISSING_TEMPLATE_TOOLTIP); + } else if (getContainer().getTemplateSlot().getItem().getItem() instanceof SmithingTemplateItem smithingTemplate) { + + if (isHoveringEmptySlot(getContainer().getBaseSlot(), mouseX, mouseY)) { + renderOnboardingTooltip(guiGraphics, mouseX, mouseY, smithingTemplate.getBaseSlotDescription()); + } else if (isHoveringEmptySlot(getContainer().getAdditionalSlot(), mouseX, mouseY)) { + renderOnboardingTooltip(guiGraphics, mouseX, mouseY, smithingTemplate.getAdditionSlotDescription()); + } + } + } + } + + private void renderOnboardingTooltip(GuiGraphics guiGraphics, int mouseX, int mouseY, Component tooltip) { + guiGraphics.pose().pushPose(); + guiGraphics.pose().translate(0, 0, 410); + guiGraphics.renderTooltip(font, font.split(tooltip, 115), mouseX, mouseY); + guiGraphics.pose().popPose(); + } + + private boolean hasRecipeError() { + return getContainer().getTemplateSlot().hasItem() && getContainer().getBaseSlot().hasItem() && getContainer().getAdditionalSlot().hasItem() && !getContainer().getResultSlot().hasItem(); + } + +} diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeWrapper.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeWrapper.java new file mode 100644 index 00000000..10519ad1 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeWrapper.java @@ -0,0 +1,44 @@ +package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing; + +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.items.ItemStackHandler; +import net.p3pp3rf1y.sophisticatedcore.api.IStorageWrapper; +import net.p3pp3rf1y.sophisticatedcore.upgrades.UpgradeWrapperBase; +import net.p3pp3rf1y.sophisticatedcore.util.NBTHelper; + +import java.util.function.Consumer; + +public class SmithingUpgradeWrapper extends UpgradeWrapperBase { + private final ItemStackHandler inventory; + + protected SmithingUpgradeWrapper(IStorageWrapper storageWrapper, ItemStack upgrade, Consumer upgradeSaveHandler) { + super(storageWrapper, upgrade, upgradeSaveHandler); + + inventory = new ItemStackHandler(3) { + @Override + protected void onContentsChanged(int slot) { + super.onContentsChanged(slot); + upgrade.addTagElement("craftingInventory", serializeNBT()); + save(); + } + }; + } + + public ItemStackHandler getInventory() { + return inventory; + } + + @Override + public boolean canBeDisabled() { + return false; + } + + public boolean shouldShiftClickIntoStorage() { + return NBTHelper.getBoolean(upgrade, "shiftClickIntoStorage").orElse(true); + } + + public void setShiftClickIntoStorage(boolean shiftClickIntoStorage) { + NBTHelper.setBoolean(upgrade, "shiftClickIntoStorage", shiftClickIntoStorage); + save(); + } +} diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/package-info.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/package-info.java new file mode 100644 index 00000000..567fe08f --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/package-info.java @@ -0,0 +1,8 @@ +// Auto generated package-info by MCP + +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing; + +import net.minecraft.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index d8365c74..8ad779d2 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -37,3 +37,7 @@ public net.minecraft.world.item.crafting.ShapedRecipe f_44149_ # result protected net.minecraft.world.inventory.AnvilMenu f_39001_ # itemName protected net.minecraft.world.inventory.ItemCombinerMenu m_266254_(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V # createInputSlots protected net.minecraft.world.inventory.ItemCombinerMenu m_266190_(I)Lnet/minecraft/world/SimpleContainer; # createContainer +protected net.minecraft.world.inventory.ItemCombinerMenu m_266430_(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V # createResultSlot +public net.minecraft.client.gui.screens.inventory.SmithingScreen f_265883_ # EMPTY_SLOT_SMITHING_TEMPLATES +public net.minecraft.client.gui.screens.inventory.SmithingScreen f_266014_ # ERROR_TOOLTIP +public net.minecraft.client.gui.screens.inventory.SmithingScreen f_266043_ # MISSING_TEMPLATE_TOOLTIP \ No newline at end of file diff --git a/src/main/resources/assets/sophisticatedbackpacks/lang/en_us.json b/src/main/resources/assets/sophisticatedbackpacks/lang/en_us.json index 9121583d..e71a5988 100644 --- a/src/main/resources/assets/sophisticatedbackpacks/lang/en_us.json +++ b/src/main/resources/assets/sophisticatedbackpacks/lang/en_us.json @@ -2,12 +2,12 @@ "itemGroup.sophisticatedbackpacks": "Sophisticated Backpacks", "item.sophisticatedbackpacks.backpack": "Backpack", "block.sophisticatedbackpacks.backpack": "Backpack", - "item.sophisticatedbackpacks.copper_backpack": "Copper Backpack", + "item.sophisticatedbackpacks.copper_backpack": "Copper Backpack", "item.sophisticatedbackpacks.iron_backpack": "Iron Backpack", "item.sophisticatedbackpacks.gold_backpack": "Gold Backpack", "item.sophisticatedbackpacks.diamond_backpack": "Diamond Backpack", "item.sophisticatedbackpacks.netherite_backpack": "Netherite Backpack", - "block.sophisticatedbackpacks.copper_backpack": "Copper Backpack", + "block.sophisticatedbackpacks.copper_backpack": "Copper Backpack", "block.sophisticatedbackpacks.iron_backpack": "Iron Backpack", "block.sophisticatedbackpacks.gold_backpack": "Gold Backpack", "block.sophisticatedbackpacks.diamond_backpack": "Diamond Backpack", @@ -97,6 +97,8 @@ "item.sophisticatedbackpacks.advanced_tool_swapper_upgrade.tooltip": "Automatically swaps item in player's hand for the one effective on the block/entity when these are left clicked.\nHas filter options and enables swapping wrench like tools for block/entity player is looking at with %s", "item.sophisticatedbackpacks.anvil_upgrade": "Anvil Upgrade", "item.sophisticatedbackpacks.anvil_upgrade.tooltip": "Anvil in an upgrade tab", + "item.sophisticatedbackpacks.smithing_upgrade": "Smithing Upgrade", + "item.sophisticatedbackpacks.smithing_upgrade.tooltip": "Smithing Table in an upgrade tab", "item.sophisticatedbackpacks.chipped.botanist_workbench_upgrade": "Chipped: Botanist's Workbench Upgrade", "item.sophisticatedbackpacks.chipped.botanist_workbench_upgrade.tooltip": "Chipped Botanist's Workbench in an upgrade tab", "item.sophisticatedbackpacks.chipped.glassblower_upgrade": "Chipped: Glassblower Upgrade", @@ -145,6 +147,7 @@ "gui.sophisticatedbackpacks.upgrades.inception": "Inception", "gui.sophisticatedbackpacks.upgrades.advanced_tool_swapper": "Tool Swap", "gui.sophisticatedbackpacks.upgrades.anvil": "Anvil", + "gui.sophisticatedbackpacks.upgrades.smithing": "Smithing", "gui.sophisticatedbackpacks.upgrades.restock.tooltip": "Restock Settings", "gui.sophisticatedbackpacks.upgrades.advanced_restock.tooltip": "Advanced Restock Settings", "gui.sophisticatedbackpacks.upgrades.deposit.tooltip": "Deposit Settings", @@ -152,6 +155,7 @@ "gui.sophisticatedbackpacks.upgrades.refill.tooltip": "Refill Settings", "gui.sophisticatedbackpacks.upgrades.advanced_refill.tooltip": "Advanced Refill Settings", "gui.sophisticatedbackpacks.upgrades.anvil.tooltip": "Anvil", + "gui.sophisticatedbackpacks.upgrades.smithing.tooltip": "Smithing", "gui.sophisticatedbackpacks.upgrades.refill.target_slot.tooltip": "Refill %s", "gui.sophisticatedbackpacks.upgrades.refill.target_slot.any": "A", "gui.sophisticatedbackpacks.upgrades.refill.target_slot.any.tooltip": "Any slot", diff --git a/src/main/resources/assets/sophisticatedbackpacks/models/item/smithing_upgrade.json b/src/main/resources/assets/sophisticatedbackpacks/models/item/smithing_upgrade.json new file mode 100644 index 00000000..f8e18f35 --- /dev/null +++ b/src/main/resources/assets/sophisticatedbackpacks/models/item/smithing_upgrade.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "sophisticatedbackpacks:item/smithing_upgrade" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/sophisticatedbackpacks/textures/item/smithing_upgrade.png b/src/main/resources/assets/sophisticatedbackpacks/textures/item/smithing_upgrade.png new file mode 100644 index 0000000000000000000000000000000000000000..da1ca64000beb669f6b54a3aa54c5b5b159318cd GIT binary patch literal 261 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`XFOdTLo7}wCoEv&2o(P_h>1%#QInVsLQ zxymwk@4ut+B6dFfe))1=ylK<+fIFr6I9rc{a8R@Vy$?EX7>imwRU|t4>PP@X7c>?o+ECvQoS3j3^P65~ literal 0 HcmV?d00001