/
PluginArboriculture.java
607 lines (532 loc) · 23.2 KB
/
PluginArboriculture.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.arboriculture;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import forestry.api.arboriculture.EnumForestryWoodType;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.EnumPileType;
import forestry.api.arboriculture.EnumVanillaWoodType;
import forestry.api.arboriculture.IAlleleFruit;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.IWoodType;
import forestry.api.arboriculture.TreeManager;
import forestry.api.arboriculture.WoodBlockKind;
import forestry.api.core.CamouflageManager;
import forestry.api.core.ForestryAPI;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.ILeafTranslator;
import forestry.api.genetics.ISaplingTranslator;
import forestry.api.recipes.RecipeManagers;
import forestry.api.storage.ICrateRegistry;
import forestry.api.storage.StorageManager;
import forestry.arboriculture.blocks.BlockForestryLeaves;
import forestry.arboriculture.blocks.BlockPile;
import forestry.arboriculture.blocks.BlockRegistryArboriculture;
import forestry.arboriculture.blocks.log.BlockArbLog;
import forestry.arboriculture.blocks.slab.BlockArbSlab;
import forestry.arboriculture.commands.CommandTree;
import forestry.arboriculture.genetics.TreeBranchDefinition;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.arboriculture.genetics.TreeFactory;
import forestry.arboriculture.genetics.TreeMutationFactory;
import forestry.arboriculture.genetics.TreeRoot;
import forestry.arboriculture.genetics.TreekeepingMode;
import forestry.arboriculture.genetics.alleles.AlleleFruit;
import forestry.arboriculture.genetics.alleles.AlleleGrowth;
import forestry.arboriculture.genetics.alleles.AlleleLeafEffect;
import forestry.arboriculture.items.ItemCharcoal;
import forestry.arboriculture.items.ItemGrafter;
import forestry.arboriculture.items.ItemRegistryArboriculture;
import forestry.arboriculture.models.TextureLeaves;
import forestry.arboriculture.network.PacketRegistryArboriculture;
import forestry.arboriculture.proxy.ProxyArboriculture;
import forestry.arboriculture.proxy.ProxyArboricultureClient;
import forestry.arboriculture.tiles.TileFruitPod;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.arboriculture.tiles.TilePile;
import forestry.arboriculture.tiles.TileSapling;
import forestry.core.PluginCore;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.fluids.Fluids;
import forestry.core.genetics.alleles.AllelePlantType;
import forestry.core.items.ItemFruit.EnumFruit;
import forestry.core.network.IPacketRegistry;
import forestry.core.recipes.RecipeUtil;
import forestry.core.render.TextureManager;
import forestry.core.utils.IMCUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.OreDictUtil;
import forestry.core.utils.VillagerTradeLists;
import forestry.factory.recipes.FabricatorRecipe;
import forestry.plugins.BlankForestryPlugin;
import forestry.plugins.ForestryPlugin;
import forestry.plugins.ForestryPluginUids;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockNewLeaf;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.IFuelHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.VillagerRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
@ForestryPlugin(pluginID = ForestryPluginUids.ARBORICULTURE, name = "Arboriculture", author = "Binnie & SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.arboriculture.description")
public class PluginArboriculture extends BlankForestryPlugin {
@SidedProxy(clientSide = "forestry.arboriculture.proxy.ProxyArboricultureClient", serverSide = "forestry.arboriculture.proxy.ProxyArboriculture")
public static ProxyArboriculture proxy;
public static String treekeepingMode = "NORMAL";
public static final List<Block> validFences = new ArrayList<>();
public static ItemRegistryArboriculture items;
public static BlockRegistryArboriculture blocks;
public static VillagerRegistry.VillagerProfession villagerArborist;
@Override
public void setupAPI() {
TreeManager.treeFactory = new TreeFactory();
TreeManager.treeMutationFactory = new TreeMutationFactory();
TreeManager.woodAccess = new WoodAccess();
// Init tree interface
TreeManager.treeRoot = new TreeRoot();
AlleleManager.alleleRegistry.registerSpeciesRoot(TreeManager.treeRoot);
// Modes
TreeManager.treeRoot.registerTreekeepingMode(TreekeepingMode.easy);
TreeManager.treeRoot.registerTreekeepingMode(TreekeepingMode.normal);
TreeManager.treeRoot.registerTreekeepingMode(TreekeepingMode.hard);
TreeManager.treeRoot.registerTreekeepingMode(TreekeepingMode.hardcore);
TreeManager.treeRoot.registerTreekeepingMode(TreekeepingMode.insane);
}
@Override
public void registerItemsAndBlocks() {
items = new ItemRegistryArboriculture();
blocks = new BlockRegistryArboriculture();
}
@Override
public void preInit() {
super.preInit();
MinecraftForge.EVENT_BUS.register(this);
WoodAccess.registerLogs(blocks.logs);
WoodAccess.registerPlanks(blocks.planks);
WoodAccess.registerSlabs(blocks.slabs);
WoodAccess.registerFences(blocks.fences);
WoodAccess.registerFenceGates(blocks.fenceGates);
WoodAccess.registerStairs(blocks.stairs);
WoodAccess.registerDoors(blocks.doors);
WoodAccess.registerLogs(blocks.logsFireproof);
WoodAccess.registerPlanks(blocks.planksFireproof);
WoodAccess.registerSlabs(blocks.slabsFireproof);
WoodAccess.registerFences(blocks.fencesFireproof);
WoodAccess.registerFenceGates(blocks.fenceGatesFireproof);
WoodAccess.registerStairs(blocks.stairsFireproof);
WoodAccess.registerLogs(blocks.logsVanillaFireproof);
WoodAccess.registerPlanks(blocks.planksVanillaFireproof);
WoodAccess.registerSlabs(blocks.slabsVanillaFireproof);
WoodAccess.registerFences(blocks.fencesVanillaFireproof);
WoodAccess.registerFenceGates(blocks.fenceGatesVanillaFireproof);
WoodAccess.registerStairs(blocks.stairsVanillaFireproof);
// Init rendering
proxy.initializeModels();
// Commands
PluginCore.rootCommand.addChildCommand(new CommandTree());
CamouflageManager.camouflageAccess.registerCamouflageItemHandler(new CamouflageHandlerArbDoor());
}
@Override
public void addLootPoolNames(Set<String> lootPoolNames) {
super.addLootPoolNames(lootPoolNames);
lootPoolNames.add("forestry_arboriculture_items");
}
@Override
public void doInit() {
super.doInit();
// Create alleles
createAlleles();
TreeDefinition.initTrees();
registerErsatzGenomes();
GameRegistry.registerTileEntity(TileSapling.class, "forestry.Sapling");
GameRegistry.registerTileEntity(TileLeaves.class, "forestry.Leaves");
GameRegistry.registerTileEntity(TileFruitPod.class, "forestry.Pods");
GameRegistry.registerTileEntity(TilePile.class, "forestry.Piles");
blocks.treeChest.init();
if (Config.enableVillagers) {
villagerArborist = new VillagerRegistry.VillagerProfession(Constants.ID_VILLAGER_ARBORIST, Constants.TEXTURE_SKIN_LUMBERJACK, Constants.TEXTURE_SKIN_ZOMBIE_LUMBERJACK);
VillagerRegistry.instance().register(villagerArborist);
VillagerRegistry.VillagerCareer arboristCareer = new VillagerRegistry.VillagerCareer(villagerArborist, "arborist");
arboristCareer.addTrade(1,
new VillagerArboristTrades.GivePlanksForEmeralds(new EntityVillager.PriceInfo(1, 1), new EntityVillager.PriceInfo(10, 32)),
new VillagerArboristTrades.GivePollenForEmeralds(new EntityVillager.PriceInfo(1, 1), new EntityVillager.PriceInfo(1, 3), EnumGermlingType.SAPLING, 4)
);
arboristCareer.addTrade(2,
new VillagerArboristTrades.GivePlanksForEmeralds(new EntityVillager.PriceInfo(1, 1), new EntityVillager.PriceInfo(10, 32)),
new VillagerTradeLists.GiveItemForEmeralds(new EntityVillager.PriceInfo(1, 4), items.grafterProven.getItemStack(), new EntityVillager.PriceInfo(1, 1)),
new VillagerArboristTrades.GivePollenForEmeralds(new EntityVillager.PriceInfo(2, 3), new EntityVillager.PriceInfo(1, 1), EnumGermlingType.POLLEN, 6)
);
arboristCareer.addTrade(3,
new VillagerArboristTrades.GiveLogsForEmeralds(new EntityVillager.PriceInfo(2, 5), new EntityVillager.PriceInfo(6, 18)),
new VillagerArboristTrades.GiveLogsForEmeralds(new EntityVillager.PriceInfo(2, 5), new EntityVillager.PriceInfo(6, 18))
);
arboristCareer.addTrade(4,
new VillagerArboristTrades.GivePollenForEmeralds(new EntityVillager.PriceInfo(5, 20), new EntityVillager.PriceInfo(1, 1), EnumGermlingType.POLLEN, 10),
new VillagerArboristTrades.GivePollenForEmeralds(new EntityVillager.PriceInfo(5, 20), new EntityVillager.PriceInfo(1, 1), EnumGermlingType.SAPLING, 10)
);
}
}
@Override
public void registerCrates() {
ICrateRegistry crateRegistry = StorageManager.crateRegistry;
crateRegistry.registerCrate(EnumFruit.CHERRY.getStack());
crateRegistry.registerCrate(EnumFruit.WALNUT.getStack());
crateRegistry.registerCrate(EnumFruit.CHESTNUT.getStack());
crateRegistry.registerCrate(EnumFruit.LEMON.getStack());
crateRegistry.registerCrate(EnumFruit.PLUM.getStack());
crateRegistry.registerCrate(EnumFruit.PAPAYA.getStack());
crateRegistry.registerCrate(EnumFruit.DATES.getStack());
}
@Override
public void registerRecipes() {
for (BlockArbLog log : blocks.logs) {
ItemStack logInput = new ItemStack(log, 1, OreDictionary.WILDCARD_VALUE);
ItemStack coalOutput = new ItemStack(Items.COAL, 1, 1);
RecipeUtil.addSmelting(logInput, coalOutput, 0.15F);
}
List<IWoodType> allWoodTypes = new ArrayList<>();
Collections.addAll(allWoodTypes, EnumForestryWoodType.VALUES);
Collections.addAll(allWoodTypes, EnumVanillaWoodType.VALUES);
for (IWoodType woodType : allWoodTypes) {
ItemStack planks = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.PLANKS, false);
ItemStack logs = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.LOG, false);
ItemStack slabs = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.SLAB, false);
ItemStack fences = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.FENCE, false);
ItemStack fenceGates = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.FENCE_GATE, false);
ItemStack stairs = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.STAIRS, false);
ItemStack doors = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.DOOR, false);
ItemStack fireproofPlanks = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.PLANKS, true);
ItemStack fireproofLogs = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.LOG, true);
ItemStack fireproofSlabs = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.SLAB, true);
ItemStack fireproofFences = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.FENCE, true);
ItemStack fireproofFenceGates = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.FENCE_GATE, true);
ItemStack fireproofStairs = TreeManager.woodAccess.getStack(woodType, WoodBlockKind.STAIRS, true);
if (woodType instanceof EnumForestryWoodType) {
planks.stackSize = 4;
logs.stackSize = 1;
RecipeUtil.addShapelessRecipe(planks.copy(), logs.copy());
slabs.stackSize = 6;
planks.stackSize = 1;
RecipeUtil.addPriorityRecipe(slabs.copy(), "###", '#', planks.copy());
fences.stackSize = 3;
planks.stackSize = 1;
RecipeUtil.addRecipe(fences.copy(),
"#X#",
"#X#",
'#', planks.copy(), 'X', "stickWood");
fenceGates.stackSize = 1;
planks.stackSize = 1;
RecipeUtil.addRecipe(fenceGates.copy(),
"X#X",
"X#X",
'#', planks.copy(), 'X', "stickWood");
stairs.stackSize = 4;
planks.stackSize = 1;
RecipeUtil.addPriorityRecipe(stairs.copy(),
"# ",
"## ",
"###",
'#', planks.copy());
doors.stackSize = 3;
planks.stackSize = 1;
RecipeUtil.addPriorityRecipe(doors.copy(),
"## ",
"## ",
"## ",
'#', planks.copy());
}
fireproofPlanks.stackSize = 4;
fireproofLogs.stackSize = 1;
RecipeUtil.addShapelessRecipe(fireproofPlanks.copy(), fireproofLogs.copy());
fireproofSlabs.stackSize = 6;
fireproofPlanks.stackSize = 1;
RecipeUtil.addPriorityRecipe(fireproofSlabs.copy(),
"###",
'#', fireproofPlanks.copy());
fireproofFences.stackSize = 3;
fireproofPlanks.stackSize = 1;
RecipeUtil.addRecipe(fireproofFences.copy(),
"#X#",
"#X#",
'#', fireproofPlanks.copy(), 'X', "stickWood");
fireproofFenceGates.stackSize = 1;
fireproofPlanks.stackSize = 1;
RecipeUtil.addRecipe(fireproofFenceGates.copy(),
"X#X",
"X#X",
'#', fireproofPlanks.copy(), 'X', "stickWood");
fireproofStairs.stackSize = 4;
fireproofPlanks.stackSize = 1;
RecipeUtil.addPriorityRecipe(fireproofStairs.copy(),
"# ",
"## ",
"###",
'#', fireproofPlanks.copy());
doors.stackSize = 3;
fireproofPlanks.stackSize = 1;
RecipeUtil.addPriorityRecipe(doors.copy(),
"## ",
"## ",
"## ",
'#', fireproofPlanks.copy());
// Fabricator recipes
if (ForestryAPI.enabledPlugins.containsAll(Arrays.asList(ForestryPluginUids.FACTORY, ForestryPluginUids.APICULTURE))) {
logs.stackSize = 1;
fireproofLogs.stackSize = 1;
RecipeManagers.fabricatorManager.addRecipe(new FabricatorRecipe(null, Fluids.GLASS.getFluid(500), fireproofLogs.copy(), new Object[]{
" # ",
"#X#",
" # ",
'#', PluginCore.items.refractoryWax,
'X', logs.copy()}));
planks.stackSize = 1;
fireproofPlanks.stackSize = 5;
RecipeManagers.fabricatorManager.addRecipe(new FabricatorRecipe(null, Fluids.GLASS.getFluid(500), fireproofPlanks.copy(), new Object[]{
"X#X",
"#X#",
"X#X",
'#', PluginCore.items.refractoryWax,
'X', planks.copy()}));
}
}
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FACTORY)) {
// SQUEEZER RECIPES
int seedOilMultiplier = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed");
int juiceMultiplier = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple");
int mulchMultiplier = ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple");
ItemStack mulch = new ItemStack(PluginCore.items.mulch);
RecipeManagers.squeezerManager.addRecipe(20, new ItemStack[]{EnumFruit.CHERRY.getStack()}, Fluids.SEED_OIL.getFluid(5 * seedOilMultiplier), mulch, 5);
RecipeManagers.squeezerManager.addRecipe(60, new ItemStack[]{EnumFruit.WALNUT.getStack()}, Fluids.SEED_OIL.getFluid(18 * seedOilMultiplier), mulch, 5);
RecipeManagers.squeezerManager.addRecipe(70, new ItemStack[]{EnumFruit.CHESTNUT.getStack()}, Fluids.SEED_OIL.getFluid(22 * seedOilMultiplier), mulch, 2);
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.LEMON.getStack()}, Fluids.JUICE.getFluid(juiceMultiplier * 2), mulch, (int) Math.floor(mulchMultiplier * 0.5f));
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.PLUM.getStack()}, Fluids.JUICE.getFluid((int) Math.floor(juiceMultiplier * 0.5f)), mulch, mulchMultiplier * 3);
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.PAPAYA.getStack()}, Fluids.JUICE.getFluid(juiceMultiplier * 3), mulch, (int) Math.floor(mulchMultiplier * 0.5f));
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.DATES.getStack()}, Fluids.JUICE.getFluid((int) Math.floor(juiceMultiplier * 0.25)), mulch, mulchMultiplier);
RecipeUtil.addFermenterRecipes(items.sapling.getItemStack(), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS);
}
// Grafter
RecipeUtil.addRecipe(items.grafter.getItemStack(),
" B",
" # ",
"# ",
'B', "ingotBronze",
'#', "stickWood");
RecipeUtil.addRecipe(blocks.treeChest,
" # ",
"XYX",
"XXX",
'#', "blockGlass",
'X', "treeSapling",
'Y', "chestWood");
//Wood Piles
for (ITree tree : TreeManager.treeRoot.getIndividualTemplates()) {
IAlleleTreeSpecies treeSpecies = tree.getGenome().getPrimary();
ItemStack log = treeSpecies.getWoodProvider().getWoodStack().copy();
log.stackSize = 1;
ItemStack woodPile = BlockPile.createWoodPile(treeSpecies);
RecipeUtil.addShapelessRecipe(woodPile, log, log, log, log);
}
//Dirt Pile Block
RecipeUtil.addShapelessRecipe(new ItemStack(PluginArboriculture.blocks.piles.get(EnumPileType.DIRT)), OreDictUtil.DUST_ASH, Items.CLAY_BALL, OreDictUtil.DUST_ASH, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.DIRT, OreDictUtil.TREE_LEAVES, Items.CLAY_BALL, OreDictUtil.TREE_LEAVES);
}
private static void createAlleles() {
TreeBranchDefinition.createAlleles();
AlleleGrowth.createAlleles();
AlleleLeafEffect.createAlleles();
AllelePlantType.createAlleles();
}
private static void registerErsatzGenomes() {
AlleleManager.leafTranslators.put(Blocks.LEAVES, new ILeafTranslator() {
@Nullable
@Override
public ITree getTreeFromLeaf(IBlockState leafBlockState) {
if (!leafBlockState.getValue(BlockLeaves.DECAYABLE)) {
return null;
}
switch (leafBlockState.getValue(BlockOldLeaf.VARIANT)) {
case OAK:
return TreeDefinition.Oak.getIndividual();
case SPRUCE:
return TreeDefinition.Spruce.getIndividual();
case BIRCH:
return TreeDefinition.Birch.getIndividual();
case JUNGLE:
return TreeDefinition.Jungle.getIndividual();
}
return null;
}
});
AlleleManager.leafTranslators.put(Blocks.LEAVES2, new ILeafTranslator() {
@Nullable
@Override
public ITree getTreeFromLeaf(IBlockState leafBlockState) {
if (!leafBlockState.getValue(BlockLeaves.DECAYABLE)) {
return null;
}
switch (leafBlockState.getValue(BlockNewLeaf.VARIANT)) {
case ACACIA:
return TreeDefinition.AcaciaVanilla.getIndividual();
case DARK_OAK:
return TreeDefinition.DarkOak.getIndividual();
}
return null;
}
});
AlleleManager.saplingTranslation.put(Item.getItemFromBlock(Blocks.SAPLING), new ISaplingTranslator() {
@Nullable
@Override
public ITree getTreeFromSapling(ItemStack sapling) {
switch (sapling.getMetadata()) {
case 0:
return TreeDefinition.Oak.getIndividual();
case 1:
return TreeDefinition.Spruce.getIndividual();
case 2:
return TreeDefinition.Birch.getIndividual();
case 3:
return TreeDefinition.Jungle.getIndividual();
case 4:
return TreeDefinition.AcaciaVanilla.getIndividual();
case 5:
return TreeDefinition.DarkOak.getIndividual();
}
return null;
}
});
}
@Override
public IFuelHandler getFuelHandler() {
return new FuelHandler();
}
@Override
public IPacketRegistry getPacketRegistry() {
return new PacketRegistryArboriculture();
}
@Override
public boolean processIMCMessage(IMCMessage message) {
if (message.key.equals("add-fence-block") && message.isStringMessage()) {
Block block = ItemStackUtil.getBlockFromRegistry(message.getStringValue());
if (block != null) {
validFences.add(block);
} else {
IMCUtil.logInvalidIMCMessage(message);
}
return true;
}
return super.processIMCMessage(message);
}
@Override
public void getHiddenItems(List<ItemStack> hiddenItems) {
// sapling itemBlock is different from the normal item
hiddenItems.add(new ItemStack(blocks.saplingGE));
}
private static class FuelHandler implements IFuelHandler {
@Override
public int getBurnTime(ItemStack fuel) {
Item item = fuel.getItem();
if (items.sapling == item) {
return 100;
}
if(items.charcoal == item){
return ItemCharcoal.getBurnTime(fuel);
}
Block block = Block.getBlockFromItem(item);
if (block instanceof IWoodTyped) {
IWoodTyped woodTypedBlock = (IWoodTyped) block;
if (woodTypedBlock.isFireproof()) {
return 0;
} else if (block instanceof BlockArbSlab) {
return 150;
}else{
return 300;
}
}
return 0;
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void registerSprites(TextureStitchEvent.Pre event) {
TextureLeaves.registerAllSprites();
for (IAlleleFruit alleleFruit : AlleleFruit.getFruitAlleles()) {
alleleFruit.getProvider().registerSprites();
}
List<ResourceLocation> textures = new ArrayList<>();
for(IWoodType type : TreeManager.woodAccess.getRegisteredWoodTypes()){
textures.add(new ResourceLocation(type.getHeartTexture()));
textures.add(new ResourceLocation(type.getBarkTexture()));
textures.add(new ResourceLocation(type.getDoorLowerTexture()));
textures.add(new ResourceLocation(type.getDoorUpperTexture()));
textures.add(new ResourceLocation(type.getPlankTexture()));
}
for(ResourceLocation loc : textures){
TextureManager.getInstance();
TextureManager.registerSprite(loc);
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onModelBake(ModelBakeEvent event) {
((ProxyArboricultureClient)proxy).onModelBake(event);
}
@SubscribeEvent
public void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent event) {
IBlockState state = event.getState();
Block block = state.getBlock();
if (block instanceof BlockLeaves && !(block instanceof BlockForestryLeaves)) {
EntityPlayer player = event.getHarvester();
if (player != null) {
ItemStack harvestingTool = player.getHeldItemMainhand();
if (harvestingTool != null && harvestingTool.getItem() instanceof ItemGrafter) {
if (event.getDrops().isEmpty()) {
World world = event.getWorld();
Item itemDropped = block.getItemDropped(state, world.rand, 3);
if (itemDropped != null) {
event.getDrops().add(new ItemStack(itemDropped, 1, block.damageDropped(state)));
}
}
harvestingTool.damageItem(1, player);
if (harvestingTool.stackSize <= 0) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, harvestingTool, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, null);
}
}
}
}
}
}