/
DisguiseScreen.java
77 lines (61 loc) · 2.94 KB
/
DisguiseScreen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package slimeknights.tmechworks.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import slimeknights.tmechworks.TMechworks;
import slimeknights.tmechworks.api.disguisestate.DisguiseStates;
import slimeknights.tmechworks.client.gui.components.DisguiseStateWidget;
import slimeknights.tmechworks.common.blocks.tileentity.RedstoneMachineTileEntity;
import slimeknights.tmechworks.common.inventory.DisguiseContainer;
public class DisguiseScreen extends ContainerScreen<DisguiseContainer> {
public static final ResourceLocation SCREEN_LOCATION = new ResourceLocation(TMechworks.modId, "textures/gui/generic_1.png");
private DisguiseStateWidget disguiseWidget;
public DisguiseScreen(DisguiseContainer container, PlayerInventory inventory, ITextComponent name) {
super(container, inventory, name);
}
public static DisguiseScreen create(DisguiseContainer container, PlayerInventory player, ITextComponent title){
return new DisguiseScreen(container, player, title);
}
@Override
protected void init() {
super.init();
disguiseWidget = new DisguiseStateWidget(guiLeft + 99, guiTop + 30, container.getTileEntity());
addButton(disguiseWidget);
}
@Override
public void tick() {
super.tick();
RedstoneMachineTileEntity te = container.getTileEntity();
ItemStack disguise = te.getDisguiseBlock();
if (disguise.getItem() instanceof BlockItem) {
BlockState disguiseState = ((BlockItem) disguise.getItem()).getBlock().getDefaultState();
disguiseWidget.setState(DisguiseStates.getForState(disguiseState), te.getDisguiseState());
} else {
disguiseWidget.setState(null, null);
}
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
this.renderBackground();
super.render(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bindTexture(SCREEN_LOCATION);
blit(guiLeft, guiTop, 0, 0, xSize, ySize); // Background
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
String s = title.getFormattedText();
font.drawString(s, xSize / 2F - font.getStringWidth(s) / 2F, 6, 4210752);
font.drawString(playerInventory.getDisplayName().getFormattedText(), 8, ySize - 96 + 2, 4210752);
}
}