Add a way to hard blacklist Blocks from the Teleposer

The blocks in this list cannot be changed via config file. The two lists are kept (instead just one) so that the config one can be refreshed at any point with ConfigChangedEvent.
This commit is contained in:
Nick 2016-01-01 12:33:42 -08:00
parent ad68a89f15
commit e5a90c5e7f
2 changed files with 51 additions and 3 deletions

View file

@ -3,16 +3,23 @@ package WayofTime.bloodmagic.api;
import WayofTime.bloodmagic.api.util.helper.LogHelper; import WayofTime.bloodmagic.api.util.helper.LogHelper;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import java.util.ArrayList;
import java.util.List;
public class BloodMagicAPI public class BloodMagicAPI
{ {
public static final String ORB = "ItemBloodOrb"; public static final String ORB = "ItemBloodOrb";
public static final String SCRIBE = "ItemInscriptionTool"; public static final String SCRIBE = "ItemInscriptionTool";
@Getter
private static final List<BlockStack> teleposerBlacklist = new ArrayList<BlockStack>();
@Getter @Getter
@Setter @Setter
private static boolean loggingEnabled; private static boolean loggingEnabled;
@ -23,6 +30,10 @@ public class BloodMagicAPI
@Getter @Getter
private static DamageSource damageSource = new DamageSourceBloodMagic(); private static DamageSource damageSource = new DamageSourceBloodMagic();
@Getter
@Setter
private static Fluid lifeEssence;
/** /**
* Used to obtain Items from BloodMagic. Use the constants above for common * Used to obtain Items from BloodMagic. Use the constants above for common
* items in case internal names change. * items in case internal names change.
@ -37,7 +48,40 @@ public class BloodMagicAPI
return GameRegistry.findItem(Constants.Mod.MODID, name); return GameRegistry.findItem(Constants.Mod.MODID, name);
} }
@Getter /**
@Setter * Used to add a {@link BlockStack} to the Teleposer blacklist that
private static Fluid lifeEssence; * cannot be changed via Configuration files.
*
* @param blockStack
* - The BlockStack to blacklist.
*/
public static void addToTeleposerBlacklist(BlockStack blockStack)
{
if (!teleposerBlacklist.contains(blockStack))
teleposerBlacklist.add(blockStack);
}
/**
* @see #addToTeleposerBlacklist(BlockStack)
*
* @param block
* - The block to blacklist
* @param meta
* - The meta of the block to blacklist
*/
public static void addToTeleposerBlacklist(Block block, int meta)
{
addToTeleposerBlacklist(new BlockStack(block, meta));
}
/**
* @see #addToTeleposerBlacklist(BlockStack)
*
* @param block
* - The block to blacklist
*/
public static void addToTeleposerBlacklist(Block block)
{
addToTeleposerBlacklist(block, 0);
}
} }

View file

@ -2,6 +2,7 @@ package WayofTime.bloodmagic.util.handler;
import WayofTime.bloodmagic.ConfigHandler; import WayofTime.bloodmagic.ConfigHandler;
import WayofTime.bloodmagic.api.BlockStack; import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.event.TeleposeEvent; import WayofTime.bloodmagic.api.event.TeleposeEvent;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper; import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
@ -89,6 +90,9 @@ public class EventHandler
if (ConfigHandler.teleposerBlacklist.contains(initialBlock) || ConfigHandler.teleposerBlacklist.contains(finalBlock)) if (ConfigHandler.teleposerBlacklist.contains(initialBlock) || ConfigHandler.teleposerBlacklist.contains(finalBlock))
event.setCanceled(true); event.setCanceled(true);
if (BloodMagicAPI.getTeleposerBlacklist().contains(initialBlock) || BloodMagicAPI.getTeleposerBlacklist().contains(finalBlock))
event.setCanceled(true);
} }
@SubscribeEvent @SubscribeEvent