Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ replaceGradleTokenInFile =
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
# Example value: (apiPackage = api) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.api
apiPackage =
apiPackage = api

# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# There can be multiple files in a space-separated list.
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/talonos/blightbuster/BlightBuster.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package talonos.blightbuster;

import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
Expand All @@ -14,6 +20,7 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import talonos.blightbuster.api.BlightbusterAPI;
import talonos.blightbuster.blocks.BBBlock;
import talonos.blightbuster.entities.EntitySilverPotion;
import talonos.blightbuster.handlers.PurityFocusEventHandler;
Expand All @@ -22,6 +29,12 @@
import talonos.blightbuster.rituals.RitualDawnMachine;
import talonos.blightbuster.tileentity.DawnMachineSpoutTileEntity;
import talonos.blightbuster.tileentity.dawnmachine.DawnMachineChunkLoader;
import thaumcraft.common.entities.monster.EntityTaintChicken;
import thaumcraft.common.entities.monster.EntityTaintCow;
import thaumcraft.common.entities.monster.EntityTaintCreeper;
import thaumcraft.common.entities.monster.EntityTaintPig;
import thaumcraft.common.entities.monster.EntityTaintSheep;
import thaumcraft.common.entities.monster.EntityTaintVillager;
import thaumicenergistics.api.ThEApi;

@Mod(
Expand Down Expand Up @@ -93,8 +106,18 @@ public void postInit(FMLPostInitializationEvent event) {
if (BlightbusterConfig.enableBlood) {
RitualDawnMachine.init();
}
BlightbusterConfig.init_mappings();
BlightbusterConfig.initConfigMaps();
registerMappings();

BlightBuster.proxy.reloadResearchOnLangChange();
}

private void registerMappings() {
BlightbusterAPI.registerEntityPurificationMapping(EntityTaintSheep.class, EntitySheep.class);
BlightbusterAPI.registerEntityPurificationMapping(EntityTaintCow.class, EntityCow.class);
BlightbusterAPI.registerEntityPurificationMapping(EntityTaintChicken.class, EntityChicken.class);
BlightbusterAPI.registerEntityPurificationMapping(EntityTaintPig.class, EntityPig.class);
BlightbusterAPI.registerEntityPurificationMapping(EntityTaintVillager.class, EntityVillager.class);
BlightbusterAPI.registerEntityPurificationMapping(EntityTaintCreeper.class, EntityCreeper.class);
}
}
52 changes: 9 additions & 43 deletions src/main/java/talonos/blightbuster/BlightbusterConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package talonos.blightbuster;

import java.lang.reflect.Constructor;
import java.util.HashMap;

import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.config.Configuration;

