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 5d76fb8 commit 9313735
Show file tree
Hide file tree
Showing 14 changed files with 540 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,17 @@ protected void buildRecipes(Consumer<FinishedRecipe> 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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -241,6 +245,7 @@ private ModItems() {
public static final RegistryObject<PumpUpgradeItem> ADVANCED_PUMP_UPGRADE = ITEMS.register("advanced_pump_upgrade", () -> new PumpUpgradeItem(true, true, Config.SERVER.pumpUpgrade, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<XpPumpUpgradeItem> XP_PUMP_UPGRADE = ITEMS.register("xp_pump_upgrade", () -> new XpPumpUpgradeItem(Config.SERVER.xpPumpUpgrade, Config.SERVER.maxUpgradesPerStorage));
public static final RegistryObject<AnvilUpgradeItem> ANVIL_UPGRADE = ITEMS.register("anvil_upgrade", AnvilUpgradeItem::new);
public static final RegistryObject<SmithingUpgradeItem> SMITHING_UPGRADE = ITEMS.register("smithing_upgrade", SmithingUpgradeItem::new);

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

Expand Down Expand Up @@ -323,6 +328,7 @@ private static void onResourceReload(AddReloadListenerEvent event) {
private static final UpgradeContainerType<PumpUpgradeWrapper, PumpUpgradeContainer> ADVANCED_PUMP_TYPE = new UpgradeContainerType<>(PumpUpgradeContainer::new);
private static final UpgradeContainerType<XpPumpUpgradeWrapper, XpPumpUpgradeContainer> XP_PUMP_TYPE = new UpgradeContainerType<>(XpPumpUpgradeContainer::new);
private 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(ForgeRegistries.Keys.MENU_TYPES)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
}

Expand Down
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 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();
}
}
}
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 9313735

Please sign in to comment.