添加充电站GUI渲染
This commit is contained in:
parent
78a67b6c51
commit
477c0d4079
5 changed files with 49 additions and 7 deletions
|
@ -6,6 +6,9 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.Containers;
|
import net.minecraft.world.Containers;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.*;
|
import net.minecraft.world.level.block.*;
|
||||||
|
@ -16,6 +19,7 @@ import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@ -28,6 +32,23 @@ public class ChargingStationBlock extends BaseEntityBlock {
|
||||||
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
|
||||||
|
if (pLevel.isClientSide) {
|
||||||
|
return InteractionResult.SUCCESS;
|
||||||
|
} else {
|
||||||
|
this.openContainer(pLevel, pPos, pPlayer);
|
||||||
|
return InteractionResult.CONSUME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void openContainer(Level pLevel, BlockPos pPos, Player pPlayer) {
|
||||||
|
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
|
||||||
|
if (blockentity instanceof ChargingStationBlockEntity blockEntity) {
|
||||||
|
pPlayer.openMenu(blockEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderShape getRenderShape(BlockState pState) {
|
public RenderShape getRenderShape(BlockState pState) {
|
||||||
return RenderShape.MODEL;
|
return RenderShape.MODEL;
|
||||||
|
|
|
@ -19,10 +19,12 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
import net.minecraft.world.inventory.ContainerData;
|
import net.minecraft.world.inventory.ContainerData;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
|
@ -114,9 +116,10 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo
|
||||||
if (flag.get()) return;
|
if (flag.get()) return;
|
||||||
|
|
||||||
ItemStack fuel = blockEntity.getItem(SLOT_FUEL);
|
ItemStack fuel = blockEntity.getItem(SLOT_FUEL);
|
||||||
if (fuel.getBurnTime(null) > 0) {
|
int burnTime = ForgeHooks.getBurnTime(fuel, RecipeType.SMELTING);
|
||||||
blockEntity.fuelTick = fuel.getBurnTime(null);
|
if (burnTime > 0) {
|
||||||
blockEntity.maxFuelTick = fuel.getBurnTime(null);
|
blockEntity.fuelTick = burnTime;
|
||||||
|
blockEntity.maxFuelTick = burnTime;
|
||||||
fuel.shrink(1);
|
fuel.shrink(1);
|
||||||
blockEntity.setChanged();
|
blockEntity.setChanged();
|
||||||
} else if (fuel.getItem().isEdible()) {
|
} else if (fuel.getItem().isEdible()) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ import net.minecraft.world.inventory.ContainerData;
|
||||||
import net.minecraft.world.inventory.SimpleContainerData;
|
import net.minecraft.world.inventory.SimpleContainerData;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
|
|
||||||
public class ChargingStationMenu extends AbstractContainerMenu {
|
public class ChargingStationMenu extends AbstractContainerMenu {
|
||||||
|
@ -19,7 +21,7 @@ public class ChargingStationMenu extends AbstractContainerMenu {
|
||||||
private final ContainerData containerData;
|
private final ContainerData containerData;
|
||||||
|
|
||||||
public static final int X_OFFSET = 0;
|
public static final int X_OFFSET = 0;
|
||||||
public static final int Y_OFFSET = 11;
|
public static final int Y_OFFSET = 0;
|
||||||
|
|
||||||
public ChargingStationMenu(int id, Inventory inventory) {
|
public ChargingStationMenu(int id, Inventory inventory) {
|
||||||
this(id, inventory, new SimpleContainer(2), new SimpleContainerData(ChargingStationBlockEntity.MAX_DATA_COUNT));
|
this(id, inventory, new SimpleContainer(2), new SimpleContainerData(ChargingStationBlockEntity.MAX_DATA_COUNT));
|
||||||
|
@ -34,8 +36,8 @@ public class ChargingStationMenu extends AbstractContainerMenu {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.containerData = containerData;
|
this.containerData = containerData;
|
||||||
|
|
||||||
this.addSlot(new Slot(container, 0, 51, 43));
|
this.addSlot(new Slot(container, 0, 44, 54));
|
||||||
this.addSlot(new ChargingStationMenu.ChargingSlot(container, 1, 110, 43));
|
this.addSlot(new ChargingStationMenu.ChargingSlot(container, 1, 116, 54));
|
||||||
|
|
||||||
this.addDataSlots(containerData);
|
this.addDataSlots(containerData);
|
||||||
|
|
||||||
|
@ -66,7 +68,7 @@ public class ChargingStationMenu extends AbstractContainerMenu {
|
||||||
if (!this.moveItemStackTo(itemstack1, 1, 2, true)) {
|
if (!this.moveItemStackTo(itemstack1, 1, 2, true)) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
} else if (itemstack1.getBurnTime(null) > 0 || itemstack1.getFoodProperties(null) != null) {
|
} else if (ForgeHooks.getBurnTime(itemstack1, RecipeType.SMELTING) > 0 || itemstack1.getFoodProperties(null) != null) {
|
||||||
if (!this.moveItemStackTo(itemstack1, 0, 1, false)) {
|
if (!this.moveItemStackTo(itemstack1, 0, 1, false)) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.client.screens;
|
package com.atsuishio.superbwarfare.client.screens;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.block.entity.ChargingStationBlockEntity;
|
||||||
import com.atsuishio.superbwarfare.block.menu.ChargingStationMenu;
|
import com.atsuishio.superbwarfare.block.menu.ChargingStationMenu;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
@ -27,7 +28,22 @@ public class ChargingStationScreen extends AbstractContainerScreen<ChargingStati
|
||||||
int j = (this.height - this.imageHeight) / 2;
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
||||||
|
|
||||||
|
int fuelTick = ChargingStationScreen.this.menu.getFuelTick();
|
||||||
|
int maxFuelTick = ChargingStationScreen.this.menu.getMaxFuelTick();
|
||||||
|
int energy = ChargingStationScreen.this.menu.getEnergy();
|
||||||
|
|
||||||
|
if (maxFuelTick == 0) {
|
||||||
|
maxFuelTick = ChargingStationBlockEntity.DEFAULT_FUEL_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fuel
|
||||||
|
float fuelRate = (float) fuelTick / (float) maxFuelTick;
|
||||||
|
pGuiGraphics.blit(TEXTURE, i + 45, j + 51 - (int) (13 * fuelRate), 177, 14 - (int) (13 * fuelRate), 13, (int) (13 * fuelRate));
|
||||||
|
|
||||||
|
// Energy
|
||||||
|
float energyRate = (float) energy / (float) ChargingStationBlockEntity.MAX_ENERGY;
|
||||||
|
pGuiGraphics.blit(TEXTURE, i + 80, j + 70 - (int) (54 * energyRate),
|
||||||
|
177, 17, 16, (int) (54 * energyRate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2 KiB |
Loading…
Add table
Reference in a new issue