import talonos.blightbuster.api.BlightbusterAPI;
import talonos.blightbuster.compat.CompatFixes;
import talonos.blightbuster.items.ItemPurityFocus;
import thaumcraft.api.aspects.Aspect;
Expand All @@ -31,22 +26,10 @@ public class BlightbusterConfig {
public static boolean createThaumTab = false;

public static boolean customNpcSupport = false;
// public static String purifiedMappingsString =
// "thaumcraft.common.entities.monster.EntityTaintSheep:net.minecraft.entity.passive.EntitySheep,"
// + "thaumcraft.common.entities.monster.EntityTaintCow:net.minecraft.entity.passive.EntityCow,"
// + "thaumcraft.common.entities.monster.EntityTaintChicken:net.minecraft.entity.passive.EntityChicken,"
// + "thaumcraft.common.entities.monster.EntityTaintPig:net.minecraft.entity.passive.EntityPig,"
// + "thaumcraft.common.entities.monster.EntityTaintVillager:net.minecraft.entity.passive.EntityVillager,"
// + "thaumcraft.common.entities.monster.EntityTaintCreeper:net.minecraft.entity.monster.EntityCreeper";
public static String purifiedMappingsString = "Thaumcraft.TaintedSheep:Sheep," + "Thaumcraft.TaintedCow:Cow,"
+ "Thaumcraft.TaintedChicken:Chicken,"
+ "Thaumcraft.TaintedPig:Pig,"
+ "Thaumcraft.TaintedVillager:Villager,"
+ "Thaumcraft.TaintedCreeper:Creeper";
public static HashMap<Class<?>, Constructor<?>> purifiedMappings = new HashMap<>();

public static String purifiedMappingsString = "";
public static String customNpcMappingsString = "TaintedOcelot:Ozelot," + "TaintedWolf:Wolf,"
+ "TaintedTownsfolk:Villager";
public static HashMap<String, Constructor<?>> customNpcMappings = new HashMap<>();

public static boolean enableBlood = false;
public static boolean enableRf = false;
Expand Down Expand Up @@ -262,40 +245,23 @@ private static AspectList parseVisCost(String[] config) {
return cost;
}

@SuppressWarnings("unchecked")
public static Class<? extends EntityLivingBase> getEntityConstructorByStringId(String entityId) {
return (Class<? extends EntityLivingBase>) EntityList.stringToClassMapping.get(entityId);
}

public static void init_mappings() {
public static void initConfigMaps() {
if (customNpcSupport) {
for (String s : customNpcMappingsString.split(",")) {
String[] split = s.split(":");
if (split.length == 2) {
Class<? extends EntityLivingBase> clazz = getEntityConstructorByStringId(split[1]);
if (clazz != null) {
try {
customNpcMappings.put(split[0], clazz.getConstructor(World.class));
continue;
} catch (NoSuchMethodException e) {
BlightBuster.logger.error(e);

}
if (!BlightbusterAPI.registerCustomNpcPurificationMapping(split[0], split[1])) {
BlightBuster.logger
.error("Error registering CustomNPC purification mapping: {} to {}", split[0], split[1]);
}
BlightBuster.logger.error("Error finding entity: {}", split[1]);
}
}
}
for (String s : purifiedMappingsString.split(",")) {
String[] split = s.split(":");
if (split.length == 2) {
try {
Class<?> tainted = getEntityConstructorByStringId(split[0]);
Class<?> purified = getEntityConstructorByStringId(split[1]);
purifiedMappings.put(tainted, purified.getConstructor(World.class));
} catch (NoSuchMethodException e) {
BlightBuster.logger.error(e);
BlightBuster.logger.error("Error parsing class: {} or {}", split[0], split[1]);
if (!BlightbusterAPI.registerEntityPurificationMapping(split[0], split[1])) {
BlightBuster.logger.error("Error registering purification mapping: {} to {}", split[0], split[1]);
}
}
}
Expand Down
93 changes: 93 additions & 0 deletions src/main/java/talonos/blightbuster/api/BlightbusterAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package talonos.blightbuster.api;

import java.lang.reflect.Constructor;
import java.util.HashMap;

import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.world.World;

import talonos.blightbuster.BlightBuster;

public class BlightbusterAPI {

public static String purifiedMappingsString = "Thaumcraft.TaintedSheep:Sheep," + "Thaumcraft.TaintedCow:Cow,"
+ "Thaumcraft.TaintedChicken:Chicken,"
+ "Thaumcraft.TaintedPig:Pig,"
+ "Thaumcraft.TaintedVillager:Villager,"
+ "Thaumcraft.TaintedCreeper:Creeper";
private static HashMap<Class<?>, Constructor<?>> purifiedMappings = new HashMap<>();
public static String customNpcMappingsString = "TaintedOcelot:Ozelot," + "TaintedWolf:Wolf,"
+ "TaintedTownsfolk:Villager";
private static HashMap<String, Constructor<?>> customNpcMappings = new HashMap<>();

public static boolean registerEntityPurificationMapping(Class<?> taintedClass, Class<?> purifiedConstructor) {
return registerMapping(purifiedMappings, taintedClass, purifiedConstructor);
}

public static boolean registerCustomNpcPurificationMapping(String linkedName, Class<?> purifiedConstructor) {
return registerMapping(customNpcMappings, linkedName, purifiedConstructor);
}

public static boolean registerEntityPurificationMapping(String taintedEntity, String entityName) {
Class<? extends EntityLivingBase> tainted = getEntityConstructorByStringId(taintedEntity);
Class<? extends EntityLivingBase> purified = getEntityConstructorByStringId(entityName);
if (tainted == null || purified == null) {
return false;
}

return BlightbusterAPI.registerEntityPurificationMapping(tainted, purified);
}

public static boolean registerCustomNpcPurificationMapping(String linkedName, String entityName) {

Class<? extends EntityLivingBase> clazz = getEntityConstructorByStringId(entityName);
if (clazz != null) {
return BlightbusterAPI.registerCustomNpcPurificationMapping(linkedName, clazz);

}
return false;
}

public static Constructor<?> getPurifiedEntityConstructor(Class<?> taintedClass) {
return purifiedMappings.get(taintedClass);
}

public static Constructor<?> getCustomNpcPurifiedEntityConstructor(String linkedName) {
return customNpcMappings.get(linkedName);
}

public static boolean isMapped(Class<?> clazz) {
try {
return purifiedMappings.containsValue(clazz.getConstructor(World.class));
} catch (NoSuchMethodException e) {
BlightBuster.logger.error("Error checking mapped class {}", clazz);
return false;
}
}

@SuppressWarnings("unchecked")
private static Class<? extends EntityLivingBase> getEntityConstructorByStringId(String entityId) {
Class<? extends EntityLivingBase> clazz;
try {
clazz = (Class<? extends EntityLivingBase>) EntityList.stringToClassMapping.get(entityId);
} catch (Exception e) {
BlightBuster.logger.error("Could not find entity class for name {}", entityId);
return null;
}
return clazz;
}

private static <T> boolean registerMapping(HashMap<T, Constructor<?>> mapping, T key, Class<?> purified) {
if (mapping.containsKey(key)) {
return false;
}
try {
mapping.put(key, purified.getConstructor(World.class));
} catch (NoSuchMethodException e) {
BlightBuster.logger.error(e);
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingDropsEvent;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import talonos.blightbuster.BlightBuster;
import talonos.blightbuster.BlightbusterConfig;
import talonos.blightbuster.api.BlightbusterAPI;
import thaumcraft.api.potions.PotionVisExhaust;
import thaumcraft.api.wands.ItemFocusBasic;
import thaumcraft.common.config.Config;
Expand All @@ -26,14 +25,8 @@ public class PurityFocusEventHandler {
public void onEntityDrop(LivingDropsEvent event) {
if (event.entity instanceof EntityLivingBase entity) {
if (entity.isPotionActive(Config.potionTaintPoisonID)) {
try {
if (BlightbusterConfig.purifiedMappings.containsValue(
entity.getClass()
.getConstructor(World.class))) {
entity.capturedDrops.clear();
}
} catch (NoSuchMethodException e) {
BlightBuster.logger.error("Error capturing drops from class {}", entity.getClass());
if (BlightbusterAPI.isMapped(entity.getClass()) && !(entity instanceof EntityPlayer)) {
entity.capturedDrops.clear();
}
}
}
Expand Down
42 changes: 22 additions & 20 deletions src/main/java/talonos/blightbuster/lib/CleansingHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package talonos.blightbuster.lib;

import java.lang.reflect.Constructor;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
Expand All @@ -12,6 +14,7 @@
import noppes.npcs.entity.EntityCustomNpc;
import talonos.blightbuster.BlightBuster;
import talonos.blightbuster.BlightbusterConfig;
import talonos.blightbuster.api.BlightbusterAPI;
import talonos.blightbuster.network.BlightbusterNetwork;
import thaumcraft.common.blocks.BlockFluxGoo;
import thaumcraft.common.config.Config;
Expand All @@ -20,36 +23,35 @@
public class CleansingHelper {

public static boolean cleanseMobFromMapping(Entity entity, World world) {
boolean didSomething = false;
Class<?> clazz = entity.getClass();
if (BlightbusterConfig.purifiedMappings.containsKey(clazz)) {
try {
cleanseSingleMob(
entity,
(EntityLivingBase) BlightbusterConfig.purifiedMappings.get(clazz)
.newInstance(world));
return true;
} catch (final Exception e) {
BlightBuster.logger.error("Failed to cleanse entity from mapping: {}", clazz.getName(), e);
Constructor<?> constructor;
if (!BlightbusterConfig.customNpcSupport || !(entity instanceof EntityCustomNpc)) {
constructor = BlightbusterAPI.getPurifiedEntityConstructor(clazz);
if (constructor != null) {
try {
cleanseSingleMob(entity, (EntityLivingBase) constructor.newInstance(world));
didSomething = true;
} catch (final Exception e) {
BlightBuster.logger.error("Failed to cleanse entity from mapping: {}", clazz.getName(), e);
}
}
}
if (BlightbusterConfig.customNpcSupport && entity instanceof EntityCustomNpc npc) {
if (BlightbusterConfig.customNpcMappings.containsKey(npc.linkedName)) {
} else {
constructor = BlightbusterAPI.getCustomNpcPurifiedEntityConstructor(((EntityCustomNpc) entity).linkedName);
if (constructor != null) {
try {
cleanseSingleMob(
entity,
(EntityLivingBase) BlightbusterConfig.customNpcMappings.get(npc.linkedName)
.newInstance(world));
return true;
cleanseSingleMob(entity, (EntityLivingBase) constructor.newInstance(world));
didSomething = true;
} catch (final Exception e) {
BlightBuster.logger.error("Failed to cleanse entity from mapping: {}", npc.linkedName, e);
BlightBuster.logger.error("Failed to cleanse CustomNPC from mapping: {}", clazz.getName(), e);
}
}
}
if (entity instanceof EntityLivingBase e && e.isPotionActive(Config.potionTaintPoisonID)) {
e.removePotionEffect(Config.potionTaintPoisonID);
return true;
didSomething = true;
}
return false;
return didSomething;
}

private static void cleanseSingleMob(Entity tainted, EntityLivingBase cleansed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import noppes.npcs.entity.EntityCustomNpc;
import talonos.blightbuster.BlightBuster;
import talonos.blightbuster.BlightbusterConfig;
import talonos.blightbuster.api.BlightbusterAPI;
import talonos.blightbuster.lib.CleansingHelper;
import talonos.blightbuster.lib.Coordinates;
import talonos.blightbuster.network.BlightbusterNetwork;
Expand Down Expand Up @@ -355,10 +356,11 @@ protected boolean hasAnythingToCleanseHere(Chunk chunk) {
for (final List<Entity> list : chunk.entityLists) {
for (final Entity entity : list) {
if (entity instanceof EntityCustomNpc && BlightbusterConfig.customNpcSupport
&& BlightbusterConfig.customNpcMappings.containsKey(((EntityCustomNpc) entity).linkedName)) {
&& BlightbusterAPI.getCustomNpcPurifiedEntityConstructor(((EntityCustomNpc) entity).linkedName)
!= null) {
return true;
}
if (BlightbusterConfig.purifiedMappings.containsKey(entity.getClass())) {
if (BlightbusterAPI.getPurifiedEntityConstructor(entity.getClass()) != null) {
return true;
}
}
Expand Down