Skip to content

Commit d422c4c

Browse files
committed
Optimize GUIs
1 parent 131b782 commit d422c4c

24 files changed

+250
-272
lines changed

src/main/java/com/github/alexthe666/iceandfire/IceAndFire.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
package com.github.alexthe666.iceandfire;
22

33

4-
import com.github.alexthe666.citadel.server.message.PropertiesMessage;
5-
import com.github.alexthe666.iceandfire.entity.IafVillagerRegistry;
6-
import com.github.alexthe666.iceandfire.message.*;
7-
import com.github.alexthe666.iceandfire.world.IafProcessors;
84
import org.apache.logging.log4j.LogManager;
95
import org.apache.logging.log4j.Logger;
106

117
import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
128
import com.github.alexthe666.iceandfire.config.ConfigHolder;
139
import com.github.alexthe666.iceandfire.entity.IafEntityRegistry;
10+
import com.github.alexthe666.iceandfire.entity.IafVillagerRegistry;
11+
import com.github.alexthe666.iceandfire.inventory.IafContainerRegistry;
1412
import com.github.alexthe666.iceandfire.item.IafItemRegistry;
1513
import com.github.alexthe666.iceandfire.loot.IafLootRegistry;
14+
import com.github.alexthe666.iceandfire.message.*;
15+
import com.github.alexthe666.iceandfire.world.IafProcessors;
1616
import com.github.alexthe666.iceandfire.world.IafWorldRegistry;
1717

1818
import net.minecraft.entity.player.ServerPlayerEntity;
1919
import net.minecraft.item.ItemGroup;
2020
import net.minecraft.item.ItemStack;
2121
import net.minecraft.util.ResourceLocation;
22+
2223
import net.minecraftforge.common.MinecraftForge;
2324
import net.minecraftforge.event.world.BiomeLoadingEvent;
25+
import net.minecraftforge.eventbus.api.IEventBus;
2426
import net.minecraftforge.eventbus.api.SubscribeEvent;
2527
import net.minecraftforge.fml.DistExecutor;
2628
import net.minecraftforge.fml.ModLoadingContext;
@@ -73,15 +75,18 @@ public ItemStack createIcon() {
7375

7476
public IceAndFire() {
7577
final ModLoadingContext modLoadingContext = ModLoadingContext.get();
76-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
77-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient);
78-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupComplete);
7978
modLoadingContext.registerConfig(ModConfig.Type.CLIENT, ConfigHolder.CLIENT_SPEC);
8079
modLoadingContext.registerConfig(ModConfig.Type.COMMON, ConfigHolder.SERVER_SPEC);
8180
MinecraftForge.EVENT_BUS.addListener(this::onBiomeLoadFromJSON);
8281
MinecraftForge.EVENT_BUS.addListener(this::onServerStarted);
8382
PROXY.init();
8483
IafWorldRegistry.register();
84+
85+
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
86+
IafContainerRegistry.CONTAINERS.register(modBus);
87+
modBus.addListener(this::setup);
88+
modBus.addListener(this::setupClient);
89+
modBus.addListener(this::setupComplete);
8590
}
8691

8792
@SubscribeEvent

src/main/java/com/github/alexthe666/iceandfire/api/event/RenderPodiumItemEvent.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.alexthe666.iceandfire.entity.tile.TileEntityPodium;
55

66
import net.minecraft.item.ItemStack;
7+
78
import net.minecraftforge.eventbus.api.Event;
89

