Skip to content

Commit

Permalink
Remove unneeded ReflectionModule once and for all! (reverted from com…
Browse files Browse the repository at this point in the history
…mit a11def2)
  • Loading branch information
alexbegt committed Jan 22, 2018
1 parent ba0f059 commit e74b946
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/main/java/iguanaman/hungeroverhaul/HungerOverhaul.java
Expand Up @@ -22,6 +22,7 @@
import iguanaman.hungeroverhaul.module.loot.LootModule;
import iguanaman.hungeroverhaul.module.natura.NaturaModule;
import iguanaman.hungeroverhaul.module.natura.helper.NaturaHelper;
import iguanaman.hungeroverhaul.module.reflection.ReflectionModule;
import iguanaman.hungeroverhaul.module.tinkersconstruct.TinkersConstructModule;
import iguanaman.hungeroverhaul.module.tweak.TweaksModule;
import iguanaman.hungeroverhaul.module.vanilla.VanillaModule;
Expand Down Expand Up @@ -119,6 +120,7 @@ public void postInit(FMLPostInitializationEvent event)
//}

VanillaModule.postInit();
ReflectionModule.postInit();
TweaksModule.postInit();
VillageModule.postInit();
LootModule.postInit();
Expand Down
Expand Up @@ -18,6 +18,7 @@
import iguanaman.hungeroverhaul.module.growth.PlantGrowthModule;
import iguanaman.hungeroverhaul.module.growth.modification.PlantGrowthModification;
import iguanaman.hungeroverhaul.module.harvestcraft.helper.PamsModsHelper;
import iguanaman.hungeroverhaul.module.reflection.ReflectionModule;
import iguanaman.hungeroverhaul.module.seed.GrassSeedsModule;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBeetroot;
Expand Down Expand Up @@ -518,11 +519,12 @@ else if (clicked_block.getClass() == BlockBeetroot.class)
resultingState = real_state.withProperty(BlockBeetroot.BEETROOT_AGE, 0);
}
}
//TODO: REMOVE REFLECTION HELPER IN 1.13
else if (Loader.isModLoaded("harvestcraft") && clicked_block.getClass() == BlockPamCrop.class)
{
if (real_state.getValue(BlockPamCrop.AGE) >= 3)
if (ReflectionModule.pamCropAgeFound && real_state.getValue(ReflectionModule.pamCropAge) >= 3)
{
resultingState = real_state.withProperty(BlockPamCrop.AGE, 0);
resultingState = real_state.withProperty(ReflectionModule.pamCropAge, 0);
}
}
else if (Loader.isModLoaded("harvestcraft") && clicked_block.getClass() == BlockPamFruit.class)
Expand Down Expand Up @@ -573,6 +575,8 @@ else if (Loader.isModLoaded("harvestcraft") && clicked_block.getClass() == Block
@SubscribeEvent
public void onBlockHarvested(HarvestDropsEvent event)
{
//TODO: REMOVE REFLECTION HELPER IN 1.13

if (!Config.modifyCropDropsBreak)
{
return;
Expand Down Expand Up @@ -609,7 +613,7 @@ public void onBlockHarvested(HarvestDropsEvent event)
|| (isBeetrootCrop && state.getValue(BlockBeetroot.BEETROOT_AGE) >= 3)
|| (isCottonCrop && state.getValue(BlockNaturaCotton.AGE) == 4)
|| (isBarleyCrop && state.getValue(BlockNaturaBarley.AGE) == 3)
|| (isPamCrop && state.getValue(BlockPamCrop.AGE) == 3)
|| (ReflectionModule.pamCropAgeFound && (isPamCrop && state.getValue(ReflectionModule.pamCropAge) == 3))
|| (isPamFruit && state.getValue(BlockPamFruit.AGE) == 2)
|| (isPamFruitLog && state.getValue(BlockPamFruitLog.AGE) == 2);

Expand Down
Expand Up @@ -20,6 +20,7 @@
import iguanaman.hungeroverhaul.module.growth.PlantGrowthModule;
import iguanaman.hungeroverhaul.module.growth.modification.PlantGrowthModification;
import iguanaman.hungeroverhaul.module.harvestcraft.helper.PamsModsHelper;
import iguanaman.hungeroverhaul.module.reflection.ReflectionModule;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -833,23 +834,30 @@ else if (lowerSaturationCrops.contains(crop))
@Override
public IBlockState getNewState(World world, BlockPos pos, IBlockState currentState)
{
int currentMeta = currentState.getValue(BlockPamCrop.AGE);
int metaFullyGrown = 3;
int metaIncrease = 0;

if (currentMeta != metaFullyGrown)
//TODO REMOVE REFLECTION
if (ReflectionModule.pamCropAgeFound)
{
metaIncrease = 1;
int currentMeta = currentState.getValue(ReflectionModule.pamCropAge);
int metaFullyGrown = 3;
int metaIncrease = 0;

if (Config.difficultyScalingBoneMeal && world.getDifficulty().ordinal() < EnumDifficulty.NORMAL.ordinal())
if (currentMeta != metaFullyGrown)
{
int metaRandomIncreaseRange = currentMeta < 3 ? 2 : 3;
metaIncrease += random.nextInt(metaRandomIncreaseRange);
}
}
metaIncrease = 1;

return currentState.withProperty(BlockPamCrop.AGE, Math.min(currentMeta + metaIncrease, metaFullyGrown));
if (Config.difficultyScalingBoneMeal && world.getDifficulty().ordinal() < EnumDifficulty.NORMAL.ordinal())
{
int metaRandomIncreaseRange = currentMeta < 3 ? 2 : 3;
metaIncrease += random.nextInt(metaRandomIncreaseRange);
}
}

return currentState.withProperty(ReflectionModule.pamCropAge, Math.min(currentMeta + metaIncrease, metaFullyGrown));
}
else
{
return currentState;
}
}
};
BonemealModule.registerBonemealModifier(BlockPamCrop.class, cropBonemealModification);
Expand Down
@@ -0,0 +1,38 @@
package iguanaman.hungeroverhaul.module.reflection;

import java.lang.reflect.Field;

import com.pam.harvestcraft.blocks.growables.BlockPamCrop;

import net.minecraft.block.properties.PropertyInteger;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.ReflectionHelper;

//TODO: REMOVE REFLECTION HELPER IN 1.13
public class ReflectionModule
{
//@formatter:off
public static PropertyInteger pamCropAge = null;

public static boolean pamCropAgeFound = false;
//@formatter:on

public static void postInit()
{
if (Loader.isModLoaded("harvestcraft"))
{
Field pamCropAgeField = ReflectionHelper.findField(BlockPamCrop.class, "AGE");
pamCropAgeField.setAccessible(true);

try
{
pamCropAge = (PropertyInteger) pamCropAgeField.get(null);
pamCropAgeFound = pamCropAge != null;
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}

0 comments on commit e74b946

Please sign in to comment.