添加基础雷达gui渲染

This commit is contained in:
17146 2024-12-25 23:49:03 +08:00
parent ee8909061d
commit c055a204ec
5 changed files with 98 additions and 3 deletions

View file

@ -0,0 +1,51 @@
package com.atsuishio.superbwarfare.client.screens;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.menu.FuMO25Menu;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class FuMO25Screen extends AbstractContainerScreen<FuMO25Menu> {
private static final ResourceLocation TEXTURE = ModUtils.loc("textures/gui/radar.png");
private static final ResourceLocation SCAN = ModUtils.loc("textures/gui/radar_scan.png");
public FuMO25Screen(FuMO25Menu pMenu, Inventory pPlayerInventory, Component pTitle) {
super(pMenu, pPlayerInventory, pTitle);
imageWidth = 340;
imageHeight = 166;
}
@Override
protected void renderBg(GuiGraphics pGuiGraphics, float pPartialTick, int pMouseX, int pMouseY) {
int i = (this.width - this.imageWidth) / 2;
int j = (this.height - this.imageHeight) / 2;
pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight, 358, 328);
}
@Override
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
this.renderBackground(pGuiGraphics);
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
}
@Override
protected void renderLabels(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY) {
}
@Override
protected void init() {
super.init();
this.titleLabelX = 33;
this.titleLabelY = 5;
this.inventoryLabelX = 105;
this.inventoryLabelY = 128;
}
}

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.client.screens.ChargingStationScreen;
import com.atsuishio.superbwarfare.client.screens.FuMO25Screen;
import com.atsuishio.superbwarfare.client.screens.ReforgingTableScreen;
import com.atsuishio.superbwarfare.client.screens.VehicleScreen;
import net.minecraft.client.gui.screens.MenuScreens;
@ -18,6 +19,7 @@ public class ModScreens {
MenuScreens.register(ModMenuTypes.REFORGING_TABLE_MENU.get(), ReforgingTableScreen::new);
MenuScreens.register(ModMenuTypes.CHARGING_STATION_MENU.get(), ChargingStationScreen::new);
MenuScreens.register(ModMenuTypes.VEHICLE_MENU.get(), VehicleScreen::new);
MenuScreens.register(ModMenuTypes.FUMO_25_MENU.get(), FuMO25Screen::new);
});
}
}

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.menu;
import com.atsuishio.superbwarfare.init.ModBlocks;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModMenuTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
@ -12,13 +13,19 @@ import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import javax.annotation.Nullable;
public class FuMO25Menu extends AbstractContainerMenu {
protected final Container container;
protected final ContainerLevelAccess access;
public static final int X_OFFSET = 0;
public static final int Y_OFFSET = 11;
private int posX = Integer.MIN_VALUE;
private int posY = Integer.MIN_VALUE;
private int posZ = Integer.MIN_VALUE;
public static final int X_OFFSET = 164;
public static final int Y_OFFSET = 0;
public FuMO25Menu(int pContainerId, Inventory pPlayerInventory) {
this(pContainerId, pPlayerInventory, new SimpleContainer(1), ContainerLevelAccess.NULL);
@ -36,7 +43,7 @@ public class FuMO25Menu extends AbstractContainerMenu {
this.container = container;
this.access = access;
this.addSlot(new ParaSlot(container, 0, 8 + X_OFFSET, 11 + Y_OFFSET));
this.addSlot(new ParaSlot(container, 0, 278, 60));
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
@ -49,6 +56,40 @@ public class FuMO25Menu extends AbstractContainerMenu {
}
}
public void setPos(int x, int y, int z) {
this.posX = x;
this.posY = y;
this.posZ = z;
}
public void resetPos() {
this.posX = Integer.MIN_VALUE;
this.posY = Integer.MIN_VALUE;
this.posZ = Integer.MIN_VALUE;
}
public void setPosToParameters() {
if (this.posX != Integer.MIN_VALUE && this.posY != Integer.MIN_VALUE) {
ItemStack stack = this.container.getItem(0);
if (stack.isEmpty()) return;
stack.getOrCreateTag().putInt("TargetX", this.posX);
stack.getOrCreateTag().putInt("TargetY", this.posY);
stack.getOrCreateTag().putInt("TargetZ", this.posZ);
this.resetPos();
this.container.setChanged();
}
}
@Nullable
public BlockPos getCurrentPos() {
if (this.posX != Integer.MIN_VALUE && this.posY != Integer.MIN_VALUE && this.posZ != Integer.MIN_VALUE) {
return new BlockPos(this.posX, this.posY, this.posZ);
}
return null;
}
@Override
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
ItemStack itemstack = ItemStack.EMPTY;
@ -100,6 +141,7 @@ public class FuMO25Menu extends AbstractContainerMenu {
pPlayer.getInventory().placeItemBackInInventory(para);
}
this.container.removeItemNoUpdate(0);
resetPos();
});
}

View file

Before

Width:  |  Height:  |  Size: 9 KiB

After

Width:  |  Height:  |  Size: 9 KiB

View file

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB