Skip to content

Commit

Permalink
Everything works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed May 11, 2024
1 parent 817e610 commit 2990773
Show file tree
Hide file tree
Showing 19 changed files with 346 additions and 84 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ java {
// These can be tweaked, removed, or duplicated as needed.
runs {
// applies to all the run configs below
configureEach {
configureEach { net.neoforged.gradle.dsl.common.runs.run.Run run ->
// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
Expand All @@ -86,9 +86,9 @@ runs {
modSource project.sourceSets.main

//if the selected toolchain is a JBR, enable DCEVM
//if (run.project.javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse("").contains("JetBrains")) {
// run.jvmArgument("-XX:+AllowEnhancedClassRedefinition")
//}
if (run.project.javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse("").contains("JetBrains")) {
run.jvmArgument("-XX:+AllowEnhancedClassRedefinition")
}
}

client {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.6 2024-05-11T13:25:30.0411425 Languages: en_us for mod: mininggadgets
e818e2aea1f0fc0b2317b97b5679d8eebc239abb assets/mininggadgets/lang/en_us.json
// 1.20.6 2024-05-11T13:50:02.2019011 Languages: en_us for mod: mininggadgets
de5afda06eece1f64a4df1a2f3fd029bcc802b1b assets/mininggadgets/lang/en_us.json
4 changes: 2 additions & 2 deletions src/generated/resources/assets/mininggadgets/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"mininggadgets.tooltip.item.upgrades": "Current Upgrades:",
"mininggadgets.tooltip.item.use_cost": "+%1$d FE per use",
"mininggadgets.tooltip.screen.beam_preview": "Beam preview",
"mininggadgets.tooltip.screen.blacklist": "Blacklist active",
"mininggadgets.tooltip.screen.blacklist": "Destroy List",
"mininggadgets.tooltip.screen.block_break_style": "Breaking Style",
"mininggadgets.tooltip.screen.blue": "Blue",
"mininggadgets.tooltip.screen.delay_explain": "Controls how often a freeze particle is spawned\nby default it is one particle every tick, to reduce\nthe amount of particles add more delay",
Expand All @@ -68,7 +68,7 @@
"mininggadgets.tooltip.screen.visual_settings": "Visual Settings",
"mininggadgets.tooltip.screen.visuals_menu": "Edit Visuals",
"mininggadgets.tooltip.screen.volume": "Volume",
"mininggadgets.tooltip.screen.whitelist": "Whitelist active",
"mininggadgets.tooltip.screen.whitelist": "Keep List",
"mininggadgets.tooltip.single.filters": "Filters",
"mininggadgets.tooltip.single.insert": "Insert",
"mininggadgets.upgrade.replacement": "Upgrade: ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.direwolf20.mininggadgets.client.screens.ModificationTableScreen;
import com.direwolf20.mininggadgets.common.MiningGadgets;
import com.direwolf20.mininggadgets.common.items.MiningGadget;
import com.direwolf20.mininggadgets.common.util.MGDataComponents;
import com.direwolf20.mininggadgets.setup.Config;
import com.direwolf20.mininggadgets.setup.MGDataComponents;
import com.direwolf20.mininggadgets.setup.Registration;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.direwolf20.mininggadgets.common.capabilities;

import com.direwolf20.mininggadgets.common.util.MGDataComponents;
import com.direwolf20.mininggadgets.setup.MGDataComponents;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.Tag;
Expand All @@ -11,7 +11,7 @@ public class EnergyStorageItemstack extends EnergyStorage {
protected final ItemStack itemStack;

public EnergyStorageItemstack(int capacity, ItemStack itemStack) {
super(capacity, capacity, capacity, 0);
super(getMaxCapacity(itemStack, capacity), Integer.MAX_VALUE, Integer.MAX_VALUE);
this.itemStack = itemStack;
this.energy = itemStack.getOrDefault(MGDataComponents.FORGE_ENERGY, 0);
}
Expand All @@ -21,6 +21,10 @@ public void setEnergy(int energy) {
itemStack.set(MGDataComponents.FORGE_ENERGY, energy);
}

private static int getMaxCapacity(ItemStack stack, int capacity) {
return stack.getOrDefault(MGDataComponents.FORGE_ENERGY_MAX_ENERGY, capacity);
}

public void updatedMaxEnergy(int max) {
itemStack.set(MGDataComponents.FORGE_ENERGY_MAX_ENERGY, max);
this.capacity = max;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package com.direwolf20.mininggadgets.common.containers;

import com.direwolf20.mininggadgets.common.containers.handlers.DataComponentHandler;
import com.direwolf20.mininggadgets.common.items.MiningGadget;
import com.direwolf20.mininggadgets.common.items.UpgradeCard;
import com.direwolf20.mininggadgets.setup.Registration;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.ItemStackHandler;
import net.neoforged.neoforge.items.SlotItemHandler;
import net.neoforged.neoforge.items.wrapper.InvWrapper;


public class FilterContainer extends AbstractContainerMenu {
public FilterContainer(int windowId, Inventory playerInventory, FriendlyByteBuf extraData) {
this(windowId, playerInventory, new ItemStackHandler(30));
public FilterContainer(int windowId, Inventory playerInventory, RegistryFriendlyByteBuf extraData) {
this(windowId, playerInventory, new DataComponentHandler(ItemStack.OPTIONAL_STREAM_CODEC.decode(extraData), 30));

}

public FilterContainer(int windowId, Inventory playerInventory, IItemHandler ghostInventory) {
public FilterContainer(int windowId, Inventory playerInventory, DataComponentHandler ghostInventory) {
super(Registration.FILTER_CONTAINER.get(), windowId);
this.setup(new InvWrapper(playerInventory), ghostInventory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public static boolean insertButton(ModificationTableContainer container, ItemSta
boolean hasFortune = UpgradeTools.containsUpgradeFromList(upgrades, Upgrade.FORTUNE_1);
boolean hasSilk = UpgradeTools.containsUpgradeFromList(upgrades, Upgrade.SILK);

if (UpgradeTools.containsUpgrade(laser, card))
return false;

// Did we just insert a Range upgrade?
if (card.getBaseName().equals(Upgrade.RANGE_1.getBaseName())) {
// Always reset the range regardless if it's bigger or smaller
Expand All @@ -45,9 +48,6 @@ public static boolean insertButton(ModificationTableContainer container, ItemSta
MiningProperties.setMaxMiningRange(laser, UpgradeTools.getMaxMiningRange(card.getTier()));
}

if (UpgradeTools.containsUpgrade(laser, card))
return false;

if (hasFortune && card.getBaseName().equals(Upgrade.SILK.getBaseName()) || hasSilk && card.getBaseName().equals(Upgrade.FORTUNE_1.getBaseName()))
((UpgradeCard) upgrade.getItem()).getUpgrade().setEnabled(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
public class ModificationTableHandler extends ItemStackHandler {
ModificationTableTileEntity blockEntity;

public ModificationTableHandler(int size) {
super(size);
}

public ModificationTableHandler(int size, ModificationTableTileEntity blockEntity) {
super(size);
this.blockEntity = blockEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.direwolf20.mininggadgets.common.containers.handlers;

import com.direwolf20.mininggadgets.setup.MGDataComponents;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandlerModifiable;

public class DataComponentHandler implements IItemHandlerModifiable {
private final ItemStack stack;
private final int size;

public DataComponentHandler(ItemStack stack, int size) {
this.stack = stack;
this.size = size;
}

@Override
public int getSlots() {
return size;
}

@Override
public ItemStack getStackInSlot(int slot) {
validateSlotIndex(slot);
if (getItemList().size() < slot + 1)
return ItemStack.EMPTY;
return getItemList().get(slot);
}

@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (stack.isEmpty())
return ItemStack.EMPTY;

if (!isItemValid(slot, stack))
return stack;

validateSlotIndex(slot);

NonNullList<ItemStack> itemStacks = getItemList();

ItemStack existing = itemStacks.get(slot);

int limit = Math.min(getSlotLimit(slot), stack.getMaxStackSize());

if (!existing.isEmpty()) {
if (!ItemStack.isSameItemSameComponents(stack, existing))
return stack;

limit -= existing.getCount();
}

if (limit <= 0)
return stack;

boolean reachedLimit = stack.getCount() > limit;

if (!simulate) {
if (existing.isEmpty()) {
itemStacks.set(slot, reachedLimit ? stack.copyWithCount(limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
}
setItemList(itemStacks);
}

return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY;
}

@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
NonNullList<ItemStack> itemStacks = getItemList();
if (amount == 0)
return ItemStack.EMPTY;

validateSlotIndex(slot);

ItemStack existing = itemStacks.get(slot);

if (existing.isEmpty())
return ItemStack.EMPTY;

int toExtract = Math.min(amount, existing.getMaxStackSize());

if (existing.getCount() <= toExtract) {
if (!simulate) {
itemStacks.set(slot, ItemStack.EMPTY);
setItemList(itemStacks);
return existing;
} else {
return existing.copy();
}
} else {
if (!simulate) {
itemStacks.set(slot, existing.copyWithCount(existing.getCount() - toExtract));
setItemList(itemStacks);
}

return existing.copyWithCount(toExtract);
}
}

private void validateSlotIndex(int slot) {
if (slot < 0 || slot >= getSlots())
throw new RuntimeException("Slot " + slot + " not in valid range - [0," + getSlots() + ")");
}

@Override
public int getSlotLimit(int slot) {
return 64;
}

@Override
public boolean isItemValid(int slot, ItemStack stack) {
return stack.getItem().canFitInsideContainerItems();
}

@Override
public void setStackInSlot(int slot, ItemStack stack) {
validateSlotIndex(slot);
if (!stack.isEmpty() && !isItemValid(slot, stack))
throw new RuntimeException("Invalid stack " + stack + " for slot " + slot + ")");
NonNullList<ItemStack> itemStacks = getItemList();
itemStacks.set(slot, stack);
setItemList(itemStacks);
}

private NonNullList<ItemStack> getItemList() {
DireItemContainerContents contents = this.stack.getOrDefault(MGDataComponents.ITEMSTACK_HANDLER, DireItemContainerContents.fromItems(NonNullList.withSize(size, ItemStack.EMPTY)));
NonNullList<ItemStack> list = NonNullList.withSize(size, ItemStack.EMPTY);
contents.copyInto(list);
return list;
}

private void setItemList(NonNullList<ItemStack> itemStacks) {
this.stack.set(MGDataComponents.ITEMSTACK_HANDLER, DireItemContainerContents.fromItems(itemStacks));
}
}
Loading

0 comments on commit 2990773

Please sign in to comment.