Refactored dictionary in a separate class

This commit is contained in:
LemADEC 2015-12-26 21:11:34 +01:00
parent 6c7f56bef7
commit 24fe6b2315
9 changed files with 548 additions and 409 deletions

View file

@ -36,6 +36,7 @@ import net.minecraftforge.common.util.Constants;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.warpdrive.block.movement.TileEntityShipCore;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.JumpBlock;
import cr0s.warpdrive.data.MovingEntity;
@ -582,7 +583,7 @@ public class EntityJump extends Entity {
Block block = worldObj.getBlock(x, y, z);
// Skipping vanilla air & ignored blocks
if (block == Blocks.air || WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block)) {
if (block == Blocks.air || Dictionary.BLOCKS_LEFTBEHIND.contains(block)) {
continue;
}
@ -593,7 +594,7 @@ public class EntityJump extends Entity {
}
// Stop on non-movable blocks
if (WarpDriveConfig.BLOCKS_ANCHOR.contains(block)) {
if (Dictionary.BLOCKS_ANCHOR.contains(block)) {
reason.append(block.getUnlocalizedName() + " detected onboard at " + x + ", " + y + ", " + z + ". Aborting.");
LocalProfiler.stop();
return -1;
@ -619,12 +620,12 @@ public class EntityJump extends Entity {
Block block = worldObj.getBlock(x, y, z);
// Skipping any air block & ignored blocks
if (worldObj.isAirBlock(x, y, z) || WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block)) {
if (worldObj.isAirBlock(x, y, z) || Dictionary.BLOCKS_LEFTBEHIND.contains(block)) {
continue;
}
// Skipping non-movable blocks
if (WarpDriveConfig.BLOCKS_ANCHOR.contains(block)) {
if (Dictionary.BLOCKS_ANCHOR.contains(block)) {
continue;
}
@ -676,7 +677,7 @@ public class EntityJump extends Entity {
Block block = worldObj.getBlock(x, y, z);
// Skipping vanilla air & ignored blocks
if (block == Blocks.air || WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block)) {
if (block == Blocks.air || Dictionary.BLOCKS_LEFTBEHIND.contains(block)) {
continue;
}
@ -693,7 +694,7 @@ public class EntityJump extends Entity {
}
// default priority is 2 for block, 3 for tile entities
Integer placeTime = WarpDriveConfig.BLOCKS_PLACE.get(block);
Integer placeTime = Dictionary.BLOCKS_PLACE.get(block);
if (placeTime == null) {
if (tileEntity == null) {
placeTime = 2;
@ -1092,12 +1093,12 @@ public class EntityJump extends Entity {
}
String id = EntityList.getEntityString(entity);
if (WarpDriveConfig.ENTITIES_ANCHOR.contains(id)) {
if (Dictionary.ENTITIES_ANCHOR.contains(id)) {
result = "Anchor entity " + id + " detected at " + Math.floor(entity.posX) + ", " + Math.floor(entity.posY) + ", " + Math.floor(entity.posZ) + ", aborting jump...";
// we need to continue so players are added so they can see the message...
continue;
}
if (WarpDriveConfig.ENTITIES_LEFTBEHIND.contains(id)) {
if (Dictionary.ENTITIES_LEFTBEHIND.contains(id)) {
if (WarpDriveConfig.LOGGING_JUMPBLOCKS) {
WarpDrive.logger.info("Leaving entity " + id + " behind: " + entity);
}
@ -1287,7 +1288,7 @@ public class EntityJump extends Entity {
blockSource = worldObj.getBlock(x, y, z);
blockTarget = worldObj.getBlock(newX, newY, newZ);
if (WarpDriveConfig.BLOCKS_ANCHOR.contains(blockTarget)) {
if (Dictionary.BLOCKS_ANCHOR.contains(blockTarget)) {
result.add(x, y, z,
newX + 0.5D - movementVector[0] * 1.0D,
newY + 0.5D - movementVector[1] * 1.0D,
@ -1299,9 +1300,9 @@ public class EntityJump extends Entity {
}
if ( blockSource != Blocks.air
&& !WarpDriveConfig.BLOCKS_EXPANDABLE.contains(blockSource)
&& !Dictionary.BLOCKS_EXPANDABLE.contains(blockSource)
&& blockTarget != Blocks.air
&& !WarpDriveConfig.BLOCKS_EXPANDABLE.contains(blockTarget)) {
&& !Dictionary.BLOCKS_EXPANDABLE.contains(blockTarget)) {
result.add(x, y, z,
newX + 0.5D + movementVector[0] * 0.1D,
newY + 0.5D + movementVector[1] * 0.1D,

View file

@ -1,5 +1,6 @@
package cr0s.warpdrive;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
@ -45,7 +46,7 @@ public class GravityManager {
for (int i = 0; i < 4; i++) {
ItemStack armor = player.getCurrentArmor(i);
if (armor != null) {
if (WarpDriveConfig.ITEMS_FLYINSPACE.contains(armor.getItem())) {
if (Dictionary.ITEMS_FLYINSPACE.contains(armor.getItem())) {
return SPACE_VOID_GRAVITY_JETPACKSNEAK;
}
}

View file

@ -23,6 +23,7 @@ import cpw.mods.fml.common.Optional;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.block.TileEntityAbstractEnergy;
import cr0s.warpdrive.block.movement.TileEntityShipCore;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.JumpBlock;
import cr0s.warpdrive.data.Vector3;
@ -167,9 +168,9 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
// Deploy single block
JumpBlock jb = blocksToDeploy[currentDeployIndex];
if (jb != null && !WarpDriveConfig.BLOCKS_ANCHOR.contains(jb.block)) {
if (jb != null && !Dictionary.BLOCKS_ANCHOR.contains(jb.block)) {
Block blockAtTarget = worldObj.getBlock(targetX + jb.x, targetY + jb.y, targetZ + jb.z);
if (blockAtTarget == Blocks.air || WarpDriveConfig.BLOCKS_EXPANDABLE.contains(blockAtTarget)) {
if (blockAtTarget == Blocks.air || Dictionary.BLOCKS_EXPANDABLE.contains(blockAtTarget)) {
jb.deploy(worldObj, targetX, targetY, targetZ);
if (worldObj.rand.nextInt(100) <= 10) {
@ -270,7 +271,7 @@ public class TileEntityShipScanner extends TileEntityAbstractEnergy {
Block block = worldObj.getBlock(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z);
// Skip leftBehind and anchor blocks
if (WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block) || WarpDriveConfig.BLOCKS_ANCHOR.contains(block)) {
if (Dictionary.BLOCKS_LEFTBEHIND.contains(block) || Dictionary.BLOCKS_ANCHOR.contains(block)) {
block = Blocks.air;
}

View file

@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
@ -398,15 +399,15 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
}
private static boolean isSoil(Block block) {
return WarpDriveConfig.BLOCKS_SOILS.contains(block);
return Dictionary.BLOCKS_SOILS.contains(block);
}
private static boolean isLog(Block block) {
return WarpDriveConfig.BLOCKS_LOGS.contains(block);
return Dictionary.BLOCKS_LOGS.contains(block);
}
private static boolean isLeaf(Block block) {
return WarpDriveConfig.BLOCKS_LEAVES.contains(block);
return Dictionary.BLOCKS_LEAVES.contains(block);
}
private LinkedList<VectorI> scanSoils() {
@ -470,7 +471,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
}
}
if (logPositions.size() > 0) {
HashSet<Block> whitelist = (HashSet<Block>) WarpDriveConfig.BLOCKS_LOGS.clone();
HashSet<Block> whitelist = (HashSet<Block>) Dictionary.BLOCKS_LOGS.clone();
if (breakLeaves) {
// whitelist.addAll(WarpDriveConfig.BLOCKS_LEAVES);
}

View file

@ -14,6 +14,7 @@ import net.minecraftforge.fluids.FluidRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.data.VectorI;
@ -224,12 +225,12 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
return false;
}
// check blacklist
if (WarpDriveConfig.BLOCKS_NOMINING.contains(block)) {
if (Dictionary.BLOCKS_NOMINING.contains(block)) {
stop();
return false;
}
// check whitelist
if (WarpDriveConfig.BLOCKS_MINING.contains(block) || WarpDriveConfig.BLOCKS_ORES.contains(block)) {
if (Dictionary.BLOCKS_MINING.contains(block) || Dictionary.BLOCKS_ORES.contains(block)) {
return true;
}
// check default (explosion resistance is used to test for force fields and reinforced blocks, basically preventing mining a base or ship)
@ -256,7 +257,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
z = zCoord;
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
if (mineAllBlocks || Dictionary.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
@ -270,7 +271,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
for (; x <= xmax; x++) {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
if (mineAllBlocks || Dictionary.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
@ -280,7 +281,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
for (; z <= zmax; z++) {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
if (mineAllBlocks || Dictionary.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
@ -290,7 +291,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
for (; x >= xmin; x--) {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
if (mineAllBlocks || Dictionary.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
@ -300,7 +301,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
for (; z > zmin; z--) {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
if (mineAllBlocks || Dictionary.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}
@ -310,7 +311,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
for (; x < xCoord; x++) {
block = worldObj.getBlock(x, currentLayer, z);
if (canDig(block, x, currentLayer, z)) {
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
if (mineAllBlocks || Dictionary.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
valuablesInLayer.add(new VectorI(x, currentLayer, z));
}
}

View file

@ -25,6 +25,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
import cr0s.warpdrive.EntityJump;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.block.TileEntityAbstractEnergy;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.Jumpgate;
import cr0s.warpdrive.data.StarMapEntry;
@ -635,10 +636,10 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
Block block = worldObj.getBlock(x, y, z);
// Skipping vanilla air & ignored blocks
if (block == Blocks.air || WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block)) {
if (block == Blocks.air || Dictionary.BLOCKS_LEFTBEHIND.contains(block)) {
continue;
}
if (WarpDriveConfig.BLOCKS_NOMASS.contains(block)) {
if (Dictionary.BLOCKS_NOMASS.contains(block)) {
continue;
}
@ -696,9 +697,9 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
// not vanilla air nor ignored blocks at source
// not vanilla air nor expandable blocks are target location
if ( blockSource != Blocks.air
&& !WarpDriveConfig.BLOCKS_EXPANDABLE.contains(blockSource)
&& !Dictionary.BLOCKS_EXPANDABLE.contains(blockSource)
&& blockTarget != Blocks.air
&& !WarpDriveConfig.BLOCKS_EXPANDABLE.contains(blockTarget)) {
&& !Dictionary.BLOCKS_EXPANDABLE.contains(blockTarget)) {
return false;
}
}
@ -1030,12 +1031,12 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
Block block = worldObj.getBlock(x, y, z);
// Skipping vanilla air & ignored blocks
if (block == Blocks.air || WarpDriveConfig.BLOCKS_LEFTBEHIND.contains(block)) {
if (block == Blocks.air || Dictionary.BLOCKS_LEFTBEHIND.contains(block)) {
continue;
}
newVolume++;
if (WarpDriveConfig.BLOCKS_NOMASS.contains(block)) {
if (Dictionary.BLOCKS_NOMASS.contains(block)) {
continue;
}
newMass++;

View file

@ -0,0 +1,495 @@
package cr0s.warpdrive.config;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameRegistry;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.block.hull.BlockHullGlass;
import cr0s.warpdrive.block.hull.BlockHullPlain;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.oredict.OreDictionary;
public class Dictionary {
private static boolean forceResistance = false;
// Tagged blocks and entities (loaded from configuration file at PreInit, parsed at PostInit)
private static HashMap<String, String> taggedBlocks = null;
private static HashMap<String, String> taggedEntities = null;
private static HashMap<String, String> taggedItems = null;
// Blocks dictionary
public static HashSet<Block> BLOCKS_ORES = null;
public static HashSet<Block> BLOCKS_SOILS = null;
public static HashSet<Block> BLOCKS_LOGS = null;
public static HashSet<Block> BLOCKS_LEAVES = null;
public static HashSet<Block> BLOCKS_ANCHOR = null;
public static HashSet<Block> BLOCKS_NOMASS = null;
public static HashSet<Block> BLOCKS_LEFTBEHIND = null;
public static HashSet<Block> BLOCKS_EXPANDABLE = null;
public static HashSet<Block> BLOCKS_MINING = null;
public static HashSet<Block> BLOCKS_NOMINING = null;
public static HashMap<Block, Integer> BLOCKS_PLACE = null;
// Entities dictionary
public static HashSet<String> ENTITIES_ANCHOR = null;
public static HashSet<String> ENTITIES_NOMASS = null;
public static HashSet<String> ENTITIES_LEFTBEHIND = null;
public static HashSet<String> ENTITIES_NONLIVINGTARGET = null;
// Items dictionary
public static HashSet<Item> ITEMS_FLYINSPACE = null;
public static HashSet<Item> ITEMS_NOFALLDAMAGE = null;
public static HashSet<Item> ITEMS_BREATHINGIC2 = null;
public static void loadConfig(Configuration config) {
// Block dictionary
{
config.addCustomCategoryComment("block_tags",
"Use this section to enable special behavior on blocks using tags.\n"
+ "Most blocks are already supported automatically. Only modify this section when something doesn't work!\n" + "\n"
+ "Tags shall be separated by at least one space, comma or tabulation.\n"
+ "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n"
+ "In case of conflicts, the latest tag overwrite the previous ones.\n"
+ "- Soil: this block is a soil for plants (default: dirt, farmland, grass, sand & soul sand).\n"
+ "- Log: this block is harvestable as a wood log (default: all 'log*', '*log' & '*logs' blocks from the ore dictionnary).\n"
+ "- Leaf: this block is harvestable as a leaf (default: all 'leave*', '*leave' & '*leaves' blocks from the ore dictionnary).\n"
+ "- Anchor: ship can't move with this block aboard (default: bedrock and assimilated).\n"
+ "- NoMass: this block doesn't count when calculating ship volume/mass (default: leaves, all 'air' blocks).\n"
+ "- LeftBehind: this block won't move with your ship (default: RailCraft heat, WarpDrive gases).\n"
+ "- Expandable: this block will be squished/ignored in case of collision.\n"
+ "- Mining: this block is mineable (default: all 'ore' blocks from the ore dictionnary).\n"
+ "- NoMining: this block is non-mineable (default: forcefields).\n"
+ "- PlaceEarliest: this block will be removed last and placed first (default: ship hull and projectors).\n"
+ "- PlaceEarlier: this block will be placed fairly soon (default: forcefield blocks).\n"
+ "- PlaceNormal: this block will be removed and placed with non-tile entities.\n"
+ "- PlaceLater: this block will be placed fairly late (default: IC2 Reactor core).\n"
+ "- PlaceLatest: this block will be removed first and placed last (default: IC2 Reactor chamber).");
ConfigCategory categoryBlockTags = config.getCategory("block_tags");
String[] taggedBlocksName = categoryBlockTags.getValues().keySet().toArray(new String[0]);
if (taggedBlocksName.length == 0) {
// farming
config.get("block_tags", "minecraft:dirt" , "Soil").getString();
config.get("block_tags", "minecraft:farmland" , "Soil").getString();
config.get("block_tags", "minecraft:grass" , "Soil").getString();
config.get("block_tags", "minecraft:sand" , "Soil").getString();
config.get("block_tags", "minecraft:soul_sand" , "Soil").getString();
config.get("block_tags", "IC2:blockRubWood" , "Log").getString();
// anchors
config.get("block_tags", "minecraft:bedrock" , "Anchor NoMining").getString();
config.get("block_tags", "IC2:blockPersonal" , "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:invisible_bedrock" , "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:invisible_bedrock" , "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:anti_anti_builder_stone", "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:anti_builder" , "Anchor NoMining").getString();
// placement priorities
config.get("block_tags", "IC2:blockReinforcedFoam" , "PlaceEarliest NoMining").getString();
config.get("block_tags", "IC2:blockAlloy" , "PlaceEarliest NoMining").getString();
config.get("block_tags", "IC2:blockAlloyGlass" , "PlaceEarliest NoMining").getString();
config.get("block_tags", "minecraft:obsidian" , "PlaceEarliest Mining").getString();
config.get("block_tags", "AdvancedRepulsionSystems:field" , "PlaceEarlier NoMining").getString();
// FIXME config.get("block_tags", "MFFS:field" , "PlaceEarlier NoMining" ).getString();
config.get("block_tags", "IC2:blockGenerator" , "PlaceLater").getString();
config.get("block_tags", "IC2:blockReactorChamber" , "PlaceLatest").getString();
// expandables, a.k.a. "don't blow my ship with this..."
config.get("block_tags", "WarpDrive:blockGas" , "LeftBehind Expandable").getString();
config.get("block_tags", "Railcraft:residual.heat" , "LeftBehind Expandable").getString();
config.get("block_tags", "InvisibLights:blockLightSource" , "NoMass Expandable").getString();
config.get("block_tags", "WarpDrive:blockAir" , "NoMass Expandable PlaceLatest").getString();
// mining a mineshaft...
config.get("block_tags", "minecraft:web" , "Mining").getString();
config.get("block_tags", "minecraft:fence" , "Mining").getString();
config.get("block_tags", "minecraft:torch" , "Mining").getString();
config.get("block_tags", "minecraft:glowstone" , "Mining").getString();
config.get("block_tags", "minecraft:redstone_block" , "Mining").getString();
// mining an 'end' moon
config.get("block_tags", "WarpDrive:blockIridium" , "Mining").getString(); // stronger than obsidian but can still be mined (see ender moon)
taggedBlocksName = categoryBlockTags.getValues().keySet().toArray(new String[0]);
}
taggedBlocks = new HashMap(taggedBlocksName.length);
for (String name : taggedBlocksName) {
String tags = config.get("block_tags", name, "").getString();
taggedBlocks.put(name, tags);
}
}
// Entity dictionary
{
config.addCustomCategoryComment("entity_tags",
"Use this section to enable special behavior on entities using tags.\n"
+ "Most entities are already supported automatically. Only modify this section when something doesn't work!\n" + "\n"
+ "Tags shall be separated by at least one space, comma or tabulation.\n" + "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n"
+ "In case of conflicts, the latest tag overwrite the previous ones.\n" + "- Anchor: ship can't move with this entity aboard (default: none).\n"
+ "- NoMass: this entity doesn't count when calculating ship volume/mass (default: Galacticraft air bubble).\n"
+ "- LeftBehind: this entity won't move with your ship (default: Galacticraft air bubble).\n"
+ "- NonLivingTarget: this non-living entity can be targeted/removed by weapons (default: ItemFrame, Painting).");
ConfigCategory categoryEntityTags = config.getCategory("entity_tags");
String[] taggedEntitiesName = categoryEntityTags.getValues().keySet().toArray(new String[0]);
if (taggedEntitiesName.length == 0) {
config.get("entity_tags", "GalacticraftCore.OxygenBubble", "NoMass LeftBehind").getString();
config.get("entity_tags", "ItemFrame" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "Painting" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "LeashKnot" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "Boat" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartRideable" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartChest" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartFurnace" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartTNT" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartHopper" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartSpawner" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "EnderCrystal" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.BoatCarbon" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.BoatRubber" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.BoatElectric" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.Nuke" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.Itnt" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.StickyDynamite" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.Dynamite" , "NoMass NonLivingTarget").getString();
taggedEntitiesName = categoryEntityTags.getValues().keySet().toArray(new String[0]);
}
taggedEntities = new HashMap(taggedEntitiesName.length);
for (String name : taggedEntitiesName) {
String tags = config.get("entity_tags", name, "").getString();
taggedEntities.put(name, tags);
}
}
// Item dictionary
{
config.addCustomCategoryComment("item_tags", "Use this section to enable special behavior on items using tags.\n"
+ "Most items are already supported automatically. Only modify this section when something doesn't work!\n" + "\n"
+ "Tags shall be separated by at least one space, comma or tabulation.\n" + "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n"
+ "In case of conflicts, the latest tag overwrite the previous ones.\n" + "- FlyInSpace: player can move without gravity effect while wearing this item (default: jetpacks).\n"
+ "- NoFallDamage: player doesn't take fall damage while wearing this armor item (default: IC2 rubber boots).\n"
+ "- BreathingIC2: player can breath IC2 compressed air while wearing this armor item (default: IC2 nano helmet and Cie).\n");
ConfigCategory categoryItemTags = config.getCategory("item_tags");
String[] taggedItemsName = categoryItemTags.getValues().keySet().toArray(new String[0]);
if (taggedItemsName.length == 0) {
config.get("item_tags", "IC2:itemArmorHazmatHelmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemSolarHelmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemArmorNanoHelmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemArmorQuantumHelmet", "BreathingIC2").getString();
config.get("item_tags", "AdvancedSolarPanel:advanced_solar_helmet", "BreathingIC2").getString();
config.get("item_tags", "AdvancedSolarPanel:hybrid_solar_helmet", "BreathingIC2").getString();
config.get("item_tags", "AdvancedSolarPanel:ultimate_solar_helmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemArmorJetpack", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "IC2:itemArmorJetpackElectric", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "GraviSuite:advJetpack", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "GraviSuite:advNanoChestPlate", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "GraviSuite:graviChestPlate", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "IC2:itemArmorRubBoots", "NoFallDamage").getString();
config.get("item_tags", "IC2:itemArmorQuantumBoots", "NoFallDamage").getString();
taggedItemsName = categoryItemTags.getValues().keySet().toArray(new String[0]);
}
taggedItems = new HashMap(taggedItemsName.length);
for (String name : taggedItemsName) {
String tags = config.get("item_tags", name, "").getString();
taggedItems.put(name, tags);
}
}
}
public static void apply() {
// get default settings from parsing ore dictionary
BLOCKS_ORES = new HashSet<Block>();
BLOCKS_LOGS = new HashSet<Block>();
BLOCKS_LEAVES = new HashSet<Block>();
String[] oreNames = OreDictionary.getOreNames();
for (String oreName : oreNames) {
String lowerOreName = oreName.toLowerCase();
if (oreName.length() > 4 && oreName.substring(0, 3).equals("ore")) {
ArrayList<ItemStack> itemStacks = OreDictionary.getOres(oreName);
for (ItemStack itemStack : itemStacks) {
BLOCKS_ORES.add(Block.getBlockFromItem(itemStack.getItem()));
// WarpDrive.logger.info("- added " + oreName + " to ores as " + itemStack);
}
}
if (lowerOreName.startsWith("log") || lowerOreName.endsWith("log") || lowerOreName.endsWith("logs")) {
ArrayList<ItemStack> itemStacks = OreDictionary.getOres(oreName);
for (ItemStack itemStack : itemStacks) {
BLOCKS_LOGS.add(Block.getBlockFromItem(itemStack.getItem()));
// WarpDrive.logger.info("- added " + oreName + " to logs as " + itemStack);
}
}
if (lowerOreName.startsWith("leave") || lowerOreName.endsWith("leave") || lowerOreName.endsWith("leaves")) {
ArrayList<ItemStack> itemStacks = OreDictionary.getOres(oreName);
for (ItemStack itemStack : itemStacks) {
BLOCKS_LEAVES.add(Block.getBlockFromItem(itemStack.getItem()));
// WarpDrive.logger.info("- added " + oreName + " to leaves as " + itemStack);
}
}
}
// translate tagged blocks
BLOCKS_SOILS = new HashSet(taggedBlocks.size());
BLOCKS_ANCHOR = new HashSet(taggedBlocks.size());
BLOCKS_NOMASS = new HashSet(taggedBlocks.size() + BLOCKS_LEAVES.size());
BLOCKS_NOMASS.addAll(BLOCKS_LEAVES);
BLOCKS_LEFTBEHIND = new HashSet(taggedBlocks.size());
BLOCKS_EXPANDABLE = new HashSet(taggedBlocks.size() + BLOCKS_LEAVES.size());
BLOCKS_EXPANDABLE.addAll(BLOCKS_LEAVES);
BLOCKS_MINING = new HashSet(taggedBlocks.size());
BLOCKS_NOMINING = new HashSet(taggedBlocks.size());
BLOCKS_PLACE = new HashMap(taggedBlocks.size());
for (Entry<String, String> taggedBlock : taggedBlocks.entrySet()) {
Block block = Block.getBlockFromName(taggedBlock.getKey());
if (block == null) {
WarpDrive.logger.info("Ignoring missing block " + taggedBlock.getKey());
continue;
}
for (String tag : taggedBlock.getValue().replace("\t", " ").replace(",", " ").replace(" ", " ").split(" ")) {
switch (tag) {
case "Soil" : BLOCKS_SOILS.add(block); break;
case "Log" : BLOCKS_LOGS.add(block); break;
case "Leaf" : BLOCKS_LEAVES.add(block); break;
case "Anchor" : BLOCKS_ANCHOR.add(block); break;
case "NoMass" : BLOCKS_NOMASS.add(block); break;
case "LeftBehind" : BLOCKS_LEFTBEHIND.add(block); break;
case "Expandable" : BLOCKS_EXPANDABLE.add(block); break;
case "Mining" : BLOCKS_MINING.add(block); break;
case "NoMining" : BLOCKS_NOMINING.add(block); break;
case "PlaceEarliest": BLOCKS_PLACE.put(block, 0); break;
case "PlaceEarlier" : BLOCKS_PLACE.put(block, 1); break;
case "PlaceNormal" : BLOCKS_PLACE.put(block, 2); break;
case "PlaceLater" : BLOCKS_PLACE.put(block, 3); break;
case "PlaceLatest" : BLOCKS_PLACE.put(block, 4); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for block " + block);
break;
}
}
}
// translate tagged entities
ENTITIES_ANCHOR = new HashSet(taggedEntities.size());
ENTITIES_NOMASS = new HashSet(taggedEntities.size());
ENTITIES_LEFTBEHIND = new HashSet(taggedEntities.size());
ENTITIES_NONLIVINGTARGET = new HashSet(taggedEntities.size());
for (Entry<String, String> taggedEntity : taggedEntities.entrySet()) {
String entityId = taggedEntity.getKey();
/* we can't detect missing entities, since some of them are 'hacked' in
if (!EntityList.stringToIDMapping.containsKey(entityId)) {
WarpDrive.logger.info("Ignoring missing entity " + entityId);
continue;
}
/**/
for (String tag : taggedEntity.getValue().replace("\t", " ").replace(",", " ").replace(" ", " ").split(" ")) {
switch (tag) {
case "Anchor" : ENTITIES_ANCHOR.add(entityId); break;
case "NoMass" : ENTITIES_NOMASS.add(entityId); break;
case "LeftBehind" : ENTITIES_LEFTBEHIND.add(entityId); break;
case "NonLivingTarget" : ENTITIES_NONLIVINGTARGET.add(entityId); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for entity " + entityId);
break;
}
}
}
// translate tagged items
ITEMS_FLYINSPACE = new HashSet(taggedItems.size());
ITEMS_NOFALLDAMAGE = new HashSet(taggedItems.size());
ITEMS_BREATHINGIC2 = new HashSet(taggedItems.size());
for (Entry<String, String> taggedItem : taggedItems.entrySet()) {
String itemId = taggedItem.getKey();
Item item = GameData.getItemRegistry().getObject(itemId);
if (item == null) {
WarpDrive.logger.info("Ignoring missing item " + itemId);
continue;
}
for (String tag : taggedItem.getValue().replace("\t", " ").replace(",", " ").replace(" ", " ").split(" ")) {
switch (tag) {
case "FlyInSpace" : ITEMS_FLYINSPACE.add(item); break;
case "NoFallDamage" : ITEMS_NOFALLDAMAGE.add(item); break;
case "BreathingIC2" : ITEMS_BREATHINGIC2.add(item); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for item " + item);
break;
}
}
}
adjustHardnessAndResistance();
print();
}
private static void print() {
// translate tagged blocks
WarpDrive.logger.info("Active blocks dictionnary:");
WarpDrive.logger.info("- " + BLOCKS_ORES.size() + " ores: " + getHashMessage(BLOCKS_ORES));
WarpDrive.logger.info("- " + BLOCKS_SOILS.size() + " soils: " + getHashMessage(BLOCKS_SOILS));
WarpDrive.logger.info("- " + BLOCKS_LOGS.size() + " logs: " + getHashMessage(BLOCKS_LOGS));
WarpDrive.logger.info("- " + BLOCKS_LEAVES.size() + " leaves: " + getHashMessage(BLOCKS_LEAVES));
WarpDrive.logger.info("- " + BLOCKS_ANCHOR.size() + " anchors: " + getHashMessage(BLOCKS_ANCHOR));
WarpDrive.logger.info("- " + BLOCKS_NOMASS.size() + " with NoMass tag: " + getHashMessage(BLOCKS_NOMASS));
WarpDrive.logger.info("- " + BLOCKS_LEFTBEHIND.size() + " with LeftBehind tag: " + getHashMessage(BLOCKS_LEFTBEHIND));
WarpDrive.logger.info("- " + BLOCKS_EXPANDABLE.size() + " expandable: " + getHashMessage(BLOCKS_EXPANDABLE));
WarpDrive.logger.info("- " + BLOCKS_MINING.size() + " with Mining tag: " + getHashMessage(BLOCKS_MINING));
WarpDrive.logger.info("- " + BLOCKS_NOMINING.size() + " with NoMining tag: " + getHashMessage(BLOCKS_NOMINING));
WarpDrive.logger.info("- " + BLOCKS_PLACE.size() + " with Placement priority: " + getHashMessage(BLOCKS_PLACE));
// translate tagged entities
WarpDrive.logger.info("Active entities dictionnary:");
WarpDrive.logger.info("- " + ENTITIES_ANCHOR.size() + " anchors: " + getHashMessage(ENTITIES_ANCHOR));
WarpDrive.logger.info("- " + ENTITIES_NOMASS.size() + " with NoMass tag: " + getHashMessage(ENTITIES_NOMASS));
WarpDrive.logger.info("- " + ENTITIES_LEFTBEHIND.size() + " with LeftBehind tag: " + getHashMessage(ENTITIES_LEFTBEHIND));
WarpDrive.logger.info("- " + ENTITIES_NONLIVINGTARGET.size() + " with NonLivingTarget tag: " + getHashMessage(ENTITIES_NONLIVINGTARGET));
// translate tagged items
WarpDrive.logger.info("Active items dictionnary:");
WarpDrive.logger.info("- " + ITEMS_FLYINSPACE.size() + " allowing fly in space: " + getHashMessage(ITEMS_FLYINSPACE));
WarpDrive.logger.info("- " + ITEMS_NOFALLDAMAGE.size() + " absorbing fall damages: " + getHashMessage(ITEMS_NOFALLDAMAGE));
WarpDrive.logger.info("- " + ITEMS_BREATHINGIC2.size() + " allowing breathing compressed air: " + getHashMessage(ITEMS_BREATHINGIC2));
}
private static void adjustHardnessAndResistance() {
// Apply explosion resistance adjustments
Blocks.obsidian.setResistance(60.0F);
Blocks.enchanting_table.setResistance(60.0F);
Blocks.ender_chest.setResistance(60.0F);
Blocks.anvil.setResistance(60.0F);
Blocks.water.setResistance(30.0F);
Blocks.flowing_water.setResistance(30.0F);
Blocks.lava.setResistance(30.0F);
Blocks.flowing_lava.setResistance(30.0F);
// open access to Block.blockHardness
Field fieldHardness = null;
Class<?> classBlock = null;
try {
classBlock = Class.forName("net.minecraft.block.Block");
} catch (Exception exception) {
exception.printStackTrace();
}
if (classBlock != null) {
try {
fieldHardness = classBlock.getDeclaredField("blockHardness");
} catch (Exception exception1) {
try {
fieldHardness = classBlock.getDeclaredField("field_149782_v");
} catch (Exception exception2) {
exception2.printStackTrace();
String map = "";
for(Field field : classBlock.getDeclaredFields()) {
if (!map.isEmpty()) {
map += ", ";
}
map += field.getName();
}
WarpDrive.logger.error("Unable to find blockHardness field in " + Blocks.air.getClass() + " class. Available fields are: " + map);
}
}
}
// TODO adjust IC2 Reinforced stone stats
if (WarpDriveConfig.isIndustrialCraft2loaded) {
ItemStack itemStackReinforcedStone = WarpDriveConfig.getModItemStack("IC2", "blockAlloy", -1);
WarpDrive.logger.info("Item " + Item.itemRegistry.getObject("IC2:blockAlloy"));
WarpDrive.logger.info("Block " + Block.blockRegistry.getObject("IC2:blockAlloy"));
Block blockReinforcedStone = (Block) Block.blockRegistry.getObject("IC2:blockAlloy");
}
// scan blocks registry
for(Object blockKey : Block.blockRegistry.getKeys()) {
Object block = Block.blockRegistry.getObject(blockKey);
WarpDrive.logger.debug("Checking block registry for '" + blockKey + "': " + block);
if (!(block instanceof Block)) {
WarpDrive.logger.error("Block registry for '" + blockKey + "': this is not a block? " + block);
} else {
// get hardness and blast resistance
float hardness = -2.0F;
if (fieldHardness != null) {
fieldHardness.setAccessible(true);
try {
hardness = (float)fieldHardness.get(block);
} catch (IllegalArgumentException | IllegalAccessException exception) {
exception.printStackTrace();
WarpDrive.logger.error("Unable to access block hardness value '" + blockKey + "' " + block);
}
}
float blastResistance = ((Block)block).getExplosionResistance(null);
// check actual values
if (hardness != -2.0F) {
if (hardness < 0 && !(BLOCKS_ANCHOR.contains(block))) {// unbreakable block
WarpDrive.logger.warn("Warning: non-anchor block with unbreakable hardness '" + blockKey + "' " + block + " (" + hardness + ")");
// WarpDrive.logger.error("Blacklisting block with unbreakable hardness '" + blockKey + "' " + block + " (" + hardness + ")");
// BLOCKS_ANCHOR.add((Block)block);
// BLOCKS_NOMINING.add((Block)block);
} else if (hardness > WarpDriveConfig.HULL_HARDNESS[0] && !(block instanceof BlockHullPlain || block instanceof BlockHullGlass || BLOCKS_ANCHOR.contains(block))) {
}
}
if (blastResistance > WarpDriveConfig.HULL_BLAST_RESISTANCE[0] && !(block instanceof BlockHullPlain || block instanceof BlockHullGlass || BLOCKS_ANCHOR.contains(block))) {
((Block)block).setResistance(WarpDriveConfig.HULL_BLAST_RESISTANCE[0]);
WarpDrive.logger.warn("Warning: non-anchor block with crazt blast resistance '" + blockKey + "' " + block + " (" + hardness + ")");
if (forceResistance) {
WarpDrive.logger.warn("Adjusting blast resistance of '" + blockKey + "' " + block + " from " + blastResistance + " to " + ((Block)block).getExplosionResistance(null));
if (((Block)block).getExplosionResistance(null) > WarpDriveConfig.HULL_BLAST_RESISTANCE[0]) {
WarpDrive.logger.error("Blacklisting block with crazy blast resistance '" + blockKey + "' " + block + " (" + blastResistance + ")");
BLOCKS_ANCHOR.add((Block)block);
BLOCKS_NOMINING.add((Block)block);
}
}
}
WarpDrive.logger.info("Block registry for '" + blockKey + "': Block " + block
+ " with hardness " + (fieldHardness != null ? hardness : "-") + " resistance " + ((Block)block).getExplosionResistance(null));
}
}
}
private static String getHashMessage(HashSet hashSet) {
String message = "";
for (Object object : hashSet) {
if (!message.isEmpty()) {
message += ", ";
}
if (object instanceof Block) {
message += GameRegistry.findUniqueIdentifierFor((Block) object);
} else if (object instanceof String) {
message += (String) object;
} else {
message += object;
}
}
return message;
}
private static String getHashMessage(HashMap<Block, Integer> hashMap) {
String message = "";
for (Entry<Block, Integer> entry : hashMap.entrySet()) {
if (!message.isEmpty()) {
message += ", ";
}
message += GameRegistry.findUniqueIdentifierFor(entry.getKey()) + "=" + entry.getValue();
}
return message;
}
}

View file

@ -6,25 +6,18 @@ import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameRegistry;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.filler.FillerManager;
import cr0s.warpdrive.config.structures.StructureManager;
import cr0s.warpdrive.data.Planet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -32,7 +25,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.oredict.OreDictionary;
public class WarpDriveConfig {
private static File configDirectory;
@ -147,35 +139,6 @@ public class WarpDriveConfig {
public static String[] SHIP_VOLUME_UNLIMITED_PLAYERNAMES = { "notch", "someone" };
public static boolean SHIP_WARMUP_SICKNESS = true;
// Tagged blocks and entities (loaded from configuration file at PreInit, parsed at PostInit)
private static HashMap<String, String> taggedBlocks = null;
private static HashMap<String, String> taggedEntities = null;
private static HashMap<String, String> taggedItems = null;
// Blocks dictionary
public static HashSet<Block> BLOCKS_ORES = null;
public static HashSet<Block> BLOCKS_SOILS = null;
public static HashSet<Block> BLOCKS_LOGS = null;
public static HashSet<Block> BLOCKS_LEAVES = null;
public static HashSet<Block> BLOCKS_ANCHOR = null;
public static HashSet<Block> BLOCKS_NOMASS = null;
public static HashSet<Block> BLOCKS_LEFTBEHIND = null;
public static HashSet<Block> BLOCKS_EXPANDABLE = null;
public static HashSet<Block> BLOCKS_MINING = null;
public static HashSet<Block> BLOCKS_NOMINING = null;
public static HashMap<Block, Integer> BLOCKS_PLACE = null;
// Entities dictionary
public static HashSet<String> ENTITIES_ANCHOR = null;
public static HashSet<String> ENTITIES_NOMASS = null;
public static HashSet<String> ENTITIES_LEFTBEHIND = null;
public static HashSet<String> ENTITIES_NONLIVINGTARGET = null;
// Items dictionary
public static HashSet<Item> ITEMS_FLYINSPACE = null;
public static HashSet<Item> ITEMS_NOFALLDAMAGE = null;
public static HashSet<Item> ITEMS_BREATHINGIC2 = null;
// Radar
public static int RADAR_MAX_ENERGY_STORED = 100000000; // 100kk eU
public static int RADAR_MAX_ISOLATION_RANGE = 2;
@ -303,6 +266,13 @@ public class WarpDriveConfig {
public static int CL_MAX_DISTANCE = 2;
public static int CL_RF_PER_CHUNKTICK = 320;
// Hull
public static float[] HULL_HARDNESS = { 25.0F, 50.0F, 80.0F };
public static float[] HULL_BLAST_RESISTANCE = { 60.0F, 90.0F, 120.0F };
public static Block getModBlock(final String mod, final String id) {
try {
return GameRegistry.findBlock(mod, id);
@ -484,161 +454,6 @@ public class WarpDriveConfig {
SHIP_CONTROLLER_UPDATE_INTERVAL_SECONDS = clamp(0, 300,
config.get("ship", "controller_update_interval", SHIP_CONTROLLER_UPDATE_INTERVAL_SECONDS, "(measured in seconds)").getInt());
// Block dictionary
{
config.addCustomCategoryComment("block_tags",
"Use this section to enable special behavior on blocks using tags.\n"
+ "Most blocks are already supported automatically. Only modify this section when something doesn't work!\n" + "\n"
+ "Tags shall be separated by at least one space, comma or tabulation.\n"
+ "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n"
+ "In case of conflicts, the latest tag overwrite the previous ones.\n"
+ "- Soil: this block is a soil for plants (default: dirt, farmland, grass, sand & soul sand).\n"
+ "- Log: this block is harvestable as a wood log (default: all 'log*', '*log' & '*logs' blocks from the ore dictionnary).\n"
+ "- Leaf: this block is harvestable as a leaf (default: all 'leave*', '*leave' & '*leaves' blocks from the ore dictionnary).\n"
+ "- Anchor: ship can't move with this block aboard (default: bedrock and assimilated).\n"
+ "- NoMass: this block doesn't count when calculating ship volume/mass (default: leaves, all 'air' blocks).\n"
+ "- LeftBehind: this block won't move with your ship (default: RailCraft heat, WarpDrive gases).\n"
+ "- Expandable: this block will be squished/ignored in case of collision.\n"
+ "- Mining: this block is mineable (default: all 'ore' blocks from the ore dictionnary).\n"
+ "- NoMining: this block is non-mineable (default: forcefields).\n"
+ "- PlaceEarliest: this block will be removed last and placed first (default: ship hull and projectors).\n"
+ "- PlaceEarlier: this block will be placed fairly soon (default: forcefield blocks).\n"
+ "- PlaceNormal: this block will be removed and placed with non-tile entities.\n"
+ "- PlaceLater: this block will be placed fairly late (default: IC2 Reactor core).\n"
+ "- PlaceLatest: this block will be removed first and placed last (default: IC2 Reactor chamber).");
ConfigCategory categoryBlockTags = config.getCategory("block_tags");
String[] taggedBlocksName = categoryBlockTags.getValues().keySet().toArray(new String[0]);
if (taggedBlocksName.length == 0) {
// farming
config.get("block_tags", "minecraft:dirt" , "Soil").getString();
config.get("block_tags", "minecraft:farmland" , "Soil").getString();
config.get("block_tags", "minecraft:grass" , "Soil").getString();
config.get("block_tags", "minecraft:sand" , "Soil").getString();
config.get("block_tags", "minecraft:soul_sand" , "Soil").getString();
config.get("block_tags", "IC2:blockRubWood" , "Log").getString();
// anchors
config.get("block_tags", "minecraft:bedrock" , "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:invisible_bedrock" , "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:invisible_bedrock" , "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:anti_anti_builder_stone", "Anchor NoMining").getString();
config.get("block_tags", "Artifacts:anti_builder" , "Anchor NoMining").getString();
// placement priorities
config.get("block_tags", "IC2:blockReinforcedFoam" , "PlaceEarliest NoMining").getString();
config.get("block_tags", "IC2:blockAlloy" , "PlaceEarliest NoMining").getString();
config.get("block_tags", "IC2:blockAlloyGlass" , "PlaceEarliest NoMining").getString();
config.get("block_tags", "minecraft:obsidian" , "PlaceEarliest Mining").getString();
config.get("block_tags", "AdvancedRepulsionSystems:field" , "PlaceEarlier NoMining").getString();
// FIXME config.get("block_tags", "MFFS:field" , "PlaceEarlier NoMining" ).getString();
config.get("block_tags", "IC2:blockGenerator" , "PlaceLater").getString();
config.get("block_tags", "IC2:blockReactorChamber" , "PlaceLatest").getString();
// expandables, a.k.a. "don't blow my ship with this..."
config.get("block_tags", "WarpDrive:blockGas" , "LeftBehind Expandable").getString();
config.get("block_tags", "Railcraft:residual.heat" , "LeftBehind Expandable").getString();
config.get("block_tags", "InvisibLights:blockLightSource" , "NoMass Expandable").getString();
config.get("block_tags", "WarpDrive:blockAir" , "NoMass Expandable PlaceLatest").getString();
// mining a mineshaft...
config.get("block_tags", "minecraft:web" , "Mining").getString();
config.get("block_tags", "minecraft:fence" , "Mining").getString();
config.get("block_tags", "minecraft:torch" , "Mining").getString();
config.get("block_tags", "minecraft:glowstone" , "Mining").getString();
config.get("block_tags", "minecraft:redstone_block" , "Mining").getString();
// mining an 'end' moon
config.get("block_tags", "WarpDrive:blockIridium" , "Mining").getString(); // stronger than obsidian but can still be mined (see ender moon)
taggedBlocksName = categoryBlockTags.getValues().keySet().toArray(new String[0]);
}
taggedBlocks = new HashMap(taggedBlocksName.length);
for (String name : taggedBlocksName) {
String tags = config.get("block_tags", name, "").getString();
taggedBlocks.put(name, tags);
}
}
// Entity dictionary
{
config.addCustomCategoryComment("entity_tags",
"Use this section to enable special behavior on entities using tags.\n"
+ "Most entities are already supported automatically. Only modify this section when something doesn't work!\n" + "\n"
+ "Tags shall be separated by at least one space, comma or tabulation.\n" + "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n"
+ "In case of conflicts, the latest tag overwrite the previous ones.\n" + "- Anchor: ship can't move with this entity aboard (default: none).\n"
+ "- NoMass: this entity doesn't count when calculating ship volume/mass (default: Galacticraft air bubble).\n"
+ "- LeftBehind: this entity won't move with your ship (default: Galacticraft air bubble).\n"
+ "- NonLivingTarget: this non-living entity can be targeted/removed by weapons (default: ItemFrame, Painting).");
ConfigCategory categoryEntityTags = config.getCategory("entity_tags");
String[] taggedEntitiesName = categoryEntityTags.getValues().keySet().toArray(new String[0]);
if (taggedEntitiesName.length == 0) {
config.get("entity_tags", "GalacticraftCore.OxygenBubble", "NoMass LeftBehind").getString();
config.get("entity_tags", "ItemFrame" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "Painting" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "LeashKnot" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "Boat" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartRideable" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartChest" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartFurnace" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartTNT" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartHopper" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "MinecartSpawner" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "EnderCrystal" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.BoatCarbon" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.BoatRubber" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.BoatElectric" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.Nuke" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.Itnt" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.StickyDynamite" , "NoMass NonLivingTarget").getString();
config.get("entity_tags", "IC2.Dynamite" , "NoMass NonLivingTarget").getString();
taggedEntitiesName = categoryEntityTags.getValues().keySet().toArray(new String[0]);
}
taggedEntities = new HashMap(taggedEntitiesName.length);
for (String name : taggedEntitiesName) {
String tags = config.get("entity_tags", name, "").getString();
taggedEntities.put(name, tags);
}
}
// Item dictionary
{
config.addCustomCategoryComment("item_tags", "Use this section to enable special behavior on items using tags.\n"
+ "Most items are already supported automatically. Only modify this section when something doesn't work!\n" + "\n"
+ "Tags shall be separated by at least one space, comma or tabulation.\n" + "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n"
+ "In case of conflicts, the latest tag overwrite the previous ones.\n" + "- FlyInSpace: player can move without gravity effect while wearing this item (default: jetpacks).\n"
+ "- NoFallDamage: player doesn't take fall damage while wearing this armor item (default: IC2 rubber boots).\n"
+ "- BreathingIC2: player can breath IC2 compressed air while wearing this armor item (default: IC2 nano helmet and Cie).\n");
ConfigCategory categoryItemTags = config.getCategory("item_tags");
String[] taggedItemsName = categoryItemTags.getValues().keySet().toArray(new String[0]);
if (taggedItemsName.length == 0) {
config.get("item_tags", "IC2:itemArmorHazmatHelmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemSolarHelmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemArmorNanoHelmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemArmorQuantumHelmet", "BreathingIC2").getString();
config.get("item_tags", "AdvancedSolarPanel:advanced_solar_helmet", "BreathingIC2").getString();
config.get("item_tags", "AdvancedSolarPanel:hybrid_solar_helmet", "BreathingIC2").getString();
config.get("item_tags", "AdvancedSolarPanel:ultimate_solar_helmet", "BreathingIC2").getString();
config.get("item_tags", "IC2:itemArmorJetpack", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "IC2:itemArmorJetpackElectric", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "GraviSuite:advJetpack", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "GraviSuite:advNanoChestPlate", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "GraviSuite:graviChestPlate", "FlyInSpace NoFallDamage").getString();
config.get("item_tags", "IC2:itemArmorRubBoots", "NoFallDamage").getString();
config.get("item_tags", "IC2:itemArmorQuantumBoots", "NoFallDamage").getString();
taggedItemsName = categoryItemTags.getValues().keySet().toArray(new String[0]);
}
taggedItems = new HashMap(taggedItemsName.length);
for (String name : taggedItemsName) {
String tags = config.get("item_tags", name, "").getString();
taggedItems.put(name, tags);
}
}
// Radar
RADAR_MAX_ENERGY_STORED = clamp(0, Integer.MAX_VALUE,
config.get("radar", "max_energy_stored", RADAR_MAX_ENERGY_STORED).getInt());
@ -840,6 +655,9 @@ public class WarpDriveConfig {
LIFT_UPDATE_INTERVAL_TICKS = clamp(1, 60,
config.get("lift", "update_interval_ticks", LIFT_UPDATE_INTERVAL_TICKS).getInt());
// Dictionary
Dictionary.loadConfig(config);
config.save();
}
@ -899,192 +717,11 @@ public class WarpDriveConfig {
FillerManager.loadOres(configDirectory);
StructureManager.loadStructures(configDirectory);
loadDictionnary();
Dictionary.apply();
FillerManager.finishLoading();
}
private static void loadDictionnary() {
// get default settings from parsing ore dictionary
BLOCKS_ORES = new HashSet<Block>();
BLOCKS_LOGS = new HashSet<Block>();
BLOCKS_LEAVES = new HashSet<Block>();
String[] oreNames = OreDictionary.getOreNames();
for (String oreName : oreNames) {
String lowerOreName = oreName.toLowerCase();
if (oreName.length() > 4 && oreName.substring(0, 3).equals("ore")) {
ArrayList<ItemStack> itemStacks = OreDictionary.getOres(oreName);
for (ItemStack itemStack : itemStacks) {
BLOCKS_ORES.add(Block.getBlockFromItem(itemStack.getItem()));
// WarpDrive.logger.info("- added " + oreName + " to ores as " + itemStack);
}
}
if (lowerOreName.startsWith("log") || lowerOreName.endsWith("log") || lowerOreName.endsWith("logs")) {
ArrayList<ItemStack> itemStacks = OreDictionary.getOres(oreName);
for (ItemStack itemStack : itemStacks) {
BLOCKS_LOGS.add(Block.getBlockFromItem(itemStack.getItem()));
// WarpDrive.logger.info("- added " + oreName + " to logs as " + itemStack);
}
}
if (lowerOreName.startsWith("leave") || lowerOreName.endsWith("leave") || lowerOreName.endsWith("leaves")) {
ArrayList<ItemStack> itemStacks = OreDictionary.getOres(oreName);
for (ItemStack itemStack : itemStacks) {
BLOCKS_LEAVES.add(Block.getBlockFromItem(itemStack.getItem()));
// WarpDrive.logger.info("- added " + oreName + " to leaves as " + itemStack);
}
}
}
// translate tagged blocks
BLOCKS_SOILS = new HashSet(taggedBlocks.size());
BLOCKS_ANCHOR = new HashSet(taggedBlocks.size());
BLOCKS_NOMASS = new HashSet(taggedBlocks.size() + BLOCKS_LEAVES.size());
BLOCKS_NOMASS.addAll(BLOCKS_LEAVES);
BLOCKS_LEFTBEHIND = new HashSet(taggedBlocks.size());
BLOCKS_EXPANDABLE = new HashSet(taggedBlocks.size() + BLOCKS_LEAVES.size());
BLOCKS_EXPANDABLE.addAll(BLOCKS_LEAVES);
BLOCKS_MINING = new HashSet(taggedBlocks.size());
BLOCKS_NOMINING = new HashSet(taggedBlocks.size());
BLOCKS_PLACE = new HashMap(taggedBlocks.size());
for (Entry<String, String> taggedBlock : taggedBlocks.entrySet()) {
Block block = Block.getBlockFromName(taggedBlock.getKey());
if (block == null) {
WarpDrive.logger.info("Ignoring missing block " + taggedBlock.getKey());
continue;
}
for (String tag : taggedBlock.getValue().replace("\t", " ").replace(",", " ").replace(" ", " ").split(" ")) {
switch (tag) {
case "Soil" : BLOCKS_SOILS.add(block); break;
case "Log" : BLOCKS_LOGS.add(block); break;
case "Leaf" : BLOCKS_LEAVES.add(block); break;
case "Anchor" : BLOCKS_ANCHOR.add(block); break;
case "NoMass" : BLOCKS_NOMASS.add(block); break;
case "LeftBehind" : BLOCKS_LEFTBEHIND.add(block); break;
case "Expandable" : BLOCKS_EXPANDABLE.add(block); break;
case "Mining" : BLOCKS_MINING.add(block); break;
case "NoMining" : BLOCKS_NOMINING.add(block); break;
case "PlaceEarliest": BLOCKS_PLACE.put(block, 0); break;
case "PlaceEarlier" : BLOCKS_PLACE.put(block, 1); break;
case "PlaceNormal" : BLOCKS_PLACE.put(block, 2); break;
case "PlaceLater" : BLOCKS_PLACE.put(block, 3); break;
case "PlaceLatest" : BLOCKS_PLACE.put(block, 4); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for block " + block);
break;
}
}
}
WarpDrive.logger.info("Active blocks dictionnary:");
WarpDrive.logger.info("- " + BLOCKS_ORES.size() + " ores: " + getHashMessage(BLOCKS_ORES));
WarpDrive.logger.info("- " + BLOCKS_SOILS.size() + " soils: " + getHashMessage(BLOCKS_SOILS));
WarpDrive.logger.info("- " + BLOCKS_LOGS.size() + " logs: " + getHashMessage(BLOCKS_LOGS));
WarpDrive.logger.info("- " + BLOCKS_LEAVES.size() + " leaves: " + getHashMessage(BLOCKS_LEAVES));
WarpDrive.logger.info("- " + BLOCKS_ANCHOR.size() + " anchors: " + getHashMessage(BLOCKS_ANCHOR));
WarpDrive.logger.info("- " + BLOCKS_NOMASS.size() + " with NoMass tag: " + getHashMessage(BLOCKS_NOMASS));
WarpDrive.logger.info("- " + BLOCKS_LEFTBEHIND.size() + " with LeftBehind tag: " + getHashMessage(BLOCKS_LEFTBEHIND));
WarpDrive.logger.info("- " + BLOCKS_EXPANDABLE.size() + " expandable: " + getHashMessage(BLOCKS_EXPANDABLE));
WarpDrive.logger.info("- " + BLOCKS_MINING.size() + " with Mining tag: " + getHashMessage(BLOCKS_MINING));
WarpDrive.logger.info("- " + BLOCKS_NOMINING.size() + " with NoMining tag: " + getHashMessage(BLOCKS_NOMINING));
WarpDrive.logger.info("- " + BLOCKS_PLACE.size() + " with Placement priority: " + getHashMessage(BLOCKS_PLACE));
// translate tagged entities
ENTITIES_ANCHOR = new HashSet(taggedEntities.size());
ENTITIES_NOMASS = new HashSet(taggedEntities.size());
ENTITIES_LEFTBEHIND = new HashSet(taggedEntities.size());
ENTITIES_NONLIVINGTARGET = new HashSet(taggedEntities.size());
for (Entry<String, String> taggedEntity : taggedEntities.entrySet()) {
String entityId = taggedEntity.getKey();
/* we can't detect missing entities, since some of them are 'hacked' in
if (!EntityList.stringToIDMapping.containsKey(entityId)) {
WarpDrive.logger.info("Ignoring missing entity " + entityId);
continue;
}
/**/
for (String tag : taggedEntity.getValue().replace("\t", " ").replace(",", " ").replace(" ", " ").split(" ")) {
switch (tag) {
case "Anchor" : ENTITIES_ANCHOR.add(entityId); break;
case "NoMass" : ENTITIES_NOMASS.add(entityId); break;
case "LeftBehind" : ENTITIES_LEFTBEHIND.add(entityId); break;
case "NonLivingTarget" : ENTITIES_NONLIVINGTARGET.add(entityId); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for entity " + entityId);
break;
}
}
}
WarpDrive.logger.info("Active entities dictionnary:");
WarpDrive.logger.info("- " + ENTITIES_ANCHOR.size() + " anchors: " + getHashMessage(ENTITIES_ANCHOR));
WarpDrive.logger.info("- " + ENTITIES_NOMASS.size() + " with NoMass tag: " + getHashMessage(ENTITIES_NOMASS));
WarpDrive.logger.info("- " + ENTITIES_LEFTBEHIND.size() + " with LeftBehind tag: " + getHashMessage(ENTITIES_LEFTBEHIND));
WarpDrive.logger.info("- " + ENTITIES_NONLIVINGTARGET.size() + " with NonLivingTarget tag: " + getHashMessage(ENTITIES_NONLIVINGTARGET));
// translate tagged items
ITEMS_FLYINSPACE = new HashSet(taggedItems.size());
ITEMS_NOFALLDAMAGE = new HashSet(taggedItems.size());
ITEMS_BREATHINGIC2 = new HashSet(taggedItems.size());
for (Entry<String, String> taggedItem : taggedItems.entrySet()) {
String itemId = taggedItem.getKey();
Item item = GameData.getItemRegistry().getObject(itemId);
if (item == null) {
WarpDrive.logger.info("Ignoring missing item " + itemId);
continue;
}
for (String tag : taggedItem.getValue().replace("\t", " ").replace(",", " ").replace(" ", " ").split(" ")) {
switch (tag) {
case "FlyInSpace" : ITEMS_FLYINSPACE.add(item); break;
case "NoFallDamage" : ITEMS_NOFALLDAMAGE.add(item); break;
case "BreathingIC2" : ITEMS_BREATHINGIC2.add(item); break;
default:
WarpDrive.logger.error("Unsupported tag '" + tag + "' for item " + item);
break;
}
}
}
WarpDrive.logger.info("Active items dictionnary:");
WarpDrive.logger.info("- " + ITEMS_FLYINSPACE.size() + " allowing fly in space: " + getHashMessage(ITEMS_FLYINSPACE));
WarpDrive.logger.info("- " + ITEMS_NOFALLDAMAGE.size() + " absorbing fall damages: " + getHashMessage(ITEMS_NOFALLDAMAGE));
WarpDrive.logger.info("- " + ITEMS_BREATHINGIC2.size() + " allowing breathing compressed air: " + getHashMessage(ITEMS_BREATHINGIC2));
// Apply hardness adjustments
Blocks.obsidian.setResistance(60.0F);
Blocks.enchanting_table.setResistance(60.0F);
Blocks.ender_chest.setResistance(60.0F);
Blocks.anvil.setResistance(60.0F);
Blocks.water.setResistance(30.0F);
Blocks.flowing_water.setResistance(30.0F);
Blocks.lava.setResistance(30.0F);
Blocks.flowing_lava.setResistance(30.0F);
}
private static String getHashMessage(HashSet hashSet) {
String message = "";
for (Object object : hashSet) {
if (!message.isEmpty()) {
message += ", ";
}
if (object instanceof Block) {
message += GameRegistry.findUniqueIdentifierFor((Block) object);
} else if (object instanceof String) {
message += (String) object;
} else {
message += object;
}
}
return message;
}
private static String getHashMessage(HashMap<Block, Integer> hashMap) {
String message = "";
for (Entry<Block, Integer> entry : hashMap.entrySet()) {
if (!message.isEmpty()) {
message += ", ";
}
message += GameRegistry.findUniqueIdentifierFor(entry.getKey()) + "=" + entry.getValue();
}
return message;
}
private static void loadForgeMultipart() {
try {
Class forgeMultipart_helper = Class.forName("codechicken.multipart.MultipartHelper");

View file

@ -19,6 +19,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBreathingHelmet;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.world.SpaceTeleporter;
@ -137,7 +138,7 @@ public class LivingHandler {
player_airTank.put(playerName, air - 1);
}
}
} else if (WarpDriveConfig.ITEMS_BREATHINGIC2.contains(helmet)) {
} else if (Dictionary.ITEMS_BREATHINGIC2.contains(helmet)) {
hasHelmet = true;
if (air == null) {// new player in space => grace period
player_airTank.put(playerName, AIR_TANK_TICKS);
@ -238,7 +239,7 @@ public class LivingHandler {
for (int i = 0; i < 4; i++) {
ItemStack armor = player.getCurrentArmor(i);
if (armor != null) {
if (WarpDriveConfig.ITEMS_NOFALLDAMAGE.contains(armor.getItem())) {
if (Dictionary.ITEMS_NOFALLDAMAGE.contains(armor.getItem())) {
event.setCanceled(true); // Don't damage player
}
}