generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Pocket Generator work, it saves items
- Loading branch information
1 parent
d61559a
commit 97ab83a
Showing
19 changed files
with
389 additions
and
5 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
src/generated/resources/.cache/69ee5e809dff011efe049b68501078221ca37cb0
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// 1.20.4 2024-02-17T22:37:21.9268029 Item Models: justdirethings | ||
// 1.20.4 2024-02-18T21:20:13.5012113 Item Models: justdirethings | ||
af62c31381c904f86fde9370e374e01d828fa643 assets/justdirethings/models/item/fuel_canister.json | ||
3f50e98f22d6abc6b3edab6c01b82deec145ec78 assets/justdirethings/models/item/pocket_generator.json |
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/8202586f691eec5ad0bb88d13a278951d0c130fb
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.20.4 2024-02-18T14:01:33.7129519 Languages: en_us for mod: justdirethings | ||
1155dbc06ee9cdfaaa0dea410bbeb38a8ed5d4c3 assets/justdirethings/lang/en_us.json | ||
// 1.20.4 2024-02-18T21:20:13.5032131 Languages: en_us for mod: justdirethings | ||
cc984028f4791799fac03e23e3e9217d5d527b36 assets/justdirethings/lang/en_us.json |
4 changes: 3 additions & 1 deletion
4
src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// 1.20.4 2024-02-17T22:37:21.9338085 Recipes | ||
// 1.20.4 2024-02-18T21:20:13.5042139 Recipes | ||
08a464b9106de5bf0e3d81194dc205ed42ef7db4 data/justdirethings/advancements/recipes/misc/fuel_canister.json | ||
591f2dd8d997ccead841061e70aedc4a4984a60d data/justdirethings/advancements/recipes/misc/pocket_generator.json | ||
be43fb76c8ff5e0964f378abece4cf4d77ecd06e data/justdirethings/recipes/fuel_canister.json | ||
5b4bd1dbd73529cb2521bec1dbc1f1786fb47281 data/justdirethings/recipes/pocket_generator.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
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/justdirethings/models/item/pocket_generator.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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "justdirethings:item/pocketgenerator" | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/generated/resources/data/justdirethings/advancements/recipes/misc/pocket_generator.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,34 @@ | ||
{ | ||
"parent": "minecraft:recipes/root", | ||
"criteria": { | ||
"has_fuel_canister": { | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"items": [ | ||
"justdirethings:fuel_canister" | ||
] | ||
} | ||
] | ||
}, | ||
"trigger": "minecraft:inventory_changed" | ||
}, | ||
"has_the_recipe": { | ||
"conditions": { | ||
"recipe": "justdirethings:pocket_generator" | ||
}, | ||
"trigger": "minecraft:recipe_unlocked" | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"has_the_recipe", | ||
"has_fuel_canister" | ||
] | ||
], | ||
"rewards": { | ||
"recipes": [ | ||
"justdirethings:pocket_generator" | ||
] | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/generated/resources/data/justdirethings/recipes/pocket_generator.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,27 @@ | ||
{ | ||
"type": "minecraft:crafting_shaped", | ||
"category": "misc", | ||
"group": "justdirethings", | ||
"key": { | ||
"c": { | ||
"item": "minecraft:coal" | ||
}, | ||
"f": { | ||
"item": "justdirethings:fuel_canister" | ||
}, | ||
"i": { | ||
"tag": "forge:ingots/iron" | ||
}, | ||
"r": { | ||
"tag": "forge:dusts/redstone" | ||
} | ||
}, | ||
"pattern": [ | ||
"ici", | ||
"rfr", | ||
"ici" | ||
], | ||
"result": { | ||
"item": "justdirethings:pocket_generator" | ||
} | ||
} |
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
125 changes: 125 additions & 0 deletions
125
src/main/java/com/direwolf20/justdirethings/client/screens/PocketGeneratorScreen.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,125 @@ | ||
package com.direwolf20.justdirethings.client.screens; | ||
|
||
import com.direwolf20.justdirethings.JustDireThings; | ||
import com.direwolf20.justdirethings.common.containers.PocketGeneratorContainer; | ||
import com.mojang.blaze3d.platform.InputConstants; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public class PocketGeneratorScreen extends AbstractContainerScreen<PocketGeneratorContainer> { | ||
private final ResourceLocation GUI = new ResourceLocation(JustDireThings.MODID, "textures/gui/pocketgenerator.png"); | ||
|
||
protected final PocketGeneratorContainer container; | ||
private ItemStack pocketGenerator; | ||
|
||
public PocketGeneratorScreen(PocketGeneratorContainer container, Inventory inv, Component name) { | ||
super(container, inv, name); | ||
this.container = container; | ||
this.pocketGenerator = container.pocketGeneratorItemStack; | ||
} | ||
|
||
@Override | ||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { | ||
super.render(guiGraphics, mouseX, mouseY, partialTicks); | ||
this.renderTooltip(guiGraphics, mouseX, mouseY); | ||
/*MutableComponent msg = Component.translatable("justdirethings.fuelcanisteritemsamt", MagicHelpers.formatted((float) FuelCanister.getFuelLevel(pocketGenerator) / 200)); | ||
guiGraphics.drawString(font, msg, this.getGuiLeft() + this.imageWidth / 2 - font.width(msg) / 2, getGuiTop() + 5, Color.DARK_GRAY.getRGB(), false); | ||
msg = Component.translatable("justdirethings.fuelcanisteramt", MagicHelpers.formatted(FuelCanister.getFuelLevel(pocketGenerator))); | ||
guiGraphics.drawString(font, msg, (this.getGuiLeft() + this.imageWidth / 2) - font.width(msg) / 2, getGuiTop() + 15, Color.DARK_GRAY.getRGB(), false);*/ | ||
} | ||
|
||
@Override | ||
protected void renderTooltip(GuiGraphics pGuiGraphics, int pX, int pY) { | ||
super.renderTooltip(pGuiGraphics, pX, pY); | ||
/*if (this.menu.getCarried().isEmpty() && this.hoveredSlot != null && this.hoveredSlot.hasItem()) { | ||
ItemStack itemstack = this.hoveredSlot.getItem(); | ||
int fuelPerPiece = CommonHooks.getBurnTime(itemstack, RecipeType.SMELTING); | ||
List<Component> tooltip = this.getTooltipFromContainerItem(itemstack); | ||
if (container.handler.isItemValid(0, itemstack)) { | ||
if (hasShiftDown()) { | ||
tooltip.add(Component.translatable("justdirethings.fuelcanisteramt", MagicHelpers.formatted(fuelPerPiece)).withStyle(ChatFormatting.AQUA)); | ||
tooltip.add(Component.translatable("justdirethings.fuelcanisteramtstack", MagicHelpers.formatted(fuelPerPiece * itemstack.getCount())).withStyle(ChatFormatting.AQUA)); | ||
} else { | ||
tooltip.add(Component.translatable("justdirethings.fuelcanisteritemsamt", MagicHelpers.formatted((float) fuelPerPiece / 200)).withStyle(ChatFormatting.AQUA)); | ||
tooltip.add(Component.translatable("justdirethings.fuelcanisteritemsamtstack", MagicHelpers.formatted((float) (fuelPerPiece * itemstack.getCount()) / 200)).withStyle(ChatFormatting.AQUA)); | ||
} | ||
} | ||
pGuiGraphics.renderTooltip(this.font, tooltip, itemstack.getTooltipImage(), itemstack, pX, pY); | ||
}*/ | ||
} | ||
|
||
@Override | ||
protected void renderSlot(GuiGraphics pGuiGraphics, Slot pSlot) { | ||
super.renderSlot(pGuiGraphics, pSlot); | ||
if (!pSlot.getItem().isEmpty() && !container.handler.isItemValid(pSlot.getSlotIndex(), pSlot.getItem())) | ||
pGuiGraphics.fill(RenderType.guiOverlay(), pSlot.x, pSlot.y, pSlot.x + 16, pSlot.y + Mth.ceil(16.0F), 0x7FFF0000); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
super.init(); | ||
} | ||
|
||
@Override | ||
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) { | ||
super.renderLabels(guiGraphics, mouseX, mouseY); | ||
} | ||
|
||
@Override | ||
protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) { | ||
RenderSystem.setShaderTexture(0, GUI); | ||
int relX = (this.width - this.imageWidth) / 2; | ||
int relY = (this.height - this.imageHeight) / 2; | ||
guiGraphics.blit(GUI, relX, relY, 0, 0, this.imageWidth, this.imageHeight); | ||
} | ||
|
||
@Override | ||
public boolean isPauseScreen() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onClose() { | ||
super.onClose(); | ||
} | ||
|
||
@Override | ||
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { | ||
InputConstants.Key mouseKey = InputConstants.getKey(p_keyPressed_1_, p_keyPressed_2_); | ||
if (p_keyPressed_1_ == 256 || minecraft.options.keyInventory.isActiveAndMatches(mouseKey)) { | ||
onClose(); | ||
|
||
return true; | ||
} | ||
|
||
return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double x, double y, int btn) { | ||
return super.mouseClicked(x, y, btn); | ||
} | ||
|
||
public boolean mouseReleased(double p_mouseReleased_1_, double p_mouseReleased_3_, int p_mouseReleased_5_) { | ||
return super.mouseReleased(p_mouseReleased_1_, p_mouseReleased_3_, p_mouseReleased_5_); | ||
} | ||
|
||
@Override | ||
public boolean mouseScrolled(double mouseX, double mouseY, double pScrollX, double pScrollY) { | ||
return super.mouseScrolled(mouseX, mouseY, pScrollX, pScrollY); | ||
} | ||
|
||
private static MutableComponent getTrans(String key, Object... args) { | ||
return Component.translatable(JustDireThings.MODID + "." + key, args); | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/direwolf20/justdirethings/common/containers/PocketGeneratorContainer.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,77 @@ | ||
package com.direwolf20.justdirethings.common.containers; | ||
|
||
import com.direwolf20.justdirethings.common.items.PocketGenerator; | ||
import com.direwolf20.justdirethings.setup.Registration; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.neoforge.items.ItemStackHandler; | ||
|
||
public class PocketGeneratorContainer extends BaseContainer { | ||
public static final int SLOTS = 1; | ||
public ItemStackHandler handler; | ||
public ItemStack pocketGeneratorItemStack; | ||
public Player playerEntity; | ||
|
||
public PocketGeneratorContainer(int windowId, Inventory playerInventory, Player player, FriendlyByteBuf extraData) { | ||
this(windowId, playerInventory, player, extraData.readItem()); | ||
} | ||
|
||
public PocketGeneratorContainer(int windowId, Inventory playerInventory, Player player, ItemStack pocketGenerator) { | ||
super(Registration.PocketGenerator_Container.get(), windowId); | ||
playerEntity = player; | ||
if (pocketGenerator.getItem() instanceof PocketGenerator pocketGeneratorItem) | ||
this.handler = pocketGeneratorItem.getStackHandler(pocketGenerator); | ||
else | ||
this.handler = new ItemStackHandler(SLOTS); | ||
this.pocketGeneratorItemStack = pocketGenerator; | ||
if (handler != null) | ||
addSlotRange(handler, 0, 80, 35, 1, 18); | ||
|
||
addPlayerSlots(playerInventory, 8, 84); | ||
} | ||
|
||
@Override | ||
public boolean stillValid(Player playerIn) { | ||
return playerIn.getMainHandItem().equals(pocketGeneratorItemStack); | ||
} | ||
|
||
@Override | ||
public ItemStack quickMoveStack(Player playerIn, int index) { | ||
ItemStack itemstack = ItemStack.EMPTY; | ||
Slot slot = this.slots.get(index); | ||
if (slot.hasItem()) { | ||
ItemStack currentStack = slot.getItem(); | ||
if (index < SLOTS) { //Slot to Player Inventory | ||
if (!this.moveItemStackTo(currentStack, SLOTS, Inventory.INVENTORY_SIZE + SLOTS, true)) { | ||
return ItemStack.EMPTY; | ||
} | ||
} | ||
if (index >= SLOTS) { //Player Inventory to Slots | ||
if (!this.moveItemStackTo(currentStack, 0, SLOTS, false)) { | ||
return ItemStack.EMPTY; | ||
} | ||
} | ||
|
||
if (currentStack.isEmpty()) { | ||
slot.set(ItemStack.EMPTY); | ||
} else { | ||
slot.setChanged(); | ||
} | ||
|
||
if (currentStack.getCount() == itemstack.getCount()) { | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
slot.onTake(playerIn, currentStack); | ||
} | ||
return itemstack; | ||
} | ||
|
||
@Override | ||
public void removed(Player playerIn) { | ||
super.removed(playerIn); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...java/com/direwolf20/justdirethings/common/containers/handlers/PocketGeneratorHandler.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,27 @@ | ||
package com.direwolf20.justdirethings.common.containers.handlers; | ||
|
||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.RecipeType; | ||
import net.neoforged.neoforge.common.CommonHooks; | ||
import net.neoforged.neoforge.items.ItemStackHandler; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class PocketGeneratorHandler extends ItemStackHandler { | ||
public ItemStack stack; | ||
|
||
public PocketGeneratorHandler(int size, ItemStack itemStack) { | ||
super(size); | ||
this.stack = itemStack; | ||
} | ||
|
||
@Override | ||
protected void onContentsChanged(int slot) { | ||
super.onContentsChanged(slot); | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(int slot, @Nonnull ItemStack stack) { | ||
return CommonHooks.getBurnTime(stack, RecipeType.SMELTING) > 0; //Todo Test Lava bucket | ||
} | ||
} |
Oops, something went wrong.