| 1 | package net.minecraft.world.ticks;
|
| 2 |
|
| 3 | import net.minecraft.world.Container;
|
| 4 | import net.minecraft.world.entity.player.Player;
|
| 5 | import net.minecraft.world.item.ItemStack;
|
| 6 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 7 |
|
| 8 | public interface ContainerSingleItem extends Container {
|
| 9 | ItemStack getTheItem();
|
| 10 |
|
| 11 | default ItemStack splitTheItem(final int count) {
|
| 12 | return this.getTheItem().split(count);
|
| 13 | }
|
| 14 |
|
| 15 | void setTheItem(final ItemStack itemStack);
|
| 16 |
|
| 17 | default ItemStack removeTheItem() {
|
| 18 | return this.splitTheItem(this.getMaxStackSize());
|
| 19 | }
|
| 20 |
|
| 21 | @Override
|
| 22 | default int getContainerSize() {
|
| 23 | return 1;
|
| 24 | }
|
| 25 |
|
| 26 | @Override
|
| 27 | default boolean isEmpty() {
|
| 28 | return this.getTheItem().isEmpty();
|
| 29 | }
|
| 30 |
|
| 31 | @Override
|
| 32 | default void clearContent() {
|
| 33 | this.removeTheItem();
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | default ItemStack removeItemNoUpdate(final int slot) {
|
| 38 | return this.removeItem(slot, this.getMaxStackSize());
|
| 39 | }
|
| 40 |
|
| 41 | @Override
|
| 42 | default ItemStack getItem(final int slot) {
|
| 43 | return slot == 0 ? this.getTheItem() : ItemStack.EMPTY;
|
| 44 | }
|
| 45 |
|
| 46 | @Override
|
| 47 | default ItemStack removeItem(final int slot, final int count) {
|
| 48 | return slot != 0 ? ItemStack.EMPTY : this.splitTheItem(count);
|
| 49 | }
|
| 50 |
|
| 51 | @Override
|
| 52 | default void setItem(final int slot, final ItemStack itemStack) {
|
| 53 | if (slot == 0) {
|
| 54 | this.setTheItem(itemStack);
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | interface BlockContainerSingleItem extends ContainerSingleItem {
|
| 59 | BlockEntity getContainerBlockEntity();
|
| 60 |
|
| 61 | @Override
|
| 62 | default boolean stillValid(final Player player) {
|
| 63 | return Container.stillValidBlockEntity(this.getContainerBlockEntity(), player);
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 |
|