diff --git a/build.gradle b/build.gradle index 0eae6c1f..ea124311 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,10 @@ idea { } } +if (findProject(':SophisticatedCore') != null) { + evaluationDependsOn(':SophisticatedCore') +} + version = "${project.minecraft_version}-${project.mod_version}.${getBuildNumber()}${getStable()}" group = mod_group_id @@ -84,12 +88,6 @@ neoForge { data { data() programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() - - /* - if (findProject(':SophisticatedCore') != null) { - modSource project(':SophisticatedCore').sourceSets.main - } - */ } } @@ -97,6 +95,11 @@ neoForge { "${mod_id}" { sourceSet(sourceSets.main) } + if (findProject(':SophisticatedCore') != null) { + "sophisticatedcore" { + sourceSet(project(':SophisticatedCore').sourceSets.main) + } + } } } diff --git a/gradle.properties b/gradle.properties index efdf2554..13224424 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ loader_version_range=[4,) mod_id=sophisticatedbackpacks mod_name=Sophisticated Backpacks mod_license=GNU General Public License v3.0 -mod_version=3.20.30 +mod_version=3.21.0 mod_group_id=sophisticatedbackpacks mod_authors=P3pp3rF1y, Ridanisaurus mod_description=Fancy and functional backpacks. @@ -34,7 +34,7 @@ chipped_cf_file_id=5506938 resourcefullib_cf_file_id=5483169 athena_cf_file_id=5431579 curios_cf_file_id=5546342 -sc_version=[1.21-1.0.5,1.22) +sc_version=[1.21-1.0.8,1.22) #publish curseforge_id=422301 diff --git a/src/generated/resources/data/sophisticatedbackpacks/advancement/recipes/misc/smithing_upgrade.json b/src/generated/resources/data/sophisticatedbackpacks/advancement/recipes/misc/smithing_upgrade.json new file mode 100644 index 00000000..ccd4c08a --- /dev/null +++ b/src/generated/resources/data/sophisticatedbackpacks/advancement/recipes/misc/smithing_upgrade.json @@ -0,0 +1,38 @@ +{ + "neoforge:conditions": [ + { + "type": "sophisticatedcore:item_enabled", + "itemRegistryName": "sophisticatedbackpacks:smithing_upgrade" + } + ], + "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_the_recipe", + "has_upgrade_base" + ] + ], + "rewards": { + "recipes": [ + "sophisticatedbackpacks:smithing_upgrade" + ] + } +} \ No newline at end of file diff --git a/src/generated/resources/data/sophisticatedbackpacks/recipe/smithing_upgrade.json b/src/generated/resources/data/sophisticatedbackpacks/recipe/smithing_upgrade.json new file mode 100644 index 00000000..bba8ecc3 --- /dev/null +++ b/src/generated/resources/data/sophisticatedbackpacks/recipe/smithing_upgrade.json @@ -0,0 +1,33 @@ +{ + "neoforge:conditions": [ + { + "type": "sophisticatedcore:item_enabled", + "itemRegistryName": "sophisticatedbackpacks:smithing_upgrade" + } + ], + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "B": { + "item": "sophisticatedbackpacks:upgrade_base" + }, + "C": { + "tag": "c:chests/wooden" + }, + "I": { + "tag": "c:ingots/iron" + }, + "S": { + "item": "minecraft:smithing_table" + } + }, + "pattern": [ + " S ", + "IBI", + " C " + ], + "result": { + "count": 1, + "id": "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 0463dd6c..01e1457c 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/data/SBPRecipeProvider.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/data/SBPRecipeProvider.java @@ -623,6 +623,17 @@ protected void buildRecipes(RecipeOutput recipeOutput) { .unlockedBy(HAS_UPGRADE_BASE, has(ModItems.UPGRADE_BASE.get())) .save(recipeOutput); + 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(recipeOutput); + new SmithingBackpackUpgradeRecipeBuilder(SmithingBackpackUpgradeRecipe::new, Ingredient.of(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE), Ingredient.of(ModItems.DIAMOND_BACKPACK.get()), Ingredient.of(Items.NETHERITE_INGOT), 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 70de5dbb..ef1625e0 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItems.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItems.java @@ -69,6 +69,9 @@ import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.refill.RefillUpgradeWrapper; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.restock.RestockUpgradeItem; 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.SmithingUpgradeWrapper; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper.ToolSwapperUpgradeContainer; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper.ToolSwapperUpgradeItem; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper.ToolSwapperUpgradeWrapper; @@ -223,6 +226,7 @@ private ModItems() { public static final DeferredHolder ADVANCED_PUMP_UPGRADE = ITEMS.register("advanced_pump_upgrade", () -> new PumpUpgradeItem(true, true, Config.SERVER.pumpUpgrade, Config.SERVER.maxUpgradesPerStorage)); public static final DeferredHolder XP_PUMP_UPGRADE = ITEMS.register("xp_pump_upgrade", () -> new XpPumpUpgradeItem(Config.SERVER.xpPumpUpgrade, Config.SERVER.maxUpgradesPerStorage)); public static final DeferredHolder ANVIL_UPGRADE = ITEMS.register("anvil_upgrade", AnvilUpgradeItem::new); + public static final DeferredHolder SMITHING_UPGRADE = ITEMS.register("smithing_upgrade", SmithingUpgradeItem::new); public static final Supplier UPGRADE_BASE = ITEMS.register("upgrade_base", () -> new ItemBase(new Item.Properties().stacksTo(16))); @@ -307,6 +311,7 @@ public static void registerHandlers(IEventBus modBus) { public static final UpgradeContainerType ADVANCED_PUMP_TYPE = new UpgradeContainerType<>(PumpUpgradeContainer::new); public static final UpgradeContainerType XP_PUMP_TYPE = new UpgradeContainerType<>(XpPumpUpgradeContainer::new); public 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(Registries.MENU)) { @@ -348,6 +353,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); } public static void registerDispenseBehavior() { diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItemsClient.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItemsClient.java index 0bfda8a1..1dbc1c74 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItemsClient.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/init/ModItemsClient.java @@ -16,6 +16,7 @@ import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.refill.RefillUpgradeTab; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.restock.RestockUpgradeTab; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.restock.RestockUpgradeWrapper; +import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing.SmithingUpgradeTab; import net.p3pp3rf1y.sophisticatedbackpacks.upgrades.toolswapper.ToolSwapperUpgradeTab; import net.p3pp3rf1y.sophisticatedcore.client.gui.StorageScreenBase; import net.p3pp3rf1y.sophisticatedcore.client.gui.UpgradeGuiManager; @@ -118,6 +119,7 @@ private static void onMenuScreenRegister(RegisterMenuScreensEvent event) { UpgradeGuiManager.registerTab(ModItems.XP_PUMP_TYPE, (XpPumpUpgradeContainer upgradeContainer, Position position, StorageScreenBase screen) -> new XpPumpUpgradeTab(upgradeContainer, position, screen, Config.SERVER.xpPumpUpgrade.mendingOn.get())); UpgradeGuiManager.registerTab(ModItems.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..b21553e1 --- /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 handlePacket(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..c89420f1 --- /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() / 2F, getTopY() + getHeight() - 10, 25.0F, + SmithingScreen.ARMOR_STAND_TRANSLATION, 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..2a720581 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeWrapper.java @@ -0,0 +1,49 @@ +package net.p3pp3rf1y.sophisticatedbackpacks.upgrades.smithing; + +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.items.ComponentItemHandler; +import net.p3pp3rf1y.sophisticatedcore.api.IStorageWrapper; +import net.p3pp3rf1y.sophisticatedcore.init.ModCoreDataComponents; +import net.p3pp3rf1y.sophisticatedcore.upgrades.UpgradeWrapperBase; + +import java.util.function.Consumer; + +public class SmithingUpgradeWrapper extends UpgradeWrapperBase { + private final ComponentItemHandler inventory; + + protected SmithingUpgradeWrapper(IStorageWrapper storageWrapper, ItemStack upgrade, Consumer upgradeSaveHandler) { + super(storageWrapper, upgrade, upgradeSaveHandler); + + inventory = new ComponentItemHandler(upgrade, DataComponents.CONTAINER, 3) { + @Override + protected void onContentsChanged(int slot, ItemStack oldStack, ItemStack newStack) { + super.onContentsChanged(slot, oldStack, newStack); + save(); + } + + @Override + public boolean isItemValid(int slot, ItemStack stack) { + return true; + } + }; + } + + public ComponentItemHandler getInventory() { + return inventory; + } + + @Override + public boolean canBeDisabled() { + return false; + } + + public boolean shouldShiftClickIntoStorage() { + return upgrade.getOrDefault(ModCoreDataComponents.SHIFT_CLICK_INTO_STORAGE, true); + } + + public void setShiftClickIntoStorage(boolean shiftClickIntoStorage) { + upgrade.set(ModCoreDataComponents.SHIFT_CLICK_INTO_STORAGE, 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 deb27054..bd77d8f6 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -13,4 +13,10 @@ public net.minecraft.world.item.RecordItem BY_NAME public net.minecraft.world.item.SpawnEggItem BY_ID public net.minecraft.client.renderer.entity.EntityRenderDispatcher renderers protected net.minecraft.world.inventory.ItemCombinerMenu createInputSlots(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V -protected net.minecraft.world.inventory.ItemCombinerMenu createContainer(I)Lnet/minecraft/world/SimpleContainer; \ No newline at end of file +protected net.minecraft.world.inventory.ItemCombinerMenu createContainer(I)Lnet/minecraft/world/SimpleContainer; +protected net.minecraft.world.inventory.ItemCombinerMenu createResultSlot(Lnet/minecraft/world/inventory/ItemCombinerMenuSlotDefinition;)V +public net.minecraft.client.gui.screens.inventory.SmithingScreen ARMOR_STAND_TRANSLATION +public net.minecraft.client.gui.screens.inventory.SmithingScreen ARMOR_STAND_ANGLE +public net.minecraft.client.gui.screens.inventory.SmithingScreen EMPTY_SLOT_SMITHING_TEMPLATES +public net.minecraft.client.gui.screens.inventory.SmithingScreen ERROR_TOOLTIP +public net.minecraft.client.gui.screens.inventory.SmithingScreen 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 84ec1f9f..6dba804a 100644 --- a/src/main/resources/assets/sophisticatedbackpacks/lang/en_us.json +++ b/src/main/resources/assets/sophisticatedbackpacks/lang/en_us.json @@ -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