Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dungeon Tweaks Compat again #228

Merged
merged 7 commits into from Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -87,6 +87,9 @@ public class AS_BattleTowersCore
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
DungeonTweaksCompat.legacyCheck();
DungeonTweaksCompat.registerDungeons();

configuration = new Configuration(event.getSuggestedConfigurationFile(), false);
loadForgeConfig();

Expand Down
Expand Up @@ -154,7 +154,7 @@ else if (countFoliage == result)
}

@SuppressWarnings("deprecation") // is needed because getDefaultState on stairs does not work
public void generate(World world, int ix, int jy, int kz, int towerchoice, boolean underground)
public void generate(World world, Random random, int ix, int jy, int kz, int towerchoice, boolean underground)
{
TowerTypes towerChosen = TowerTypes.values()[towerchoice];

Expand Down Expand Up @@ -387,19 +387,7 @@ public void generate(World world, int ix, int jy, int kz, int towerchoice, boole
}
else
{
try
{
@SuppressWarnings("unchecked")
Constructor<? extends Event> constructor = (Constructor<? extends Event>) Class.forName("com.EvilNotch.dungeontweeks.main.Events.EventDungeon$Post")
.getConstructor(TileEntity.class, BlockPos.class, Random.class, ResourceLocation.class, World.class);
Event event = constructor.newInstance(tileentitymobspawner, tileentitymobspawner.getPos(), world.rand, new ResourceLocation("battletowers:" + towerChosen.getName()),
world);
MinecraftForge.EVENT_BUS.post(event);
}
catch (Throwable t)
{
t.printStackTrace();
}
DungeonTweaksCompat.fireDungeonSpawn(tileentitymobspawner, world, random, towerChosen);
}
}

Expand All @@ -413,19 +401,7 @@ public void generate(World world, int ix, int jy, int kz, int towerchoice, boole
}
else
{
try
{
@SuppressWarnings("unchecked")
Constructor<? extends Event> constructor = (Constructor<? extends Event>) Class.forName("com.EvilNotch.dungeontweeks.main.Events.EventDungeon$Post")
.getConstructor(TileEntity.class, BlockPos.class, Random.class, ResourceLocation.class, World.class);
Event event = constructor.newInstance(tileentitymobspawner, tileentitymobspawner.getPos(), world.rand, new ResourceLocation("battletowers:" + towerChosen.getName()),
world);
MinecraftForge.EVENT_BUS.post(event);
}
catch (Throwable t)
{
t.printStackTrace();
}
DungeonTweaksCompat.fireDungeonSpawn(tileentitymobspawner, world, random, towerChosen);
}
}
}
Expand Down Expand Up @@ -672,6 +648,11 @@ public String getName()
{
return this.typeName;
}

public ResourceLocation getId()
{
return new ResourceLocation("battletowers:" + this.typeName);
}
}

}
@@ -0,0 +1,104 @@
package atomicstryker.battletowers.common;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Random;

import com.evilnotch.dungeontweeks.main.world.worldgen.mobs.DungeonLocation;
import com.evilnotch.dungeontweeks.main.world.worldgen.mobs.DungeonMobs;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure the idea of compat proxies is to avoid having to IMPORT the addons?

Copy link
Author

@jredfox jredfox Sep 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I will remove the imports but, I don't use them. I converted them to reflection so you don't have to have my mod to compile even though it would be safe using it without the mod since loader is mod loaded


