Skip to content

Commit

Permalink
Remove FertilizationEvent entirely (breaking change)
Browse files Browse the repository at this point in the history
> FertilizationEvent has always been a pain to maintain (due to constant hard-to-debug issues, compounded by the fact that it touches every IGrowable), and as far as I'm aware it's never been used by any mod that depends on AppleCore (except Biota, but it was never finished).

Closes #107, closes #96
  • Loading branch information
squeek502 committed Nov 29, 2017
1 parent aed8b48 commit 6ccaf20
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 401 deletions.
77 changes: 0 additions & 77 deletions java/squeek/applecore/api/plants/FertilizationEvent.java

This file was deleted.

69 changes: 0 additions & 69 deletions java/squeek/applecore/asm/Hooks.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package squeek.applecore.asm;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCake;
Expand All @@ -20,10 +17,7 @@
import squeek.applecore.api.hunger.ExhaustionEvent;
import squeek.applecore.api.hunger.HealthRegenEvent;
import squeek.applecore.api.hunger.StarvationEvent;
import squeek.applecore.api.plants.FertilizationEvent;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.common.eventhandler.Event.Result;
import squeek.applecore.asm.util.IAppleCoreFertilizable;

public class Hooks
{
Expand Down Expand Up @@ -165,69 +159,6 @@ public static void fireOnGrowthWithoutMetadataChangeEvent(Block block, World wor
AppleCoreAPI.dispatcher.announcePlantGrowthWithoutMetadataChange(block, world, x, y, z);
}

private static final Random fertilizeRandom = new Random();
private static final Map<String, Class<?>[]> fertilizeMethods = new HashMap<String, Class<?>[]>();
static
{
fertilizeMethods.put(ASMConstants.HarvestCraft.BlockPamFruit, new Class<?>[] { World.class, int.class, int.class, int.class });
fertilizeMethods.put(ASMConstants.HarvestCraft.BlockPamSapling, new Class<?>[] { World.class, int.class, int.class, int.class, Random.class });
}

public static void fireAppleCoreFertilizeEvent(Block block, World world, int x, int y, int z, Random random)
{
// if the block does not implement our dummy interface, then the transformation did occur
if (!(block instanceof IAppleCoreFertilizable))
return;

if (random == null)
random = fertilizeRandom;

int previousMetadata = world.getBlockMetadata(x, y, z);

FertilizationEvent.Fertilize event = new FertilizationEvent.Fertilize(block, world, x, y, z, random, previousMetadata);
MinecraftForge.EVENT_BUS.post(event);
Event.Result fertilizeResult = event.getResult();

if (fertilizeResult == Event.Result.DENY)
return;

if (fertilizeResult == Event.Result.DEFAULT)
{
IAppleCoreFertilizable fertilizableBlock = (IAppleCoreFertilizable) block;
try
{
if (fertilizeMethods.containsKey(block.getClass().getName()))
{
Class<?>[] argTypes = fertilizeMethods.get(block.getClass().getName());
if (argTypes.length == 4)
fertilizableBlock.AppleCore_fertilize(world, x, y, z);
else
fertilizableBlock.AppleCore_fertilize(world, x, y, z, random);
}
else
{
fertilizableBlock.AppleCore_fertilize(world, random, x, y, z);
}
}
catch (RuntimeException e)
{
throw e;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}

Hooks.fireFertilizedEvent(block, world, x, y, z, previousMetadata);
}

public static void fireFertilizedEvent(Block block, World world, int x, int y, int z, int previousMetadata)
{
FertilizationEvent.Fertilized event = new FertilizationEvent.Fertilized(block, world, x, y, z, previousMetadata);
MinecraftForge.EVENT_BUS.post(event);
}

public static int toolTipX, toolTipY, toolTipW, toolTipH;

public static void onDrawHoveringText(int x, int y, int w, int h)
Expand Down
1 change: 0 additions & 1 deletion java/squeek/applecore/asm/TransformerModuleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class TransformerModuleHandler implements IClassTransformer
registerTransformerModule(new ModuleBlockFood());
registerTransformerModule(new ModuleDrawTooltip());
registerTransformerModule(new ModulePeacefulRegen());
registerTransformerModule(new ModulePlantFertilization());
}

public static void registerTransformerModule(IClassTransformerModule transformerModule)
Expand Down
147 changes: 0 additions & 147 deletions java/squeek/applecore/asm/module/ModulePlantFertilization.java

This file was deleted.

47 changes: 0 additions & 47 deletions java/squeek/applecore/asm/reference/IGrowableModifications.java

This file was deleted.

18 changes: 0 additions & 18 deletions java/squeek/applecore/asm/util/IAppleCoreFertilizable.java

This file was deleted.

1 change: 0 additions & 1 deletion java/squeek/applecore/example/AppleCoreExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void init(FMLInitializationEvent event)
MinecraftForge.EVENT_BUS.register(new HealthRegenModifier());
MinecraftForge.EVENT_BUS.register(new StarvationModifier());
MinecraftForge.EVENT_BUS.register(new PlantGrowthModifier());
MinecraftForge.EVENT_BUS.register(new FertilizationModifier());
}
if (event.getSide() == Side.CLIENT)
MinecraftForge.EVENT_BUS.register(new FoodValuesTooltipHandler());
Expand Down
Loading

0 comments on commit 6ccaf20

Please sign in to comment.