/
BackgroundContainerScreen.java
80 lines (69 loc) · 2.79 KB
/
BackgroundContainerScreen.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
78
79
80
package knightminer.inspirations.shared.client;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import knightminer.inspirations.Inspirations;
import net.minecraft.client.gui.ScreenManager.IScreenFactory;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
/**
* Generic container screen that simply draws the given background
* @param <T> Container type
*/
@SuppressWarnings("WeakerAccess")
public class BackgroundContainerScreen<T extends Container> extends ContainerScreen<T> {
/** Background drawn for this screen */
protected final ResourceLocation background;
/**
* Creates a new screen instance
* @param container Container class
* @param inventory Player inventory
* @param name Container name
* @param background Container background
*/
public BackgroundContainerScreen(T container, PlayerInventory inventory, ITextComponent name, ResourceLocation background) {
super(container, inventory, name);
this.background = background;
}
@Override
protected void init() {
super.init();
this.titleX = (this.xSize - this.font.func_238414_a_(this.title)) / 2;
}
@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(matrixStack);
super.render(matrixStack, mouseX, mouseY, partialTicks);
this.func_230459_a_(matrixStack, mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
assert this.minecraft != null;
this.minecraft.getTextureManager().bindTexture(this.background);
this.blit(matrixStack, this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
}
public static class Factory<T extends Container> implements IScreenFactory<T,BackgroundContainerScreen<T>> {
private final ResourceLocation background;
/**
* Creates a factory from the given background location
* @param background Background location
*/
public Factory(ResourceLocation background) {
this.background = background;
}
/**
* Creates a factory from the container name
* @param name Name of this container
*/
public Factory(String name) {
this(Inspirations.getResource(String.format("textures/gui/%s.png", name)));
}
@Override
public BackgroundContainerScreen<T> create(T container, PlayerInventory inventory, ITextComponent name) {
return new BackgroundContainerScreen<>(container, inventory, name, background);
}
}
}