import atomicstryker.battletowers.common.AS_WorldGenTower.TowerTypes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* this is backwards and modern dungeon tweaks compatible
* @author jredfox
*
*/
public class DungeonTweaksCompat {

public static boolean isLegacy = false;

/**
* make backwards compatability when isLegacy becomes true
*/
public static void legacyCheck()
{
try
{
Class c = Class.forName("com.EvilNotch.dungeontweeks.main.Events.EventDungeon$Post");
isLegacy = true;
}
catch(Throwable t)
{

}
}
/**
* register all dungeon tweaks mobs to anydim towers
*/
public static void registerDungeons()
{
if(isLegacy) return;//I supported this mod in older versions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

Copy link
Author

@jredfox jredfox Sep 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I will download your formattor again I guess

try
{
Method addDungeonMob = Class.forName("com.evilnotch.dungeontweeks.main.world.worldgen.mobs.DungeonMobs").getMethod("addDungeonMob", ResourceLocation.class,ResourceLocation.class,int.class);
for(AS_WorldGenTower.TowerTypes tower : AS_WorldGenTower.TowerTypes.values())
{
boolean nether = tower == TowerTypes.Netherrack;
addDungeonMob.invoke(null, tower.getId(), new ResourceLocation("cave_spider"), 100);
addDungeonMob.invoke(null,tower.getId(), new ResourceLocation("spider"), 90);
addDungeonMob.invoke(null,tower.getId(), nether ? new ResourceLocation("wither_skeleton") : new ResourceLocation("skeleton"), 120);
addDungeonMob.invoke(null,tower.getId(), new ResourceLocation("zombie"), 120);

if(nether)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

addDungeonMob.invoke(null,tower.getId(), new ResourceLocation("blaze"), 20);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* fire the event based upon tower definitions
*/
public static void fireDungeonSpawn(TileEntityMobSpawner spawner, World world, Random random, TowerTypes towerChosen)
{
ResourceLocation towerId = towerChosen.getId();
if(isLegacy)
{
try
{
@SuppressWarnings("unchecked")
Constructor<? extends Event> constructor = (Constructor<? extends Event>) Class.forName("com.EvilNotch.dungeontweeks.main.Events.EventDungeon$Post")
.getConstructor(TileEntity.class, BlockPos.class, Random.class, ResourceLocation.class, World.class);
Event event = constructor.newInstance(spawner, spawner.getPos(), world.rand, towerId,
world);
MinecraftForge.EVENT_BUS.post(event);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
else
{
try
{
Method fireDungeonTweaks = Class.forName("com.evilnotch.dungeontweeks.main.world.worldgen.mobs.DungeonMobs").getMethod("fireDungeonTweaks",ResourceLocation.class,TileEntity.class,Random.class,World.class);
fireDungeonTweaks.invoke(null, towerId, spawner, random, world);
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}

}
Expand Up @@ -148,7 +148,7 @@ private boolean attemptToSpawnTower(World world, TowerPosition pos, Random rando
if (choice >= 0)
{
pos.underground = world.rand.nextInt(100) + 1 < AS_BattleTowersCore.instance.chanceTowerIsUnderGround;
generator.generate(world, x, y, z, choice, pos.underground);
generator.generate(world, random, x, y, z, choice, pos.underground);
return true;
}

Expand All @@ -158,7 +158,7 @@ private boolean attemptToSpawnTower(World world, TowerPosition pos, Random rando
public static void generateTower(World world, int x, int y, int z, int type, boolean underground)
{
disableGenerationHook++;
instance.generator.generate(world, x, y, z, type, underground);
instance.generator.generate(world, world.rand, x, y, z, type, underground);
obtainTowerPosListAccess();
towerPositions.add(instance.new TowerPosition(x, y, z, type, underground));
releaseTowerPosListAccess();
Expand Down Expand Up @@ -460,7 +460,7 @@ public static TowerPosition deleteNearestTower(World world, int x, int z)

if (chosen != null)
{
instance.generator.generate(world, chosen.x, chosen.y, chosen.z, AS_WorldGenTower.TowerTypes.Null.ordinal(), chosen.underground);
instance.generator.generate(world, world.rand, chosen.x, chosen.y, chosen.z, AS_WorldGenTower.TowerTypes.Null.ordinal(), chosen.underground);
obtainTowerPosListAccess();
towerPositions.remove(chosen);
releaseTowerPosListAccess();
Expand Down Expand Up @@ -490,7 +490,7 @@ public static void deleteAllTowers(World world, boolean regenerate)
obtainTowerPosListAccess();
for (TowerPosition tp : towerPositions)
{
instance.generator.generate(world, tp.x, tp.y, tp.z, regenerate ? tp.type : AS_WorldGenTower.TowerTypes.Null.ordinal(), tp.underground);
instance.generator.generate(world, world.rand, tp.x, tp.y, tp.z, regenerate ? tp.type : AS_WorldGenTower.TowerTypes.Null.ordinal(), tp.underground);
}

if (!regenerate)
Expand Down
7 changes: 7 additions & 0 deletions BattleTowers/src/main/resources/pack.mcmeta
@@ -0,0 +1,7 @@
{
"pack": {
"description": "examplemod resources",
"pack_format": 3,
"_comment": "A pack_format of 3 should be used starting with Minecraft 1.11. All resources, including language files, should be lowercase (eg: en_us.lang). A pack_format of 2 will load your mod resources with LegacyV2Adapter, which requires language files to have uppercase letters (eg: en_US.lang)."
}
}