-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
1272d21
commit 44e37f7
Showing
9 changed files
with
112 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# 3.1.0 | ||
|
||
- Cross platform support for Item inventories | ||
- Improved Item API | ||
- Added support for custom capabilities | ||
- | ||
- Support for entity capabilities (Item Container only for now while in testing) | ||
- New API format for containers (Feedback is welcome! For ItemApi only for now) |
2 changes: 1 addition & 1 deletion
2
...on/generic/util/AmountBasedContainer.java → ...n/generic/utils/AmountBasedContainer.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
2 changes: 1 addition & 1 deletion
2
...mon/generic/util/StackBasedContainer.java → ...on/generic/utils/StackBasedContainer.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
7 changes: 7 additions & 0 deletions
7
common/src/main/java/earth/terrarium/botarium/common/item/base/ItemContainerExtras.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,7 @@ | ||
package earth.terrarium.botarium.common.item.base; | ||
|
||
import net.minecraft.world.item.ItemStack; | ||
|
||
public interface ItemContainerExtras { | ||
void setStackInSlot(int slot, ItemStack stack); | ||
} |
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
78 changes: 78 additions & 0 deletions
78
common/src/main/java/earth/terrarium/botarium/common/item/utils/SlotItemContainer.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,78 @@ | ||
package earth.terrarium.botarium.common.item.utils; | ||
|
||
import earth.terrarium.botarium.common.item.base.ItemContainer; | ||
import earth.terrarium.botarium.common.item.base.ItemContainerExtras; | ||
import net.minecraft.world.Container; | ||
import net.minecraft.world.SimpleContainer; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SlotItemContainer<T extends ItemContainer & ItemContainerExtras> extends Slot { | ||
private static final Container EMPTY = new SimpleContainer(0); | ||
private final T container; | ||
|
||
public SlotItemContainer(T container, int slot, int x, int y) { | ||
super(EMPTY, slot, x, y); | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public boolean mayPlace(@NotNull ItemStack stack) { | ||
if (stack.isEmpty()) | ||
return false; | ||
return container.isItemValid(index, stack); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public ItemStack getItem() { | ||
return container.getStackInSlot(index); | ||
} | ||
|
||
// Override if your IItemHandler does not implement IItemHandlerModifiable | ||
@Override | ||
public void set(@NotNull ItemStack stack) { | ||
container.setStackInSlot(index, stack); | ||
this.setChanged(); | ||
} | ||
|
||
// Override if your IItemHandler does not implement IItemHandlerModifiable | ||
// @Override | ||
public void initialize(ItemStack stack) { | ||
container.setStackInSlot(index, stack); | ||
this.setChanged(); | ||
} | ||
|
||
@Override | ||
public void onQuickCraft(@NotNull ItemStack oldStackIn, @NotNull ItemStack newStackIn) { | ||
} | ||
|
||
@Override | ||
public int getMaxStackSize() { | ||
return container.getSlotLimit(this.index); | ||
} | ||
|
||
@Override | ||
public int getMaxStackSize(@NotNull ItemStack stack) { | ||
int maxInput = stack.getMaxStackSize(); | ||
ItemStack maxAdd = stack.copyWithCount(maxInput); | ||
ItemStack currentStack = container.getStackInSlot(index); | ||
container.setStackInSlot(index, ItemStack.EMPTY); | ||
ItemStack remainder = container.insertIntoSlot(index, maxAdd, true); | ||
container.setStackInSlot(index, currentStack); | ||
return maxInput - remainder.getCount(); | ||
} | ||
|
||
@Override | ||
public boolean mayPickup(Player playerIn) { | ||
return !container.extractFromSlot(index, 1, true).isEmpty(); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public ItemStack remove(int amount) { | ||
return container.extractFromSlot(index, amount, false); | ||
} | ||
} |
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