910
/*
@@ -12,10 +13,11 @@
1213
public class RenderPodiumItemEvent extends Event {
1314
float partialTicks;
1415
double x, y, z;
15-
private RenderPodium render;
16+
private RenderPodium<?> render;
1617
private TileEntityPodium podium;
1718

18-
public RenderPodiumItemEvent(RenderPodium renderPodium, TileEntityPodium podium, float partialTicks, double x, double y, double z) {
19+
public RenderPodiumItemEvent(RenderPodium<?> renderPodium, TileEntityPodium podium, float partialTicks, double x,
20+
double y, double z) {
1921
this.render = renderPodium;
2022
this.podium = podium;
2123
this.partialTicks = partialTicks;
@@ -24,7 +26,7 @@ public RenderPodiumItemEvent(RenderPodium renderPodium, TileEntityPodium podium,
2426
this.z = z;
2527
}
2628

27-
public RenderPodium getRender() {
29+
public RenderPodium<?> getRender() {
2830
return render;
2931
}
3032

src/main/java/com/github/alexthe666/iceandfire/client/gui/GuiDragon.java

+8-14
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,27 @@
1919
import net.minecraft.util.math.vector.Quaternion;
2020
import net.minecraft.util.math.vector.Vector3f;
2121
import net.minecraft.util.text.ITextComponent;
22-
import net.minecraftforge.api.distmarker.Dist;
23-
import net.minecraftforge.api.distmarker.OnlyIn;
2422

25-
@OnlyIn(Dist.CLIENT)
2623
public class GuiDragon extends ContainerScreen<ContainerDragon> {
2724
private static final ResourceLocation texture = new ResourceLocation("iceandfire:textures/gui/dragon.png");
28-
private PlayerInventory playerInventory;
29-
private ContainerDragon dragonInv;
3025
private float mousePosx;
3126
private float mousePosY;
3227

3328
public GuiDragon(ContainerDragon dragonInv, PlayerInventory playerInv, ITextComponent name) {
3429
super(dragonInv, playerInv, name);
35-
this.playerInventory = playerInv;
36-
this.dragonInv = dragonInv;
3730
this.ySize = 214;
3831
}
3932

4033

4134
public static void drawEntityOnScreen(int posX, int posY, float scale, float mouseX, float mouseY, LivingEntity livingEntity) {
42-
float f = (float) Math.atan((double) (mouseX / 40.0F));
43-
float f1 = (float) Math.atan((double) (mouseY / 40.0F));
35+
float f = (float) Math.atan(mouseX / 40.0F);
36+
float f1 = (float) Math.atan(mouseY / 40.0F);
4437
RenderSystem.pushMatrix();
45-
RenderSystem.translatef((float) posX, (float) posY, 1050.0F);
38+
RenderSystem.translatef(posX, posY, 1050.0F);
4639
RenderSystem.scalef(1.0F, 1.0F, -1.0F);
4740
MatrixStack matrixstack = new MatrixStack();
4841
matrixstack.translate(0.0D, 0.0D, 1000.0D);
49-
matrixstack.scale((float) scale, (float) scale, (float) scale);
42+
matrixstack.scale(scale, scale, scale);
5043
Quaternion quaternion = Vector3f.ZP.rotationDegrees(180.0F);
5144
Quaternion quaternion1 = Vector3f.XP.rotationDegrees(f1 * 20.0F);
5245
quaternion.multiply(quaternion1);
@@ -80,14 +73,16 @@ public static void drawEntityOnScreen(int posX, int posY, float scale, float mou
8073
}
8174

8275

76+
@Override
8377
protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) {
8478

8579
}
8680

81+
@Override
8782
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
8883
this.renderBackground(matrixStack);
89-
this.mousePosx = (float)mouseX;
90-
this.mousePosY = (float)mouseY;
84+
this.mousePosx = mouseX;
85+
this.mousePosY = mouseY;
9186
super.render(matrixStack, mouseX, mouseY, partialTicks);
9287
this.renderHoveredTooltip(matrixStack, mouseX, mouseY);
9388
}
@@ -107,7 +102,6 @@ protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float pa
107102
}
108103
if (entity instanceof EntityDragonBase) {
109104
EntityDragonBase dragon = (EntityDragonBase) entity;
110-
String s1 = dragon.getName().getString();
111105

112106
FontRenderer font = this.getMinecraft().fontRenderer;
113107
String s3 = dragon.getCustomName() == null ? StatCollector.translateToLocal("dragon.unnamed") : StatCollector.translateToLocal("dragon.name") + " " + dragon.getCustomName().getString();

src/main/java/com/github/alexthe666/iceandfire/client/gui/GuiDragonForge.java

+7-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.github.alexthe666.iceandfire.entity.tile.TileEntityDragonforge;
66
import com.github.alexthe666.iceandfire.inventory.ContainerDragonForge;
77
import com.mojang.blaze3d.matrix.MatrixStack;
8-
import com.mojang.blaze3d.platform.GlStateManager;
8+
import com.mojang.blaze3d.systems.RenderSystem;
99

1010
import net.minecraft.client.gui.FontRenderer;
1111
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
@@ -14,27 +14,21 @@
1414
import net.minecraft.tileentity.TileEntity;
1515
import net.minecraft.util.ResourceLocation;
1616
import net.minecraft.util.text.ITextComponent;
17-
import net.minecraftforge.api.distmarker.Dist;
18-
import net.minecraftforge.api.distmarker.OnlyIn;
1917

20-
@OnlyIn(Dist.CLIENT)
2118
public class GuiDragonForge extends ContainerScreen<ContainerDragonForge> {
2219
private static final ResourceLocation TEXTURE_FIRE = new ResourceLocation("iceandfire:textures/gui/dragonforge_fire.png");
2320
private static final ResourceLocation TEXTURE_ICE = new ResourceLocation("iceandfire:textures/gui/dragonforge_ice.png");
2421
private static final ResourceLocation TEXTURE_LIGHTNING = new ResourceLocation("iceandfire:textures/gui/dragonforge_lightning.png");
25-
private final PlayerInventory playerInventory;
2622
private ContainerDragonForge tileFurnace;
2723
private int dragonType;
2824

2925
public GuiDragonForge(ContainerDragonForge container, PlayerInventory inv, ITextComponent name) {
3026
super(container, inv, name);
31-
this.playerInventory = inv;
3227
this.tileFurnace = container;
33-
if (tileFurnace instanceof ContainerDragonForge) {
34-
this.dragonType = tileFurnace.isFire;
35-
}
28+
this.dragonType = tileFurnace.isFire;
3629
}
3730

31+
@Override
3832
protected void drawGuiContainerForegroundLayer(MatrixStack stack, int mouseX, int mouseY) {
3933
FontRenderer font = this.getMinecraft().fontRenderer;
4034
if (tileFurnace != null) {
@@ -46,7 +40,7 @@ protected void drawGuiContainerForegroundLayer(MatrixStack stack, int mouseX, in
4640

4741
@Override
4842
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) {
49-
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
43+
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
5044
if (dragonType == 0) {
5145
this.getMinecraft().getTextureManager().bindTexture(TEXTURE_FIRE);
5246
} else if (dragonType == 1) {
@@ -57,11 +51,11 @@ protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float pa
5751
int k = (this.width - this.xSize) / 2;
5852
int l = (this.height - this.ySize) / 2;
5953
this.blit(matrixStack, k, l, 0, 0, this.xSize, this.ySize);
60-
int i1 = this.func_175381_h(126);
54+
int i1 = this.getCookTime(126);
6155
this.blit(matrixStack, k + 12, l + 23, 0, 166, i1, 38);
6256
}
6357

64-
private int func_175381_h(int p_175381_1_) {
58+
private int getCookTime(int p_175381_1_) {
6559
TileEntity te = IceAndFire.PROXY.getRefrencedTE();
6660
int j = 0;
6761
int maxCookTime = 1000;
@@ -72,6 +66,7 @@ private int func_175381_h(int p_175381_1_) {
7266
return j != 0 ? j * p_175381_1_ / maxCookTime : 0;
7367
}
7468

69+
@Override
7570
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
7671
this.renderBackground(matrixStack);
7772
super.render(matrixStack, mouseX, mouseY, partialTicks);

src/main/java/com/github/alexthe666/iceandfire/client/gui/GuiHippocampus.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@
1212
import net.minecraft.entity.player.PlayerInventory;
1313
import net.minecraft.util.ResourceLocation;
1414
import net.minecraft.util.text.ITextComponent;
15-
import net.minecraftforge.api.distmarker.Dist;
16-
import net.minecraftforge.api.distmarker.OnlyIn;
1715

18-
@OnlyIn(Dist.CLIENT)
1916
public class GuiHippocampus extends ContainerScreen<ContainerHippocampus> {
2017
private static final ResourceLocation TEXTURE = new ResourceLocation("iceandfire:textures/gui/hippogryph.png");
21-
private final PlayerInventory playerInventory;
22-
private final ContainerHippocampus hippogryphInv;
2318
private float mousePosx;
2419
private float mousePosY;
2520

2621
public GuiHippocampus(ContainerHippocampus dragonInv, PlayerInventory playerInv, ITextComponent name) {
2722
super(dragonInv, playerInv, name);
28-
this.playerInventory = playerInv;
29-
this.hippogryphInv = dragonInv;
3023
}
3124

25+
@Override
3226
protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) {
3327
int k = 0;
3428
int l = 0;
@@ -41,10 +35,11 @@ protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mous
4135
font.drawString(matrixStack, this.playerInventory.getDisplayName().getString(), k+ 8, l + this.ySize - 96 + 2, 4210752);
4236
}
4337

38+
@Override
4439
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
4540
this.renderBackground(matrixStack);
46-
this.mousePosx = (float)mouseX;
47-
this.mousePosY = (float)mouseY;
41+
this.mousePosx = mouseX;
42+
this.mousePosY = mouseY;
4843
super.render(matrixStack, mouseX, mouseY, partialTicks);
4944
this.renderHoveredTooltip(matrixStack, mouseX, mouseY);
5045
}
@@ -62,7 +57,8 @@ protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float pa
6257
if (hippo.isChested()) {
6358
this.blit(matrixStack, i + 79, j + 17, 0, this.ySize, 5 * 18, 54);
6459
}
65-
GuiDragon.drawEntityOnScreen(i + 51, j + 60, 17, (float) (i + 51) - this.mousePosx, (float) (j + 75 - 50) - this.mousePosY, hippo);
60+
GuiDragon.drawEntityOnScreen(i + 51, j + 60, 17, i + 51 - this.mousePosx, j + 75 - 50 - this.mousePosY,
61+
hippo);
6662
}
6763
}
6864
}

src/main/java/com/github/alexthe666/iceandfire/client/gui/GuiHippogryph.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,18 @@
1212
import net.minecraft.entity.player.PlayerInventory;
1313
import net.minecraft.util.ResourceLocation;
1414
import net.minecraft.util.text.ITextComponent;
15-
import net.minecraftforge.api.distmarker.Dist;
16-
import net.minecraftforge.api.distmarker.OnlyIn;
1715

18-
@OnlyIn(Dist.CLIENT)
1916
public class GuiHippogryph extends ContainerScreen<ContainerHippogryph> {
2017
private static final ResourceLocation TEXTURE = new ResourceLocation("iceandfire:textures/gui/hippogryph.png");
21-
private final PlayerInventory playerInventory;
22-
private final ContainerHippogryph hippogryphInv;
2318
private float mousePosx;
2419
private float mousePosY;
2520

2621
public GuiHippogryph(ContainerHippogryph dragonInv, PlayerInventory playerInv, ITextComponent name) {
2722
super(dragonInv, playerInv, name);
28-
this.playerInventory = playerInv;
29-
this.hippogryphInv = dragonInv;
3023
}
3124

25+
@Override
3226
protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) {
33-
int k = (this.width - this.xSize) / 2;
34-
int l = (this.height - this.ySize) / 2;
3527
Entity entity = IceAndFire.PROXY.getReferencedMob();
3628
FontRenderer font = this.getMinecraft().fontRenderer;
3729
if (entity instanceof EntityHippogryph) {
@@ -41,10 +33,11 @@ protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mous
4133
font.drawString(matrixStack, this.playerInventory.getDisplayName().getString(), 8, this.ySize - 96 + 2, 4210752);
4234
}
4335

36+
@Override
4437
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
4538
this.renderBackground(matrixStack);
46-
this.mousePosx = (float)mouseX;
47-
this.mousePosY = (float)mouseY;
39+
this.mousePosx = mouseX;
40+
this.mousePosY = mouseY;
4841
super.render(matrixStack, mouseX, mouseY, partialTicks);
4942
this.renderHoveredTooltip(matrixStack, mouseX, mouseY);
5043
}
@@ -62,7 +55,8 @@ protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float pa
6255
if (hippo.isChested()) {
6356
this.blit(matrixStack, i + 79, j + 17, 0, this.ySize, 5 * 18, 54);
6457
}
65-
GuiDragon.drawEntityOnScreen(i + 51, j + 60, 17, (float) (i + 51) - this.mousePosx, (float) (j + 75 - 50) - this.mousePosY, hippo);
58+
GuiDragon.drawEntityOnScreen(i + 51, j + 60, 17, i + 51 - this.mousePosx, j + 75 - 50 - this.mousePosY,
59+
hippo);
6660
}
6761
}
6862

0 commit comments

Comments
 (0)