-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathGTFOMetaBlocks.java
More file actions
203 lines (176 loc) · 8.62 KB
/
GTFOMetaBlocks.java
File metadata and controls
203 lines (176 loc) · 8.62 KB
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
package gregtechfoodoption.block;
import com.google.common.collect.ImmutableMap;
import gregtech.api.GTValues;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Materials;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.unification.stack.ItemMaterialInfo;
import gregtech.api.unification.stack.MaterialStack;
import gregtech.common.ConfigHolder;
import gregtechfoodoption.block.tree.GTFOBlockLeaves;
import gregtechfoodoption.block.tree.GTFOBlockLog;
import gregtechfoodoption.block.tree.GTFOBlockPlanks;
import gregtechfoodoption.block.tree.GTFOBlockSapling;
import gregtechfoodoption.worldgen.berries.GTFOBerries;
import gregtechfoodoption.worldgen.trees.GTFOTree;
import gregtechfoodoption.worldgen.trees.GTFOTrees;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.*;
import java.util.stream.Collectors;
public class GTFOMetaBlocks {
public static GTFOBlockCasing GTFO_CASING;
public static GTFOMetalCasing GTFO_METAL_CASING;
public static GTFOGlassCasing GTFO_GLASS_CASING;
public static GTFOPizza PIZZA_MINCEMEAT;
public static GTFOPizza PIZZA_CHEESE;
public static GTFOPizza PIZZA_VEGGIE;
public static GTFOPizzaBox PIZZA_BOX_MINCEMEAT;
public static GTFOPizzaBox PIZZA_BOX_CHEESE;
public static GTFOPizzaBox PIZZA_BOX_VEGGIE;
public static List<GTFOBlockLeaves> GTFO_LEAVES = new ArrayList<>();
public static List<GTFOBlockLog> GTFO_LOGS = new ArrayList<>();
public static List<GTFOBlockPlanks> GTFO_PLANKS = new ArrayList<>();
public static List<GTFOBlockSapling> GTFO_SAPLINGS = new ArrayList<>();
public static void init() {
GTFO_CASING = new GTFOBlockCasing();
GTFO_CASING.setRegistryName("gtfo_casing");
GTFO_METAL_CASING = new GTFOMetalCasing();
GTFO_METAL_CASING.setRegistryName("gtfo_metal_casing");
GTFO_GLASS_CASING = new GTFOGlassCasing();
GTFO_GLASS_CASING.setRegistryName("gtfo_glass_casing");
PIZZA_MINCEMEAT = new GTFOPizza("pizza_mincemeat");
PIZZA_MINCEMEAT.setRegistryName("pizza_mincemeat");
PIZZA_CHEESE = new GTFOPizza("pizza_cheese");
PIZZA_CHEESE.setRegistryName("pizza_cheese");
PIZZA_VEGGIE = new GTFOPizza("pizza_veggie");
PIZZA_VEGGIE.setRegistryName("pizza_veggie");
PIZZA_BOX_MINCEMEAT = new GTFOPizzaBox("pizza_box_mincemeat", PIZZA_MINCEMEAT);
PIZZA_BOX_MINCEMEAT.setRegistryName("pizza_box_mincemeat");
PIZZA_BOX_CHEESE = new GTFOPizzaBox("pizza_box_cheese", PIZZA_CHEESE);
PIZZA_BOX_CHEESE.setRegistryName("pizza_box_cheese");
PIZZA_BOX_VEGGIE = new GTFOPizzaBox("pizza_box_veggie", PIZZA_VEGGIE);
PIZZA_BOX_VEGGIE.setRegistryName("pizza_box_veggie");
GTFOTrees.init();
GTFOBerries.init();
for (int i = 0; i <= (GTFOTree.TREES.size() - 1) / 4; i++) {
GTFOBlockLeaves leaves = new GTFOBlockLeaves(i);
leaves.setRegistryName("gtfo_leaves_" + i);
}
for (int i = 0; i <= (GTFOTree.TREES.size() - 1) / 4; i++) {
GTFOBlockLog log = new GTFOBlockLog(i);
log.setRegistryName("gtfo_log_" + i);
}
for (int i = 0; i <= (GTFOTree.TREES.size() - 1) / 8; i++) {
GTFOBlockSapling sapling = new GTFOBlockSapling(i);
sapling.setRegistryName("gtfo_sapling_" + i);
}
for (int i = 0; i <= (GTFOTree.TREES.size() - 1) / 16; i++) {
GTFOBlockPlanks planks = new GTFOBlockPlanks(i);
planks.setRegistryName("gtfo_planks_" + i);
}
GTFOCrops.init();
GTFOTree.TREES.forEach(GTFOTree::setupBlocks);
}
@SideOnly(Side.CLIENT)
public static void registerItemModels() {
registerItemModel(GTFO_CASING);
registerItemModel(GTFO_METAL_CASING);
registerItemModel(GTFO_GLASS_CASING);
registerItemModel(PIZZA_BOX_MINCEMEAT);
registerItemModel(PIZZA_BOX_CHEESE);
registerItemModel(PIZZA_BOX_VEGGIE);
GTFO_LEAVES.forEach(GTFOMetaBlocks::registerItemModel);
GTFO_SAPLINGS.forEach(GTFOMetaBlocks::registerItemModel);
for (GTFOBlockSapling sapling : GTFO_SAPLINGS) {
registerItemModel(sapling);
for (int v = 0; v < 8; v++)
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(sapling), v << 1,
new ModelResourceLocation(sapling.getRegistryName() + "_" + v, "inventory"));
}
for (GTFOBlockLog log : GTFO_LOGS) {
registerItemModelWithOverride(log, ImmutableMap.of(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Y));
}
GTFO_PLANKS.forEach(GTFOMetaBlocks::registerItemModel);
}
@SideOnly(Side.CLIENT)
private static void registerItemModel(Block block) {
for (IBlockState state : block.getBlockState().getValidStates()) {
//noinspection ConstantConditions
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block),
block.getMetaFromState(state),
new ModelResourceLocation(block.getRegistryName(),
statePropertiesToString(state.getProperties())));
}
}
@SideOnly(Side.CLIENT)
private static void registerItemModelWithOverride(Block block, Map<IProperty<?>, Comparable<?>> stateOverrides) {
for (IBlockState state : block.getBlockState().getValidStates()) {
HashMap<IProperty<?>, Comparable<?>> stringProperties = new HashMap<>(state.getProperties());
stringProperties.putAll(stateOverrides);
//noinspection ConstantConditions
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block),
block.getMetaFromState(state),
new ModelResourceLocation(block.getRegistryName(),
statePropertiesToString(stringProperties)));
}
}
public static void registerOreDict() {
GTFO_LEAVES.forEach(leaves -> {
OreDictUnifier.registerOre(new ItemStack(leaves, 1, GTValues.W), "treeLeaves");
});
GTFO_SAPLINGS.forEach(sapling -> {
OreDictUnifier.registerOre(new ItemStack(sapling, 1, GTValues.W), "treeSapling");
});
GTFO_LOGS.forEach(log -> {
OreDictUnifier.registerOre(new ItemStack(log, 1, GTValues.W), OrePrefix.log, Materials.Wood);
if (!ConfigHolder.recipes.harderCharcoalRecipe) {
GameRegistry.addSmelting(new ItemStack(log, 1, GTValues.W), new ItemStack(Items.COAL, 1, 1), 0.15F);
}
});
GTFO_PLANKS.forEach(planks -> {
OreDictUnifier.registerOre(new ItemStack(planks, 1, GTValues.W), OrePrefix.plank, Materials.Wood);
OreDictUnifier.registerOre(new ItemStack(planks, 1, GTValues.W), new ItemMaterialInfo(new MaterialStack(Materials.Wood, GTValues.M)));
});
}
private static String statePropertiesToString(Map<IProperty<?>, Comparable<?>> properties) {
StringBuilder stringbuilder = new StringBuilder();
List<Map.Entry<IProperty<?>, Comparable<?>>> entries = properties.entrySet().stream()
.sorted(Comparator.comparing(c -> c.getKey().getName()))
.collect(Collectors.toList());
for (Map.Entry<IProperty<?>, Comparable<?>> entry : entries) {
if (stringbuilder.length() != 0) {
stringbuilder.append(",");
}
IProperty<?> property = entry.getKey();
stringbuilder.append(property.getName());
stringbuilder.append("=");
stringbuilder.append(getPropertyName(property, entry.getValue()));
}
if (stringbuilder.length() == 0) {
stringbuilder.append("normal");
}
return stringbuilder.toString();
}
@SuppressWarnings("unchecked")
private static <T extends Comparable<T>> String getPropertyName(IProperty<T> property, Comparable<?> value) {
return property.getName((T) value);
}
@SideOnly(Side.CLIENT)
public static void registerStateMappers() {
}
@SideOnly(Side.CLIENT)
public static void registerColors() {
GTFO_LEAVES.forEach(GTFOBlockLeaves::registerColors);
}
}