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
|
package gregtech.common.tileentities.machines.basic;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import gregtech.api.enums.GTValues;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.MachineType;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.MTEBasicMachine;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.RecipeMaps;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;
public class MTEBoxinator extends MTEBasicMachine {
ItemStack aInputCache;
ItemStack aOutputCache;
int aTypeCache = 0;
public MTEBoxinator(int aID, String aName, String aNameRegional, int aTier) {
super(
aID,
aName,
aNameRegional,
aTier,
1,
MachineType.PACKAGER.tooltipDescription(),
2,
1,
TextureFactory.of(
TextureFactory
.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR_ACTIVE")),
TextureFactory.builder()
.addIcon(
new Textures.BlockIcons.CustomIcon(
"basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR_ACTIVE_GLOW"))
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR")),
TextureFactory.builder()
.addIcon(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_SIDE_BOXINATOR_GLOW"))
.glow()
.build()),
TextureFactory.of(
TextureFactory
.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR_ACTIVE")),
TextureFactory.builder()
.addIcon(
new Textures.BlockIcons.CustomIcon(
"basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR_ACTIVE_GLOW"))
.glow()
.build()),
TextureFactory.of(
TextureFactory
.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR")),
TextureFactory.builder()
.addIcon(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_FRONT_BOXINATOR_GLOW"))
.glow()
.build()),
TextureFactory.of(
TextureFactory
.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR_ACTIVE")),
TextureFactory.builder()
.addIcon(
new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR_ACTIVE_GLOW"))
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR")),
TextureFactory.builder()
.addIcon(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_TOP_BOXINATOR_GLOW"))
.glow()
.build()),
TextureFactory.of(
TextureFactory
.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR_ACTIVE")),
TextureFactory.builder()
.addIcon(
new Textures.BlockIcons.CustomIcon(
"basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR_ACTIVE_GLOW"))
.glow()
.build()),
TextureFactory.of(
TextureFactory
.of(new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR")),
TextureFactory.builder()
.addIcon(
new Textures.BlockIcons.CustomIcon("basicmachines/boxinator/OVERLAY_BOTTOM_BOXINATOR_GLOW"))
.glow()
.build()));
}
public MTEBoxinator(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 1, aDescription, aTextures, 2, 1);
}
@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTEBoxinator(this.mName, this.mTier, this.mDescriptionArray, this.mTextures);
}
@Override
public RecipeMap<?> getRecipeMap() {
return RecipeMaps.packagerRecipes;
}
private boolean hasValidCache(ItemStack mItem, int mType, boolean mClearOnFailure) {
if (aInputCache != null && aOutputCache != null
&& aTypeCache == mType
&& aInputCache.isItemEqual(mItem)
&& ItemStack.areItemStackTagsEqual(mItem, aInputCache)) return true;
// clear cache if it was invalid
if (mClearOnFailure) {
aInputCache = null;
aOutputCache = null;
aTypeCache = 0;
}
return false;
}
private void cacheItem(ItemStack mInputItem, ItemStack mOutputItem, int mType) {
aTypeCache = mType;
aOutputCache = mOutputItem.copy();
aInputCache = mInputItem.copy();
}
@Override
public int checkRecipe() {
int tCheck = super.checkRecipe();
if (tCheck != DID_NOT_FIND_RECIPE) {
return tCheck;
}
ItemStack tSlot0 = getInputAt(0);
ItemStack tSlot1 = getInputAt(1);
if ((GTUtility.isStackValid(tSlot0)) && (GTUtility.isStackValid(tSlot1))
&& (GTUtility.getContainerItem(tSlot0, true) == null)) {
if ((ItemList.Schematic_1by1.isStackEqual(tSlot1)) && (tSlot0.stackSize >= 1)) {
boolean tIsCached = hasValidCache(tSlot0, 1, true);
this.mOutputItems[0] = tIsCached ? aOutputCache.copy() : GTModHandler.getRecipeOutput(tSlot0);
if (this.mOutputItems[0] != null) {
if (canOutput(this.mOutputItems[0])) {
tSlot0.stackSize -= 1;
calculateOverclockedNess(30, 16);
// In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
if (!tIsCached) cacheItem(tSlot0, this.mOutputItems[0], 1);
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
}
return DID_NOT_FIND_RECIPE;
}
if ((ItemList.Schematic_2by2.isStackEqual(tSlot1)) && (getInputAt(0).stackSize >= 4)) {
boolean tIsCached = hasValidCache(tSlot0, 2, true);
this.mOutputItems[0] = tIsCached ? aOutputCache.copy()
: GTModHandler.getRecipeOutput(tSlot0, tSlot0, null, tSlot0, tSlot0);
if (this.mOutputItems[0] != null) {
if (canOutput(this.mOutputItems[0])) {
getInputAt(0).stackSize -= 4;
calculateOverclockedNess(30, 32);
// In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
if (!tIsCached) cacheItem(tSlot0, this.mOutputItems[0], 2);
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
}
return DID_NOT_FIND_RECIPE;
}
if ((ItemList.Schematic_3by3.isStackEqual(tSlot1)) && (getInputAt(0).stackSize >= 9)) {
boolean tIsCached = hasValidCache(tSlot0, 3, true);
this.mOutputItems[0] = tIsCached ? aOutputCache.copy()
: GTModHandler
.getRecipeOutput(tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0);
if (this.mOutputItems[0] != null) {
if (canOutput(this.mOutputItems[0])) {
getInputAt(0).stackSize -= 9;
calculateOverclockedNess(30, 64);
// In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
if (!tIsCached) cacheItem(tSlot0, this.mOutputItems[0], 3);
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
}
return DID_NOT_FIND_RECIPE;
}
}
return DID_NOT_FIND_RECIPE;
}
@Override
protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
if (!super.allowPutStackValidated(aBaseMetaTileEntity, aIndex, side, aStack)) {
return false;
}
ItemStack tInput1 = getInputAt(1);
if ((ItemList.Schematic_1by1.isStackEqual(tInput1)) || (ItemList.Schematic_2by2.isStackEqual(tInput1))
|| (ItemList.Schematic_3by3.isStackEqual(tInput1))) {
if (hasValidCache(aStack, aTypeCache, false)) return true;
if (RecipeMaps.packagerRecipes.findRecipeQuery()
.items(GTUtility.copyAmount(64, aStack), tInput1)
.voltage(GTValues.V[mTier])
.notUnificated(true)
.find() != null) {
return true;
}
if (ItemList.Schematic_1by1.isStackEqual(getInputAt(1)) && GTModHandler.getRecipeOutput(aStack) != null)
return true;
if (ItemList.Schematic_2by2.isStackEqual(getInputAt(1))
&& GTModHandler.getRecipeOutput(aStack, aStack, null, aStack, aStack) != null) {
return true;
}
return ItemList.Schematic_3by3.isStackEqual(getInputAt(1))
&& (GTModHandler.getRecipeOutput(aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack, aStack)
!= null);
} else {
return RecipeMaps.packagerRecipes.containsInput(aStack);
}
}
}
|