/
GuiHelper.java
95 lines (82 loc) · 3.68 KB
/
GuiHelper.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package mezz.jei.gui;
import javax.annotation.Nullable;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.ICraftingGridHelper;
import mezz.jei.api.gui.IDrawableAnimated;
import mezz.jei.api.gui.IDrawableStatic;
import mezz.jei.api.gui.ITickTimer;
import mezz.jei.api.recipe.IStackHelper;
import mezz.jei.util.Log;
import mezz.jei.util.TickTimer;
import net.minecraft.util.ResourceLocation;
public class GuiHelper implements IGuiHelper {
private final IStackHelper stackHelper;
private final IDrawableStatic slotDrawable;
public GuiHelper(IStackHelper stackHelper) {
this.stackHelper = stackHelper;
ResourceLocation location = new ResourceLocation("minecraft", "textures/gui/container/furnace.png");
this.slotDrawable = createDrawable(location, 55, 16, 18, 18);
}
@Override
public IDrawableStatic createDrawable(@Nullable ResourceLocation resourceLocation, int u, int v, int width, int height) {
if (resourceLocation == null) {
Log.error("Null resourceLocation, returning blank drawable", new NullPointerException());
return createBlankDrawable(width, height);
}
return new DrawableResource(resourceLocation, u, v, width, height);
}
@Override
public IDrawableStatic createDrawable(@Nullable ResourceLocation resourceLocation, int u, int v, int width, int height, int paddingTop, int paddingBottom, int paddingLeft, int paddingRight) {
if (resourceLocation == null) {
Log.error("Null resourceLocation, returning blank drawable", new NullPointerException());
return createBlankDrawable(width, height);
}
return new DrawableResource(resourceLocation, u, v, width, height, paddingTop, paddingBottom, paddingLeft, paddingRight);
}
@Override
public IDrawableAnimated createAnimatedDrawable(@Nullable IDrawableStatic drawable, int ticksPerCycle, @Nullable IDrawableAnimated.StartDirection startDirection, boolean inverted) {
if (drawable == null) {
Log.error("Null drawable, returning blank drawable", new NullPointerException());
return new DrawableBlank(0, 0);
}
if (startDirection == null) {
Log.error("Null startDirection, defaulting to Top", new NullPointerException());
startDirection = IDrawableAnimated.StartDirection.TOP;
}
if (inverted) {
if (startDirection == IDrawableAnimated.StartDirection.TOP) {
startDirection = IDrawableAnimated.StartDirection.BOTTOM;
} else if (startDirection == IDrawableAnimated.StartDirection.BOTTOM) {
startDirection = IDrawableAnimated.StartDirection.TOP;
} else if (startDirection == IDrawableAnimated.StartDirection.LEFT) {
startDirection = IDrawableAnimated.StartDirection.RIGHT;
} else {
startDirection = IDrawableAnimated.StartDirection.LEFT;
}
}
int tickTimerMaxValue;
if (startDirection == IDrawableAnimated.StartDirection.TOP || startDirection == IDrawableAnimated.StartDirection.BOTTOM) {
tickTimerMaxValue = drawable.getHeight();
} else {
tickTimerMaxValue = drawable.getWidth();
}
ITickTimer tickTimer = createTickTimer(ticksPerCycle, tickTimerMaxValue, !inverted);
return new DrawableAnimated(drawable, tickTimer, startDirection);
}
@Override
public IDrawableStatic getSlotDrawable() {
return slotDrawable;
}
@Override
public IDrawableStatic createBlankDrawable(int width, int height) {
return new DrawableBlank(width, height);
}
@Override
public ICraftingGridHelper createCraftingGridHelper(int craftInputSlot1, int craftOutputSlot) {
return new CraftingGridHelper(stackHelper, craftInputSlot1, craftOutputSlot);
}
@Override
public ITickTimer createTickTimer(int ticksPerCycle, int maxValue, boolean countDown) {
return new TickTimer(ticksPerCycle, maxValue, countDown);
}
}