添加todo
This commit is contained in:
parent
f8d0c2e886
commit
7ca2d3e268
1 changed files with 75 additions and 1 deletions
|
@ -2,22 +2,27 @@ package com.atsuishio.superbwarfare.block.entity;
|
|||
|
||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.WorldlyContainer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.HopperBlock;
|
||||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
|
||||
|
||||
|
@ -37,10 +42,79 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
|
|||
blockEntity.tickedGameTime = level.getGameTime();
|
||||
if (!blockEntity.isOnCooldown()) {
|
||||
blockEntity.setCooldown(0);
|
||||
// tryMoveItems(pLevel, pPos, pState, pBlockEntity, () -> suckInItems(pLevel, pBlockEntity));
|
||||
// tryMoveItems(level, pos, state, blockEntity, () -> suckInItems(level, blockEntity));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean tryMoveItems(Level pLevel, BlockPos pPos, BlockState pState, SuperbItemInterfaceBlockEntity pBlockEntity, BooleanSupplier pValidator) {
|
||||
if (!pLevel.isClientSide) {
|
||||
if (!pBlockEntity.isOnCooldown() && pState.getValue(HopperBlock.ENABLED)) {
|
||||
boolean flag = false;
|
||||
if (!pBlockEntity.isEmpty()) {
|
||||
flag = ejectItems(pLevel, pPos, pState, pBlockEntity);
|
||||
}
|
||||
|
||||
if (!pBlockEntity.inventoryFull()) {
|
||||
flag |= pValidator.getAsBoolean();
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
pBlockEntity.setCooldown(8);
|
||||
setChanged(pLevel, pPos, pState);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean ejectItems(Level pLevel, BlockPos pPos, BlockState pState, SuperbItemInterfaceBlockEntity pSourceContainer) {
|
||||
// if (net.minecraftforge.items.VanillaInventoryCodeHooks.insertHook(pSourceContainer)) return true;
|
||||
// Container container = getAttachedContainer(pLevel, pPos, pState);
|
||||
// if (container == null) {
|
||||
// return false;
|
||||
// } else {
|
||||
// TODO 替换成开启吸物品的directions
|
||||
// Direction direction = pState.getValue(HopperBlock.FACING).getOpposite();
|
||||
// if (!isFullContainer(container, direction)) {
|
||||
// for (int i = 0; i < pSourceContainer.getContainerSize(); ++i) {
|
||||
// if (!pSourceContainer.getItem(i).isEmpty()) {
|
||||
// ItemStack itemstack = pSourceContainer.getItem(i).copy();
|
||||
// ItemStack itemstack1 = addItem(pSourceContainer, container, pSourceContainer.removeItem(i, 1), direction);
|
||||
// if (itemstack1.isEmpty()) {
|
||||
// container.setChanged();
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// pSourceContainer.setItem(i, itemstack);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
// }
|
||||
}
|
||||
|
||||
private static IntStream getSlots(Container pContainer, Direction pDirection) {
|
||||
return pContainer instanceof WorldlyContainer ? IntStream.of(((WorldlyContainer) pContainer).getSlotsForFace(pDirection)) : IntStream.range(0, pContainer.getContainerSize());
|
||||
}
|
||||
|
||||
private static boolean isFullContainer(Container pContainer, Direction pDirection) {
|
||||
return getSlots(pContainer, pDirection).allMatch((p_59379_) -> {
|
||||
ItemStack itemstack = pContainer.getItem(p_59379_);
|
||||
return itemstack.getCount() >= itemstack.getMaxStackSize();
|
||||
});
|
||||
}
|
||||
|
||||
private boolean inventoryFull() {
|
||||
for (ItemStack itemstack : this.items) {
|
||||
if (itemstack.isEmpty() || itemstack.getCount() != itemstack.getMaxStackSize()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
|
|
Loading…
Add table
Reference in a new issue