修复卓越接口GUI问题

This commit is contained in:
17146 2025-06-22 01:45:53 +08:00 committed by Light_Quanta
parent c7b8a07eff
commit 35d3679203
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 12 additions and 23 deletions

View file

@ -35,18 +35,11 @@ import javax.annotation.ParametersAreNonnullByDefault;
public class SuperbItemInterfaceBlock extends BaseEntityBlock { public class SuperbItemInterfaceBlock extends BaseEntityBlock {
public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED; public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED;
public static final DirectionProperty FACING = DirectionProperty.create("facing"); public static final DirectionProperty FACING = DirectionProperty.create("facing");
public SuperbItemInterfaceBlock() { public SuperbItemInterfaceBlock() {
this(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).requiresCorrectToolForDrops().strength(3.0F, 4.8F).sound(SoundType.METAL)); super(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).requiresCorrectToolForDrops().strength(3.0F, 4.8F).sound(SoundType.METAL));
} this.registerDefaultState(this.stateDefinition.any().setValue(ENABLED, true).setValue(FACING, Direction.DOWN));
public SuperbItemInterfaceBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(ENABLED, true));
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.DOWN));
} }
@Nullable @Nullable
@ -66,9 +59,7 @@ public class SuperbItemInterfaceBlock extends BaseEntityBlock {
@Override @Override
public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) { public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) {
Direction direction = context.getClickedFace().getOpposite(); Direction direction = context.getClickedFace().getOpposite();
return this.defaultBlockState() return this.defaultBlockState().setValue(FACING, direction).setValue(ENABLED, true);
.setValue(FACING, direction)
.setValue(ENABLED, true);
} }
@Override @Override
@ -119,7 +110,7 @@ public class SuperbItemInterfaceBlock extends BaseEntityBlock {
} }
} }
private static final MapCodec<SuperbItemInterfaceBlock> CODEC = BlockBehaviour.simpleCodec(SuperbItemInterfaceBlock::new); private static final MapCodec<SuperbItemInterfaceBlock> CODEC = BlockBehaviour.simpleCodec(prop -> new SuperbItemInterfaceBlock());
@Override @Override
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() { protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.block.SuperbItemInterfaceBlock;
import com.atsuishio.superbwarfare.init.ModBlockEntities; import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.menu.SuperbItemInterfaceMenu; import com.atsuishio.superbwarfare.menu.SuperbItemInterfaceMenu;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -32,13 +31,8 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
private NonNullList<ItemStack> items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY); private NonNullList<ItemStack> items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY);
private int cooldownTime = -1; private int cooldownTime = -1;
private final Direction facing;
public SuperbItemInterfaceBlockEntity(BlockPos pPos, BlockState pBlockState) { public SuperbItemInterfaceBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(ModBlockEntities.SUPERB_ITEM_INTERFACE.get(), pPos, pBlockState); super(ModBlockEntities.SUPERB_ITEM_INTERFACE.get(), pPos, pBlockState);
this.facing = pBlockState.getValue(SuperbItemInterfaceBlock.FACING);
} }
public static void serverTick(Level level, BlockPos pos, BlockState state, SuperbItemInterfaceBlockEntity blockEntity) { public static void serverTick(Level level, BlockPos pos, BlockState state, SuperbItemInterfaceBlockEntity blockEntity) {
@ -48,10 +42,12 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
if (blockEntity.isEmpty()) return; if (blockEntity.isEmpty()) return;
var facing = state.getValue(SuperbItemInterfaceBlock.FACING);
// find entities // find entities
var x = pos.getX() + blockEntity.facing.getStepX(); var x = pos.getX() + facing.getStepX();
var y = pos.getY() + blockEntity.facing.getStepY(); var y = pos.getY() + facing.getStepY();
var z = pos.getZ() + blockEntity.facing.getStepZ(); var z = pos.getZ() + facing.getStepZ();
var list = level.getEntities( var list = level.getEntities(
(Entity) null, (Entity) null,
@ -113,7 +109,7 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
@Override @Override
protected @NotNull AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pInventory) { protected @NotNull AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pInventory) {
return new SuperbItemInterfaceMenu(pContainerId, pInventory); return new SuperbItemInterfaceMenu(pContainerId, pInventory, this);
} }
@Override @Override

View file

@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class SuperbItemInterfaceScreen extends AbstractContainerScreen<SuperbItemInterfaceMenu> { public class SuperbItemInterfaceScreen extends AbstractContainerScreen<SuperbItemInterfaceMenu> {
private static final ResourceLocation HOPPER_LOCATION = ResourceLocation.withDefaultNamespace("textures/gui/container/hopper.png"); private static final ResourceLocation HOPPER_LOCATION = ResourceLocation.withDefaultNamespace("textures/gui/container/hopper.png");
public SuperbItemInterfaceScreen(SuperbItemInterfaceMenu menu, Inventory playerInventory, Component title) { public SuperbItemInterfaceScreen(SuperbItemInterfaceMenu menu, Inventory playerInventory, Component title) {
@ -22,6 +23,7 @@ public class SuperbItemInterfaceScreen extends AbstractContainerScreen<SuperbIte
@Override @Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
this.renderBackground(guiGraphics, mouseX, mouseY, partialTick);
super.render(guiGraphics, mouseX, mouseY, partialTick); super.render(guiGraphics, mouseX, mouseY, partialTick);
this.renderTooltip(guiGraphics, mouseX, mouseY); this.renderTooltip(guiGraphics, mouseX, mouseY);
} }