Drastically improve the Teleposer Blacklist
It now functions correctly. Only downside to this is that currently using the wildcard value of `*` does not work. Need to figure out how to cleanly do that.
This commit is contained in:
parent
4a86518366
commit
250debb604
|
@ -6,6 +6,10 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.BlockStack;
|
||||
import WayofTime.alchemicalWizardry.common.AlchemicalWizardryEventHooks;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
@ -18,6 +22,7 @@ import WayofTime.alchemicalWizardry.common.items.armour.BoundArmour;
|
|||
import WayofTime.alchemicalWizardry.common.summoning.meteor.MeteorParadigm;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
|
@ -178,6 +183,7 @@ public class BloodMagicConfiguration
|
|||
AlchemicalWizardry.potionDisableDeafness = config.get("Alchemy Potion Blacklist", "Deafness", false).getBoolean(false);
|
||||
|
||||
teleposerBlacklist = config.get("Teleposer Blacklist", "Blacklist", blacklist, "Stops specified blocks from being teleposed. Put entries on new lines. Valid syntax is: \nmodid:blockname:meta").getStringList();
|
||||
buildTeleposerBlacklist();
|
||||
|
||||
String tempDemonConfigs = "Demon Configs";
|
||||
TEDemonPortal.buildingGridDelay = config.get(tempDemonConfigs, "Building Grid Delay", 25).getInt();
|
||||
|
@ -296,4 +302,38 @@ public class BloodMagicConfiguration
|
|||
Rituals.ritualMap.remove(ritualID);
|
||||
Rituals.keyList.remove(ritualID);
|
||||
}
|
||||
|
||||
private static void buildTeleposerBlacklist() {
|
||||
for (String blockSet : BloodMagicConfiguration.teleposerBlacklist) {
|
||||
String[] blockData = blockSet.split(":");
|
||||
|
||||
Block block = GameRegistry.findBlock(blockData[0], blockData[1]);
|
||||
int meta = 0;
|
||||
|
||||
// If the block follows full syntax: modid:blockname:meta
|
||||
if (blockData.length == 3) {
|
||||
// Check if it's an int, if so, parse it. If not, set meta to 0 to avoid crashing.
|
||||
if (isInteger(blockData[2]))
|
||||
meta = Integer.parseInt(blockData[2]);
|
||||
else if (blockData[2].equals("*"))
|
||||
meta = OreDictionary.WILDCARD_VALUE;
|
||||
else
|
||||
meta = 0;
|
||||
}
|
||||
|
||||
AlchemicalWizardryEventHooks.teleposerBlacklist.add(new BlockStack(block, meta));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInteger(String s) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch(NumberFormatException e) {
|
||||
return false;
|
||||
} catch(NullPointerException e) {
|
||||
return false;
|
||||
}
|
||||
// only got here if we didn't return false
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package WayofTime.alchemicalWizardry.api;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
/**
|
||||
* A Block with a set metadata. Similar to an ItemStack.
|
||||
*/
|
||||
public class BlockStack {
|
||||
|
||||
private Block block;
|
||||
private int meta;
|
||||
|
||||
public BlockStack(Block block, int meta) {
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public BlockStack(Block block) {
|
||||
this(block, 0);
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public int getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return GameData.getBlockRegistry().getNameForObject(block) + ":" + meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
BlockStack blockStack = (BlockStack) obj;
|
||||
|
||||
return blockStack.block == this.getBlock() && blockStack.meta == this.getMeta();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import WayofTime.alchemicalWizardry.api.BlockStack;
|
||||
import WayofTime.alchemicalWizardry.common.achievements.ModAchievements;
|
||||
import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.demon.IHoardDemon;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -68,6 +69,7 @@ public class AlchemicalWizardryEventHooks
|
|||
|
||||
public static Map<Integer, List<CoordAndRange>> respawnMap = new HashMap();
|
||||
public static Map<Integer, List<CoordAndRange>> forceSpawnMap = new HashMap();
|
||||
public static ArrayList<BlockStack> teleposerBlacklist = new ArrayList<BlockStack>();
|
||||
|
||||
public static Random rand = new Random();
|
||||
|
||||
|
@ -771,41 +773,62 @@ public class AlchemicalWizardryEventHooks
|
|||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onTelepose(TeleposeEvent event) {
|
||||
for (int i = 0; i < BloodMagicConfiguration.teleposerBlacklist.length; i++) {
|
||||
String[] blockData = BloodMagicConfiguration.teleposerBlacklist[i].split(":");
|
||||
// @SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
// public void onTelepose(TeleposeEvent event) {
|
||||
//
|
||||
// AlchemicalWizardry.logger.info(event.initialBlock + ":" + event.initialMetadata);
|
||||
// AlchemicalWizardry.logger.info(event.finalBlock + ":" + event.finalMetadata);
|
||||
//
|
||||
// for (int i = 0; i < BloodMagicConfiguration.teleposerBlacklist.length; i++) {
|
||||
// String[] blockData = BloodMagicConfiguration.teleposerBlacklist[i].split(":");
|
||||
//
|
||||
// // If the block follows full syntax: modid:blockname:meta
|
||||
// if (blockData.length == 3) {
|
||||
//
|
||||
// Block block = GameRegistry.findBlock(blockData[0], blockData[1]);
|
||||
// int meta;
|
||||
//
|
||||
// // Check if it's an int, if so, parse it. If not, set meta to 0 to avoid crashing.
|
||||
// if (isInteger(blockData[2]))
|
||||
// meta = Integer.parseInt(blockData[2]);
|
||||
// else if (blockData[2].equals("*"))
|
||||
// meta = OreDictionary.WILDCARD_VALUE;
|
||||
// else
|
||||
// meta = 0;
|
||||
//
|
||||
// AlchemicalWizardry.logger.info(block + ":" + meta);
|
||||
//
|
||||
// if (block != null) {
|
||||
// if ((block == event.initialBlock || block == event.finalBlock) && (meta == event.initialMetadata || meta == event.finalMetadata || meta == OreDictionary.WILDCARD_VALUE)) {
|
||||
// event.setCanceled(true);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // If the block uses shorthand syntax: modid:blockname
|
||||
// } else if (blockData.length == 2) {
|
||||
//
|
||||
// Block block = GameRegistry.findBlock(blockData[0], blockData[1]);
|
||||
// int meta = 0;
|
||||
//
|
||||
// if (block != null) {
|
||||
// if ((block == event.initialBlock && (meta == event.initialMetadata || meta == OreDictionary.WILDCARD_VALUE)) || (block == event.finalBlock && (meta == event.finalMetadata || meta == OreDictionary.WILDCARD_VALUE))) {
|
||||
// event.setCanceled(true);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// If the block follows full syntax: modid:blockname:meta
|
||||
if (blockData.length == 3) {
|
||||
@SubscribeEvent
|
||||
public void onTelepose(TeleposeEvent event) {
|
||||
BlockStack initialBlock = new BlockStack(event.initialBlock, event.initialMetadata);
|
||||
BlockStack finalBlock = new BlockStack(event.finalBlock, event.finalMetadata);
|
||||
|
||||
Block block = GameRegistry.findBlock(blockData[0], blockData[1]);
|
||||
int meta;
|
||||
|
||||
// Check if it's an int, if so, parse it. If not, set meta to 0 to avoid crashing.
|
||||
if (blockData[2].matches("-?\\d+"))
|
||||
meta = Integer.parseInt(blockData[2]);
|
||||
else if (blockData[2].equals("*"))
|
||||
meta = OreDictionary.WILDCARD_VALUE;
|
||||
else
|
||||
meta = 0;
|
||||
|
||||
if (block != null)
|
||||
if (( block == event.initialBlock || block == event.finalBlock) && (meta == event.initialMetadata || meta == event.finalMetadata || meta == OreDictionary.WILDCARD_VALUE))
|
||||
event.setCanceled(true);
|
||||
|
||||
// If the block uses shorthand syntax: modid:blockname
|
||||
} else if (blockData.length == 2) {
|
||||
|
||||
Block block = GameRegistry.findBlock(blockData[0], blockData[1]);
|
||||
int meta = 0;
|
||||
|
||||
if (block != null)
|
||||
if (( block == event.initialBlock || block == event.finalBlock) && (meta == event.initialMetadata || meta == event.finalMetadata || meta == OreDictionary.WILDCARD_VALUE))
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (teleposerBlacklist.contains(initialBlock) || teleposerBlacklist.contains(finalBlock))
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEntityDeath(LivingDeathEvent event)
|
||||
|
|
Loading…
Reference in a new issue