正确实现枪械重铸台GUI渲染

This commit is contained in:
Light_Quanta 2024-08-13 22:44:58 +08:00
parent 874c7559b0
commit 854fb5ed34
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 50 additions and 22 deletions

View file

@ -11,7 +11,10 @@ import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.DataSlot;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
public class ReforgingTableMenu extends AbstractContainerMenu {
@ -24,9 +27,9 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
public static final int DAMAGE_PERK_SLOT = 3;
public static final int RESULT_SLOT = 4;
private final DataSlot ammoPerkLevel = DataSlot.standalone();
private final DataSlot funcPerkLevel = DataSlot.standalone();
private final DataSlot damagePerkLevel = DataSlot.standalone();
public final DataSlot ammoPerkLevel = DataSlot.standalone();
public final DataSlot funcPerkLevel = DataSlot.standalone();
public final DataSlot damagePerkLevel = DataSlot.standalone();
public static final int X_OFFSET = 0;
public static final int Y_OFFSET = 11;
@ -55,11 +58,11 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
this.addDataSlot(funcPerkLevel);
this.addDataSlot(damagePerkLevel);
this.addSlot(new InputSlot(container, INPUT_SLOT, 20, 20));
this.addSlot(new PerkSlot(container, AMMO_PERK_SLOT, Perk.Type.AMMO, 60, 30));
this.addSlot(new PerkSlot(container, FUNC_PERK_SLOT, Perk.Type.FUNCTIONAL, 60, 50));
this.addSlot(new PerkSlot(container, DAMAGE_PERK_SLOT, Perk.Type.DAMAGE, 60, 70));
this.addSlot(new ResultSlot(container, RESULT_SLOT, 136, 40));
this.addSlot(new InputSlot(container, INPUT_SLOT, 20, 22));
this.addSlot(new PerkSlot(container, AMMO_PERK_SLOT, Perk.Type.AMMO, 80, 25));
this.addSlot(new PerkSlot(container, FUNC_PERK_SLOT, Perk.Type.FUNCTIONAL, 80, 45));
this.addSlot(new PerkSlot(container, DAMAGE_PERK_SLOT, Perk.Type.DAMAGE, 80, 65));
this.addSlot(new ResultSlot(container, RESULT_SLOT, 142, 45));
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {

View file

@ -31,7 +31,7 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
guiGraphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
guiGraphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, 200, 200);
RenderSystem.disableBlend();
}
@ -40,6 +40,21 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
this.renderBackground(pGuiGraphics);
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
var ammoPerkLevel = ReforgingTableScreen.this.menu.ammoPerkLevel.get();
var funcPerkLevel = ReforgingTableScreen.this.menu.funcPerkLevel.get();
var damagePerkLevel = ReforgingTableScreen.this.menu.damagePerkLevel.get();
if (ammoPerkLevel > 0) {
pGuiGraphics.blit(TEXTURE, this.leftPos + 140, this.topPos + 31, 5 * ammoPerkLevel - 5, 178, 5, 5, 200, 200);
}
if (funcPerkLevel > 0) {
pGuiGraphics.blit(TEXTURE, this.leftPos + 148, this.topPos + 31, 5 * funcPerkLevel - 5, 184, 5, 5, 200, 200);
}
if (damagePerkLevel > 0) {
pGuiGraphics.blit(TEXTURE, this.leftPos + 156, this.topPos + 31, 5 * damagePerkLevel - 5, 190, 5, 5, 200, 200);
}
}
@Override
@ -54,12 +69,12 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
int j = (this.height - this.imageHeight) / 2;
ReforgeButton button = new ReforgeButton(i + 124, j + 70);
UpgradeButton ammoUpgrade = new UpgradeButton(i + 100, j + 32, Perk.Type.AMMO);
DowngradeButton ammoDowngrade = new DowngradeButton(i + 86, j + 32, Perk.Type.AMMO);
UpgradeButton funcUpgrade = new UpgradeButton(i + 100, j + 52, Perk.Type.FUNCTIONAL);
DowngradeButton funcDowngrade = new DowngradeButton(i + 86, j + 52, Perk.Type.FUNCTIONAL);
UpgradeButton damageUpgrade = new UpgradeButton(i + 100, j + 72, Perk.Type.DAMAGE);
DowngradeButton damageDowngrade = new DowngradeButton(i + 86, j + 72, Perk.Type.DAMAGE);
UpgradeButton ammoUpgrade = new UpgradeButton(i + 98, j + 21, Perk.Type.AMMO);
DowngradeButton ammoDowngrade = new DowngradeButton(i + 69, j + 21, Perk.Type.AMMO);
UpgradeButton funcUpgrade = new UpgradeButton(i + 98, j + 41, Perk.Type.FUNCTIONAL);
DowngradeButton funcDowngrade = new DowngradeButton(i + 69, j + 41, Perk.Type.FUNCTIONAL);
UpgradeButton damageUpgrade = new UpgradeButton(i + 98, j + 61, Perk.Type.DAMAGE);
DowngradeButton damageDowngrade = new DowngradeButton(i + 69, j + 61, Perk.Type.DAMAGE);
this.addRenderableWidget(button);
this.addRenderableWidget(ammoUpgrade);
@ -73,6 +88,11 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
@OnlyIn(Dist.CLIENT)
static class ReforgeButton extends AbstractButton {
@Override
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), this.isHoveredOrFocused() ? 81 : 51, 184, 29, 15, 200, 200);
}
public ReforgeButton(int pX, int pY) {
super(pX, pY, 40, 16, Component.translatable("button.superbwarfare.reforge"));
}
@ -82,11 +102,6 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
}
// @Override
// public void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
//
// }
@Override
public void onPress() {
ModUtils.PACKET_HANDLER.sendToServer(new GunReforgeMessage(0));
@ -103,10 +118,15 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
public Perk.Type type;
public UpgradeButton(int pX, int pY, Perk.Type type) {
super(pX, pY, 12, 12, Component.translatable("button.superbwarfare.upgrade"));
super(pX, pY, 9, 9, Component.translatable("button.superbwarfare.upgrade"));
this.type = type;
}
@Override
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), 187, this.isHoveredOrFocused() ? 10 : 0, 9, 9, 200, 200);
}
@Override
public void onPress() {
ModUtils.PACKET_HANDLER.sendToServer(new SetPerkLevelMessage(type.ordinal(), true));
@ -122,6 +142,11 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
static class DowngradeButton extends AbstractButton {
public Perk.Type type;
@Override
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), 177, this.isHoveredOrFocused() ? 10 : 0, 9, 9, 200, 200);
}
public DowngradeButton(int pX, int pY, Perk.Type type) {
super(pX, pY, 12, 12, Component.translatable("button.superbwarfare.downgrade"));
this.type = type;