下面列出了怎么用net.minecraft.inventory.SidedInventory的API类实例代码及写法,或者点击链接到github查看源代码。
public <X> Mono<X> sbx$getComponent(WorldReader reader, Position position, BlockState state, Component<X> component, Mono<Direction> side) {
if (component == Components.INVENTORY_COMPONENT) {
if (this instanceof InventoryProvider) {
SidedInventory inventory = ((InventoryProvider) this).getInventory((net.minecraft.block.BlockState) state, (IWorld) reader, (BlockPos) position);
if (side.isPresent())
return Mono.of(new SidedRespective(inventory, side.get())).cast();
return Mono.of(new V2SInventory(inventory)).cast();
}
net.minecraft.block.entity.BlockEntity entity = ((BlockView) reader).getBlockEntity((BlockPos) position);
if (entity instanceof Inventory) {
if (side.isPresent() && entity instanceof SidedInventory)
return Mono.of(new SidedRespective((SidedInventory) entity, side.get())).cast();
return Mono.of(new V2SInventory((Inventory) entity)).cast();
}
}
if (component == Components.FLUID_COMPONENT) {
if (this instanceof Waterloggable) {
FluidLoggingContainer container = new FluidLoggingContainer((FluidLoggable) this, reader, position, state, side);
return Mono.of(container).cast();
}
}
return Mono.empty();
}
private static IntStream getAvailableSlots(Inventory inventory_1, Direction direction_1) {
return inventory_1 instanceof SidedInventory ? IntStream.of(((SidedInventory)inventory_1).getInvAvailableSlots(direction_1)) : IntStream.range(0, inventory_1.getInvSize());
}
public SidedRespective(SidedInventory inventory, Direction direction) {
super(inventory);
this.direction = direction;
this.inventory = inventory;
}