Skip to content

Commit

Permalink
feat: ✨ Added the Smithing Upgrade. It functions like a Smithing Tabl…
Browse files Browse the repository at this point in the history
…e but in an upgrade slot. Unlike the Smithing Table, this upgrade retains its contents if you exit without completing the crafting.
  • Loading branch information
P3pp3rF1y committed Dec 30, 2024
1 parent 5ab5e53 commit 5ada685
Show file tree
Hide file tree
Showing 15 changed files with 560 additions and 9 deletions.
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ idea {
}
}

if (findProject(':SophisticatedCore') != null) {
evaluationDependsOn(':SophisticatedCore')
}

version = "${project.minecraft_version}-${project.mod_version}.${getBuildNumber()}${getStable()}"
group = mod_group_id

Expand Down Expand Up @@ -84,19 +88,18 @@ 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
}
*/
}
}

mods {
"${mod_id}" {
sourceSet(sourceSets.main)
}
if (findProject(':SophisticatedCore') != null) {
"sophisticatedcore" {
sourceSet(project(':SophisticatedCore').sourceSets.main)
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -223,6 +226,7 @@ private ModItems() {
public static final DeferredHolder<Item, PumpUpgradeItem> ADVANCED_PUMP_UPGRADE = ITEMS.register("advanced_pump_upgrade", () -> new PumpUpgradeItem(true, true, Config.SERVER.pumpUpgrade, Config.SERVER.maxUpgradesPerStorage));
public static final DeferredHolder<Item, XpPumpUpgradeItem> XP_PUMP_UPGRADE = ITEMS.register("xp_pump_upgrade", () -> new XpPumpUpgradeItem(Config.SERVER.xpPumpUpgrade, Config.SERVER.maxUpgradesPerStorage));
public static final DeferredHolder<Item, AnvilUpgradeItem> ANVIL_UPGRADE = ITEMS.register("anvil_upgrade", AnvilUpgradeItem::new);
public static final DeferredHolder<Item, SmithingUpgradeItem> SMITHING_UPGRADE = ITEMS.register("smithing_upgrade", SmithingUpgradeItem::new);

public static final Supplier<ItemBase> UPGRADE_BASE = ITEMS.register("upgrade_base", () -> new ItemBase(new Item.Properties().stacksTo(16)));

Expand Down Expand Up @@ -307,6 +311,7 @@ public static void registerHandlers(IEventBus modBus) {
public static final UpgradeContainerType<PumpUpgradeWrapper, PumpUpgradeContainer> ADVANCED_PUMP_TYPE = new UpgradeContainerType<>(PumpUpgradeContainer::new);
public static final UpgradeContainerType<XpPumpUpgradeWrapper, XpPumpUpgradeContainer> XP_PUMP_TYPE = new UpgradeContainerType<>(XpPumpUpgradeContainer::new);
public static final UpgradeContainerType<AnvilUpgradeWrapper, AnvilUpgradeContainer> ANVIL_TYPE = new UpgradeContainerType<>(AnvilUpgradeContainer::new);
public static final UpgradeContainerType<SmithingUpgradeWrapper, SmithingUpgradeContainer> SMITHING_TYPE = new UpgradeContainerType<>(SmithingUpgradeContainer::new);

public static void registerContainers(RegisterEvent event) {
if (!event.getRegistryKey().equals(Registries.MENU)) {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

}
}
Original file line number Diff line number Diff line change
@@ -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<SmithingUpgradeWrapper, SmithingUpgradeContainer> {
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<SmithingUpgradeWrapper, SmithingUpgradeContainer> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<SmithingUpgradeWrapper> {
private static final UpgradeType<SmithingUpgradeWrapper> TYPE = new UpgradeType<>(SmithingUpgradeWrapper::new);
public SmithingUpgradeItem() {
super(Config.SERVER.maxUpgradesPerStorage);
}

@Override
public UpgradeType<SmithingUpgradeWrapper> getType() {
return TYPE;
}

@Override
public List<UpgradeConflictDefinition> getUpgradeConflicts() {
return List.of();
}
}
Loading

0 comments on commit 5ada685

Please sign in to comment.