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
|
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
* NotEnoughUpdates is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* NotEnoughUpdates is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.moulberry.notenoughupdates.recipes;
import com.google.common.collect.Sets;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.util.ResourceLocation;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class VillagerTradeRecipe implements NeuRecipe {
public static final int COST_SLOT_X = 52;
public static final int COST_SLOT_Y = 66;
public static final int RESULT_SLOT_Y = 66;
public static final int RESULT_SLOT_X = 124;
private static class Holder { // This holder object exists to defer initialization to first access
private static final GameProfile DREAM_PROFILE = new GameProfile(UUID.fromString(
"ec70bcaf-702f-4bb8-b48d-276fa52a780c"), "Dream");
private static final EntityLivingBase DEMO_DREAM = new AbstractClientPlayer(null, DREAM_PROFILE) {
@Override
protected NetworkPlayerInfo getPlayerInfo() {
return new NetworkPlayerInfo(DREAM_PROFILE) {
@Override
public ResourceLocation getLocationSkin() {
return new ResourceLocation("notenoughupdates", "dreamskin.png");
}
};
}
};
private static final EntityLivingBase DEMO_VILLAGER = new EntityVillager(null);
private static boolean isAprilFirst() {
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.DAY_OF_MONTH) == 1 && cal.get(Calendar.MONTH) == Calendar.APRIL;
}
private static final EntityLivingBase DEMO_ENTITY = isAprilFirst() ? DEMO_DREAM : DEMO_VILLAGER;
}
private final static ResourceLocation BACKGROUND = new ResourceLocation(
"notenoughupdates",
"textures/gui/villager_recipe_tall.png"
);
private final Ingredient result;
private final Ingredient cost;
private final int minCost, maxCost;
public VillagerTradeRecipe(Ingredient result, Ingredient cost, int minCost, int maxCost) {
this.result = result;
this.cost = cost;
this.minCost = minCost;
this.maxCost = maxCost;
}
public VillagerTradeRecipe(Ingredient result, Ingredient cost) {
this(result, cost, -1, -1);
}
public boolean hasVariableCost() {
return minCost != -1 && maxCost != -1;
}
@Override
public RecipeType getType() {
return RecipeType.TRADE;
}
@Override
public Set<Ingredient> getIngredients() {
return Sets.newHashSet(cost);
}
@Override
public Set<Ingredient> getOutputs() {
return Sets.newHashSet(result);
}
@Override
public List<RecipeSlot> getSlots() {
return Arrays.asList(
new RecipeSlot(COST_SLOT_X, COST_SLOT_Y, cost.getItemStack()),
new RecipeSlot(RESULT_SLOT_X, RESULT_SLOT_Y, result.getItemStack())
);
}
@Override
public boolean shouldUseForCraftCost() {
return false;
}
@Override
public boolean isAvailable() {
return SBInfo.getInstance().getCurrentMode() == SBInfo.Gamemode.STRANDED ||
NotEnoughUpdates.INSTANCE.config.hidden.dev;
}
@Override
public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) {
if (hasVariableCost()) {
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
Utils.drawStringCenteredScaledMaxWidth(
minCost + " - " + maxCost, fontRenderer,
gui.guiLeft + 50, gui.guiTop + 90, false, 75, 0xff00ff
);
}
}
@Override
public void drawExtraBackground(GuiItemRecipe gui, int mouseX, int mouseY) {
GuiInventory.drawEntityOnScreen(
gui.guiLeft + 90,
gui.guiTop + 100,
30,
gui.guiLeft - mouseX + 110,
gui.guiTop + 60 - mouseY,
Holder.DEMO_ENTITY
);
}
@Override
public JsonObject serialize() {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("type", "trade");
jsonObject.addProperty("result", result.serialize());
jsonObject.addProperty("cost", cost.serialize());
if (minCost > 0)
jsonObject.addProperty("min", minCost);
if (maxCost > 0)
jsonObject.addProperty("max", maxCost);
return jsonObject;
}
@Override
public ResourceLocation getBackground() {
return BACKGROUND;
}
public static VillagerTradeRecipe parseStaticRecipe(NEUManager manager, JsonObject recipe, JsonObject result) {
return new VillagerTradeRecipe(
new Ingredient(manager, recipe.get("result").getAsString()),
new Ingredient(manager, recipe.get("cost").getAsString()),
recipe.has("min") ? recipe.get("min").getAsInt() : -1,
recipe.has("max") ? recipe.get("max").getAsInt() : -1
);
}
}
|