Container.java
net.minecraft.world.Container
信息
- 全限定名:net.minecraft.world.Container
- 类型:public interface
- 包:net.minecraft.world
- 源码路径:src/main/java/net/minecraft/world/Container.java
- 起始行号:L20
- 继承:Clearable, Iterable
, SlotProvider - 职责:
TODO
字段/常量
DEFAULT_DISTANCE_BUFFER- 类型:
float - 修饰符:
package-private - 源码定位:
L21 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.world.Container.ContainerIterator- 类型:
class - 修饰符:
public static - 源码定位:
L130 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
int getContainerSize() @ L23
- 方法名:getContainerSize
- 源码定位:L23
- 返回类型:int
- 修饰符:package-private
参数:
- 无
说明:
TODO
boolean isEmpty() @ L25
- 方法名:isEmpty
- 源码定位:L25
- 返回类型:boolean
- 修饰符:package-private
参数:
- 无
说明:
TODO
ItemStack getItem(int slot) @ L27
- 方法名:getItem
- 源码定位:L27
- 返回类型:ItemStack
- 修饰符:package-private
参数:
- slot: int
说明:
TODO
ItemStack removeItem(int slot, int count) @ L29
- 方法名:removeItem
- 源码定位:L29
- 返回类型:ItemStack
- 修饰符:package-private
参数:
- slot: int
- count: int
说明:
TODO
ItemStack removeItemNoUpdate(int slot) @ L31
- 方法名:removeItemNoUpdate
- 源码定位:L31
- 返回类型:ItemStack
- 修饰符:package-private
参数:
- slot: int
说明:
TODO
void setItem(int slot, ItemStack itemStack) @ L33
- 方法名:setItem
- 源码定位:L33
- 返回类型:void
- 修饰符:package-private
参数:
- slot: int
- itemStack: ItemStack
说明:
TODO
default int getMaxStackSize() @ L35
- 方法名:getMaxStackSize
- 源码定位:L35
- 返回类型:int
- 修饰符:default
参数:
- 无
说明:
TODO
default int getMaxStackSize(ItemStack itemStack) @ L39
- 方法名:getMaxStackSize
- 源码定位:L39
- 返回类型:int
- 修饰符:default
参数:
- itemStack: ItemStack
说明:
TODO
void setChanged() @ L43
- 方法名:setChanged
- 源码定位:L43
- 返回类型:void
- 修饰符:package-private
参数:
- 无
说明:
TODO
boolean stillValid(Player player) @ L45
- 方法名:stillValid
- 源码定位:L45
- 返回类型:boolean
- 修饰符:package-private
参数:
- player: Player
说明:
TODO
default void startOpen(ContainerUser containerUser) @ L47
- 方法名:startOpen
- 源码定位:L47
- 返回类型:void
- 修饰符:default
参数:
- containerUser: ContainerUser
说明:
TODO
default void stopOpen(ContainerUser containerUser) @ L50
- 方法名:stopOpen
- 源码定位:L50
- 返回类型:void
- 修饰符:default
参数:
- containerUser: ContainerUser
说明:
TODO
default List<ContainerUser> getEntitiesWithContainerOpen() @ L53
- 方法名:getEntitiesWithContainerOpen
- 源码定位:L53
- 返回类型:List
- 修饰符:default
参数:
- 无
说明:
TODO
default boolean canPlaceItem(int slot, ItemStack itemStack) @ L57
- 方法名:canPlaceItem
- 源码定位:L57
- 返回类型:boolean
- 修饰符:default
参数:
- slot: int
- itemStack: ItemStack
说明:
TODO
default boolean canTakeItem(Container into, int slot, ItemStack itemStack) @ L61
- 方法名:canTakeItem
- 源码定位:L61
- 返回类型:boolean
- 修饰符:default
参数:
- into: Container
- slot: int
- itemStack: ItemStack
说明:
TODO
default int countItem(Item item) @ L65
- 方法名:countItem
- 源码定位:L65
- 返回类型:int
- 修饰符:default
参数:
- item: Item
说明:
TODO
default boolean hasAnyOf(Set<Item> item) @ L77
- 方法名:hasAnyOf
- 源码定位:L77
- 返回类型:boolean
- 修饰符:default
参数:
- item: Set
说明:
TODO
default boolean hasAnyMatching(Predicate<ItemStack> predicate) @ L81
- 方法名:hasAnyMatching
- 源码定位:L81
- 返回类型:boolean
- 修饰符:default
参数:
- predicate: Predicate
说明:
TODO
static boolean stillValidBlockEntity(BlockEntity blockEntity, Player player) @ L91
- 方法名:stillValidBlockEntity
- 源码定位:L91
- 返回类型:boolean
- 修饰符:static
参数:
- blockEntity: BlockEntity
- player: Player
说明:
TODO
static boolean stillValidBlockEntity(BlockEntity blockEntity, Player player, float distanceBuffer) @ L95
- 方法名:stillValidBlockEntity
- 源码定位:L95
- 返回类型:boolean
- 修饰符:static
参数:
- blockEntity: BlockEntity
- player: Player
- distanceBuffer: float
说明:
TODO
default SlotAccess getSlot(int slot) @ L105
- 方法名:getSlot
- 源码定位:L105
- 返回类型:SlotAccess
- 修饰符:default
参数:
- slot: int
说明:
TODO
default Iterator<ItemStack> iterator() @ L125
- 方法名:iterator
- 源码定位:L125
- 返回类型:Iterator
- 修饰符:default
参数:
- 无
说明:
TODO
代码
public interface Container extends Clearable, Iterable<ItemStack>, SlotProvider {
float DEFAULT_DISTANCE_BUFFER = 4.0F;
int getContainerSize();
boolean isEmpty();
ItemStack getItem(int slot);
ItemStack removeItem(int slot, int count);
ItemStack removeItemNoUpdate(int slot);
void setItem(int slot, ItemStack itemStack);
default int getMaxStackSize() {
return 99;
}
default int getMaxStackSize(ItemStack itemStack) {
return Math.min(this.getMaxStackSize(), itemStack.getMaxStackSize());
}
void setChanged();
boolean stillValid(Player player);
default void startOpen(ContainerUser containerUser) {
}
default void stopOpen(ContainerUser containerUser) {
}
default List<ContainerUser> getEntitiesWithContainerOpen() {
return List.of();
}
default boolean canPlaceItem(int slot, ItemStack itemStack) {
return true;
}
default boolean canTakeItem(Container into, int slot, ItemStack itemStack) {
return true;
}
default int countItem(Item item) {
int count = 0;
for (ItemStack slotItem : this) {
if (slotItem.getItem().equals(item)) {
count += slotItem.getCount();
}
}
return count;
}
default boolean hasAnyOf(Set<Item> item) {
return this.hasAnyMatching(stack -> !stack.isEmpty() && item.contains(stack.getItem()));
}
default boolean hasAnyMatching(Predicate<ItemStack> predicate) {
for (ItemStack slotItem : this) {
if (predicate.test(slotItem)) {
return true;
}
}
return false;
}
static boolean stillValidBlockEntity(BlockEntity blockEntity, Player player) {
return stillValidBlockEntity(blockEntity, player, 4.0F);
}
static boolean stillValidBlockEntity(BlockEntity blockEntity, Player player, float distanceBuffer) {
Level level = blockEntity.getLevel();
BlockPos worldPosition = blockEntity.getBlockPos();
if (level == null) {
return false;
} else {
return level.getBlockEntity(worldPosition) != blockEntity ? false : player.isWithinBlockInteractionRange(worldPosition, distanceBuffer);
}
}
@Override
default @Nullable SlotAccess getSlot(int slot) {
return slot >= 0 && slot < this.getContainerSize() ? new SlotAccess() {
{
Objects.requireNonNull(Container.this);
}
@Override
public ItemStack get() {
return Container.this.getItem(slot);
}
@Override
public boolean set(ItemStack itemStack) {
Container.this.setItem(slot, itemStack);
return true;
}
} : null;
}
@Override
default Iterator<ItemStack> iterator() {
return new Container.ContainerIterator(this);
}
public static class ContainerIterator implements Iterator<ItemStack> {
private final Container container;
private int index;
private final int size;
public ContainerIterator(Container container) {
this.container = container;
this.size = container.getContainerSize();
}
@Override
public boolean hasNext() {
return this.index < this.size;
}
public ItemStack next() {
if (!this.hasNext()) {
throw new NoSuchElementException();
} else {
return this.container.getItem(this.index++);
}
}
}
}引用的其他类
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
构造调用/返回值 - 关联成员:
SlotAccess()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/继承/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置: