-
Notifications
You must be signed in to change notification settings - Fork 2
/
DoggoDropHandler.java
236 lines (207 loc) · 6.69 KB
/
DoggoDropHandler.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*******************************************************************************
* @author Reika Kalseki
*
* Copyright 2017
*
* All rights reserved.
* Distribution of the software in any form is only allowed with
* explicit, prior permission from the owner.
******************************************************************************/
package Reika.Satisforestry;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import Reika.DragonAPI.Libraries.ReikaEntityHelper;
import Reika.DragonAPI.Libraries.Java.ReikaGLHelper.BlendMode;
import Reika.DragonAPI.Libraries.Registry.ReikaItemHelper;
import Reika.DragonAPI.Libraries.Rendering.ReikaGuiAPI;
import Reika.Satisforestry.Config.BiomeConfig;
import Reika.Satisforestry.Config.DoggoDrop;
import Reika.Satisforestry.Config.DoggoDrop.Condition;
import Reika.Satisforestry.Entity.EntityLizardDoggo;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
public class DoggoDropHandler extends TemplateRecipeHandler {
private final Comparator<CachedRecipe> displaySorter = new Comparator<CachedRecipe>() {
@Override
public int compare(CachedRecipe o1, CachedRecipe o2) {
if (o1 instanceof DoggoEntry && o2 instanceof DoggoEntry) {
DoggoEntry l1 = (DoggoEntry)o1;
DoggoEntry l2 = (DoggoEntry)o2;
return Integer.compare(l2.item.baseWeight, l1.item.baseWeight);
}
else if (o1 instanceof DoggoEntry) {
return Integer.MAX_VALUE;
}
else if (o2 instanceof DoggoEntry) {
return Integer.MIN_VALUE;
}
else
return 0;
}
};
public class DoggoEntry extends CachedRecipe {
private final DoggoDrop item;
public DoggoEntry(DoggoDrop is) {
item = is;
}
@Override
public PositionedStack getResult() {
return new PositionedStack(item.getItem(), 5, 10);
}
@Override
public PositionedStack getIngredient()
{
return null;
}
}
private EntityLizardDoggo renderEntity;
@Override
public String getRecipeName() {
return "Lizard Doggo Drops";
}
@Override
public String getGuiTexture() {
return "unknown.png";
}
@Override
public void drawBackground(int recipe)
{
GL11.glColor4f(1, 1, 1, 1);
//ReikaTextureHelper.bindTexture(RotaryCraft.class, this.getGuiTexture());
GL11.glDisable(GL11.GL_DEPTH_TEST);
//ReikaGuiAPI.instance.drawTexturedModalRectWithDepth(0, 1, 5, 11, 166, 70, ReikaGuiAPI.NEI_DEPTH);
}
@Override
public void drawForeground(int recipe)
{
GL11.glColor4f(1, 1, 1, 1);
GL11.glDisable(GL11.GL_LIGHTING);
//ReikaTextureHelper.bindTexture(RotaryCraft.class, this.getGuiTexture());
this.drawExtras(recipe);
}
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(0, 3, 165, 52), "doggodrops"));
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId != null && outputId.equals("doggodrops")) {
try {
for (DoggoDrop dd : BiomeConfig.instance.getDoggoDrops()) {
arecipes.add(new DoggoEntry(dd));
}
}
catch (Exception e) {
e.printStackTrace();
}
}
Collections.sort(arecipes, displaySorter);
super.loadCraftingRecipes(outputId, results);
}
@Override
public void loadUsageRecipes(String inputId, Object... ingredients) {
super.loadUsageRecipes(inputId, ingredients);
}
@Override
public void loadCraftingRecipes(ItemStack result) {
super.loadCraftingRecipes(result);
arecipes.addAll(this.getEntriesForItem(result));
Collections.sort(arecipes, displaySorter);
}
private Collection<DoggoEntry> getEntriesForItem(ItemStack is) {
ArrayList<DoggoEntry> li = new ArrayList();
try {
for (DoggoDrop dd : BiomeConfig.instance.getDoggoDrops()) {
if (ReikaItemHelper.matchStacks(dd.getItem(), is))
li.add(new DoggoEntry(dd));
}
}
catch (Exception e) {
e.printStackTrace();
}
return li;
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
super.loadUsageRecipes(ingredient);
}
@Override
public Class<? extends GuiContainer> getGuiClass() {
return null;
}
@Override
public int recipiesPerPage() {
return 1;
}
@Override
public void drawExtras(int recipe)
{
CachedRecipe r = arecipes.get(recipe);
if (r instanceof DoggoEntry) {
if (renderEntity == null) {
renderEntity = new EntityLizardDoggo(Minecraft.getMinecraft().theWorld);
}
GL11.glPushMatrix();
double sc = 48;
GL11.glScaled(sc, sc, sc);
GL11.glTranslated(2, 2, 0);
GL11.glRotated(180, 0, 1, 1);
GL11.glRotated(135, 1, 0, 0);
GL11.glRotated(45, 0, 1, 0);
GL11.glScaled(1, -1, 1);
EntityPlayer ep = Minecraft.getMinecraft().thePlayer;
renderEntity.setLocationAndAngles(ep.posX, ep.posY, ep.posZ, 0, 0);
Render rd = ReikaEntityHelper.getEntityRenderer(EntityLizardDoggo.class);
//rd.doRender(renderEntity, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
BlendMode.DEFAULT.apply();
ReikaGuiAPI api = ReikaGuiAPI.instance;
api.drawLine(0, 3, 165, 3, 0xff707070);
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
DoggoDrop wc = ((DoggoEntry)r).item;
String n = wc.getItem().getDisplayName();
fr.drawString(n, 26, 5, 0x000000);
fr.drawString("Base Weight: "+wc.baseWeight, 26, 15, 0x000000);
String counts = wc.minCount == wc.maxCount ? wc.minCount+"x" : wc.minCount+"x - "+wc.maxCount+"x";
fr.drawString("Stack Size: "+counts, 26, 25, 0x000000);
int dy = 0;
Collection<Condition> li = wc.getRequirements();
if (!li.isEmpty()) {
api.drawLine(0, 37, 165, 37, 0xff707070);
fr.drawString("Requires:", 26, 40, 0x000000);
for (Condition c : li) {
String s = c.getDisplayString();
fr.drawSplitString(s, 32, 50+dy, 135, 0x000000);
dy += (fr.FONT_HEIGHT+2)*fr.listFormattedStringToWidth(s, 135).size();
}
dy += fr.FONT_HEIGHT+2;
}
Map<Condition, Double> map = wc.getModifiers();
map = new HashMap(map);
if (!map.isEmpty()) {
api.drawLine(0, 37+dy, 165, 37+dy, 0xff707070);
fr.drawString("Weight Modifiers:", 26, 40+dy, 0x000000);
for (Entry<Condition, Double> e : map.entrySet()) {
String s = e.getKey().getDisplayString()+": "+e.getValue()+"x";
fr.drawSplitString(s, 32, 50+dy, 135, 0x000000);
dy += (fr.FONT_HEIGHT+2)*fr.listFormattedStringToWidth(s, 135).size();
}
dy += fr.FONT_HEIGHT+2;
}
api.drawLine(0, 39+dy, 165, 39+dy, 0xff707070);
}
}
}