-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Added the Smithing Upgrade. It functions like a Smithing Tabl…
…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
Showing
15 changed files
with
560 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ated/resources/data/sophisticatedbackpacks/advancement/recipes/misc/smithing_upgrade.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/generated/resources/data/sophisticatedbackpacks/recipe/smithing_upgrade.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/smithing/SmithingUpgradeItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.