generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b24b8f
commit 12f854a
Showing
12 changed files
with
194 additions
and
20 deletions.
There are no files selected for viewing
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.21.1 2024-09-07T23:32:11.7388079 Languages: en_us for mod: justdirethings | ||
6df045e49de32b41b0c0ae7b9f14dbd59d6042d3 assets/justdirethings/lang/en_us.json | ||
// 1.21.1 2024-09-08T10:48:40.1210526 Languages: en_us for mod: justdirethings | ||
d5878f400337646026ccd4b5a26fd0191197b510 assets/justdirethings/lang/en_us.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
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
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
99 changes: 99 additions & 0 deletions
99
...in/java/com/direwolf20/justdirethings/common/capabilities/InventoryHolderItemHandler.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,99 @@ | ||
package com.direwolf20.justdirethings.common.capabilities; | ||
|
||
import com.direwolf20.justdirethings.common.blockentities.InventoryHolderBE; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.neoforge.items.ItemStackHandler; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class InventoryHolderItemHandler extends ItemStackHandler { | ||
InventoryHolderBE inventoryHolderBE; | ||
ItemStackHandler sourceHandler; | ||
|
||
public InventoryHolderItemHandler(InventoryHolderBE inventoryHolderBE, ItemStackHandler sourceHandler) { | ||
super(sourceHandler.getSlots()); | ||
this.inventoryHolderBE = inventoryHolderBE; | ||
this.sourceHandler = sourceHandler; | ||
} | ||
|
||
@Override | ||
public ItemStack extractItem(int slot, int amount, boolean simulate) { | ||
if (inventoryHolderBE == null) return ItemStack.EMPTY; | ||
int amountAllowed = inventoryHolderBE.allowedExtractAmount(slot, amount); | ||
return sourceHandler.extractItem(slot, amountAllowed, simulate); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { | ||
if (stack.isEmpty()) | ||
return ItemStack.EMPTY; | ||
|
||
if (!isItemValid(slot, stack)) | ||
return stack; | ||
|
||
validateSlotIndex(slot); | ||
|
||
ItemStack existing = sourceHandler.getStackInSlot(slot); | ||
|
||
int limit = getStackLimit(slot, stack); | ||
|
||
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()) { | ||
sourceHandler.setStackInSlot(slot, reachedLimit ? stack.copyWithCount(limit) : stack); | ||
} else { | ||
existing.grow(reachedLimit ? limit : stack.getCount()); | ||
} | ||
onContentsChanged(slot); | ||
} | ||
|
||
return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY; | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(int slot, ItemStack itemStack) { | ||
if (inventoryHolderBE == null) return false; | ||
if (inventoryHolderBE.automatedFiltersOnly) | ||
return inventoryHolderBE.isStackValidFilter(itemStack, slot); | ||
return sourceHandler.isItemValid(slot, itemStack); | ||
} | ||
|
||
@Override | ||
public int getSlotLimit(int slot) { | ||
if (inventoryHolderBE == null) return 0; | ||
int allowedAmt = inventoryHolderBE.getSlotLimit(slot); | ||
if (allowedAmt == -1) | ||
return Item.ABSOLUTE_MAX_STACK_SIZE; | ||
return allowedAmt; | ||
} | ||
|
||
@Override | ||
protected int getStackLimit(int slot, ItemStack stack) { | ||
if (inventoryHolderBE == null) return 0; | ||
int allowedAmt = inventoryHolderBE.getSlotLimit(slot); | ||
if (allowedAmt == -1) | ||
return Math.min(getSlotLimit(slot), stack.getMaxStackSize()); | ||
return Math.min(allowedAmt, stack.getMaxStackSize()); | ||
} | ||
|
||
@Override | ||
public int getSlots() { | ||
return sourceHandler.getSlots(); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack getStackInSlot(int i) { | ||
return sourceHandler.getStackInSlot(i); | ||
} | ||
} |
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
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