diff --git a/config.yml b/config.yml index faec32b2..0d59d6a1 100644 --- a/config.yml +++ b/config.yml @@ -83,6 +83,19 @@ production_general: update_cycle: 20 repair_period: 28 disrepair_period: 14 +nether_general: + disable_portals: true + nether_scale: 8 + world_name: world + nether_name: world_nether + teleport_platform_material_nether_factory: OBSIDIAN + marker_material_nether_factory: COAL_BLOCK + marker_max_distance: 64 + allow_reinforcement_creation_above_teleport_platform: false + allow_block_placement_above_teleport_platform: true + teleport_platform_invunerable: false + regenerate_teleport_block_on_teleport: false + remove_blocks_above_teleport_platform_on_teleport: true printing_presses: fuel: Charcoal: @@ -1890,7 +1903,13 @@ production_factories: - Mutate_Acacia_Saplings - Mutate_Dark_Oak_Saplings - Mutate_Podzol - - Mutate_Grassless_Dirt + - Mutate_Grassless_Dirt + - Sequencing_Sunflower + - Sequencing_Lilac + - Sequencing_Double_Tallgrass + - Sequencing_Large_Fern + - Sequencing_Rose_Bush + - Sequencing_Peony repair_multiple: 10 repair_inputs: Oak Saplings: @@ -2570,6 +2589,39 @@ production_factories: amount: 1 display_name: Smaragdus lore: An item used to create a Bastion Block +nether_factory: + name: Nether Factory + fuel: + Charcoal: + material: COAL + durability: 1 + costs: + construction: + Aspect of Nether: + material: MAGMA_CREAM + amount: 8 + display_name: Aspect of Nether + lore: A concentrated essence of the Nether + Aspect of Terra: + material: DIAMOND + amount: 8 + display_name: Aspect of Terra + lore: A concentrated essence of Terra + Aspect of END: + material: FLINT + amount: 8 + display_name: Aspect of End + lore: A concentrated essence of the End + repair: + Diamond block: + material: DIAMOND_BLOCK + amount: 1 + repair_multiple: 1 + fuel_time: 10 + repair_time: 12 + scaling_radius: 5000 + cost_scaling_radius: 5000 + use_fuel_on_teleport: false production_recipes: Wood_XP_Bottle_0: name: Brew XP Bottles - 1 @@ -7287,3 +7339,192 @@ production_recipes: material: SPONGE amount: 32 display_name: Bastion + Sequencing_Sunflower: + name: Sequencing Sunflower + inputs: + Dandelion: + material: YELLOW_FLOWER + amount: 8 + Sugar Cane: + material: SUGAR_CANE + amount: 8 + outputs: + Sunflower: + material: DOUBLE_PLANT + amount: 4 + durability: 0 + Sequencing_Lilac: + name: Sequencing Lilac + inputs: + Poppy: + material: RED_ROSE + amount: 8 + Oak Sapling: + material: SAPLING + amount: 8 + outputs: + Lilac: + material: DOUBLE_PLANT + amount: 4 + durability: 1 + Sequencing_Double_Tallgrass: + name: Sequencing Double Tallgrass + inputs: + Grass: + material: LONG_GRASS + amount: 16 + durability: 1 + outputs: + Double Tallgrass: + material: DOUBLE_PLANT + amount: 4 + durability: 2 + Sequencing_Large_Fern: + name: Sequencing Large Fern + inputs: + Grass: + material: LONG_GRASS + amount: 16 + durability: 1 + outputs: + Large Fern: + material: DOUBLE_PLANT + amount: 4 + durability: 3 + Sequencing_Rose_Bush: + name: Sequencing Rose Bush + inputs: + Poppy: + material: RED_ROSE + amount: 8 + Cactus: + material: CACTUS + amount: 8 + outputs: + Rose Bush: + material: DOUBLE_PLANT + amount: 4 + durability: 4 + Sequencing_Peony: + name: Sequencing Peony + inputs: + Poppy: + material: RED_ROSE + amount: 8 + Oak Leaves: + material: LEAVES + amount: 8 + outputs: + Peony: + material: DOUBLE_PLANT + amount: 4 + durability: 5 + Aspect_Factory: + name: Arcane Elementizer + fuel: + Charcoal: + material: COAL + durability: 1 + inputs: + Netherbrick: + material: NETHER_BRICK + amount: 1536 + Redstone: + material: REDSTONE + amount: 1152 + Netherquartz: + material: QUARTZ + amount: 576 + recipes: + - Forge_Aspect_of_Terra + - Forge_Aspect_of_End + - Forge_Aspect_of_Nether + - Craft_Eye_of_Ender + repair_multiple: 26 + repair_inputs: + Nether Brick: + material: NETHER_BRICK + amount: 6 + Redstone: + material: REDSTONE + amount: 5 + Netherquartz: + material: QUARTZ + amount: 2 + Forge_Aspect_of_Terra: + name: Forge Aspect of Terra + production_time: 64 + inputs: + Emerald Block: + material: EMERALD_BLOCK + amount: 24 + Diamond Block: + material: DIAMOND_BLOCK + amount: 24 + Gold Ore: + material: GOLD_ORE + amount: 8 + Slime Ball: + material: SLIME_BALL + amount: 8 + Anvil: + material: ANVIL + amount: 8 + outputs: + Aspect of Terra: + material: DIAMOND + amount: 1 + display_name: Aspect of Terra + lore: A concentrated essence of Terra + Forge_Aspect_of_End: + name: Forge Aspect of End + production_time: 64 + inputs: + Ender Pearl: + material: ENDER_PEARL + amount: 256 + Ender Chest: + material: ENDER_CHEST + amount: 256 + Endstone: + material: ENDER_STONE + amount: 1024 + outputs: + Aspect of End: + material: FLINT + amount: 1 + display_name: Aspect of End + lore: A concentrated essence of the End + Forge_Aspect_of_Nether: + name: Forge Aspect of Nether + production_time: 64 + inputs: + Ghast Tears: + material: GHAST_TEAR + amount: 16 + Quartz Ore: + material: QUARTZ_ORE + amount: 512 + Glowstone: + material: GLOWSTONE + amount: 512 + outputs: + Aspect of Nether: + material: MAGMA_CREAM + amount: 1 + display_name: Aspect of Nether + lore: A concentrated essence of the Nether + Craft_Eye_of_Ender: + name: Craft Eye of Ender + production_time: 1 + inputs: + Blaze Powder: + material: BLAZE_POWDER + amount: 265 + Ender Pearl: + material: ENDER_PEARL + amount: 265 + outputs: + Eye of Ender: + material: EYE_OF_ENDER + amount: 256 diff --git a/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java b/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java index 47c39d46..b43331f3 100644 --- a/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java +++ b/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java @@ -25,12 +25,14 @@ import com.github.igotyou.FactoryMod.listeners.NoteStackListener; import com.github.igotyou.FactoryMod.listeners.RedstoneListener; import com.github.igotyou.FactoryMod.managers.FactoryModManager; +import com.github.igotyou.FactoryMod.properties.NetherFactoryProperties; import com.github.igotyou.FactoryMod.properties.PrintingPressProperties; import com.github.igotyou.FactoryMod.properties.ProductionProperties; import com.github.igotyou.FactoryMod.recipes.ProductionRecipe; import com.github.igotyou.FactoryMod.recipes.ProbabilisticEnchantment; import com.github.igotyou.FactoryMod.utility.ItemList; import com.github.igotyou.FactoryMod.utility.NamedItemStack; + import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.ShapelessRecipe; @@ -42,6 +44,7 @@ public class FactoryModPlugin extends JavaPlugin public static HashMap productionProperties; public static HashMap productionRecipes; public PrintingPressProperties printingPressProperties; + public NetherFactoryProperties netherFactoryProperties; public static final String VERSION = "v1.0"; //Current version of plugin public static final String PLUGIN_NAME = "FactoryMod"; //Name of plugin @@ -50,6 +53,17 @@ public class FactoryModPlugin extends JavaPlugin public static final int TICKS_PER_SECOND = 20; //The number of ticks per second public static final String PRINTING_PRESSES_SAVE_FILE = "pressSaves"; + public static final String NETHER_FACTORY_SAVE_FILE = "netherSaves"; + public static boolean DISABLE_PORTALS; + public static int NETHER_SCALE; + public static boolean ALLOW_REINFORCEMENT_CREATION_ABOVE_TELEPORT_PLATFORM; + public static boolean ALLOW_BLOCK_PLACEMENT_ABOVE_TELEPORT_PLATFORM; + public static boolean TELEPORT_PLATFORM_INVUNERABLE; + public static boolean REGENERATE_TELEPORT_BLOCK_ON_TELEPORT; + public static boolean REMOVE_BLOCK_ABOVE_TELEPORT_PLATFORM_ON_TELEPORT; + public static String WORLD_NAME; + public static String NETHER_NAME; + public static int PRODUCER_UPDATE_CYCLE; public static boolean PRODUCTION_ENEABLED; public static int SAVE_CYCLE; @@ -58,6 +72,9 @@ public class FactoryModPlugin extends JavaPlugin public static boolean CITADEL_ENABLED; public static Material FACTORY_INTERACTION_MATERIAL; public static boolean DESTRUCTIBLE_FACTORIES; + public static int NETHER_MARKER_MAX_DISTANCE; + public static Material NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL; + public static Material NETHER_FACTORY_MARKER_MATERIAL; public static boolean DISABLE_EXPERIENCE; public static long DISREPAIR_PERIOD; public static long REPAIR_PERIOD; @@ -106,31 +123,55 @@ public void initConfig() this.saveDefaultConfig(); reloadConfig(); config = getConfig(); - //how often should the managers save? - SAVE_CYCLE = config.getInt("general.save_cycle",15)*60*20; - //what's the material of the center block of factorys? - CENTRAL_BLOCK_MATERIAL = Material.getMaterial(config.getString("general.central_block")); - //Return the build materials upon destruction of factory. - RETURN_BUILD_MATERIALS = config.getBoolean("general.return_build_materials",false); - //is citadel enabled? - CITADEL_ENABLED = config.getBoolean("general.citadel_enabled",true); - //what's the tool that we use to interact with the factorys? - FACTORY_INTERACTION_MATERIAL = Material.getMaterial(config.getString("general.factory_interaction_material","STICK")); - //If factories are removed upon destruction of their blocks - DESTRUCTIBLE_FACTORIES=config.getBoolean("general.destructible_factories",false); - //Check if XP drops should be disabled - DISABLE_EXPERIENCE=config.getBoolean("general.disable_experience",false); - //How frequently factories are updated - PRODUCER_UPDATE_CYCLE = config.getInt("production_general.update_cycle",20); - //Period of days before a factory is removed after it falls into disrepair - DISREPAIR_PERIOD= config.getLong("general.disrepair_period",14)*24*60*60*1000; - //The length of time it takes a factory to go to 0% health - REPAIR_PERIOD = config.getLong("production_general.repair_period",28)*24*60*60*1000; - //Disable recipes which result in the following items - //Do we output the running state with a lever? - LEVER_OUTPUT_ENABLED = config.getBoolean("general.lever_output_enabled",true); - //Do we allow factories to be started with redstone? - REDSTONE_START_ENABLED = config.getBoolean("general.redstone_start_enabled",true); + //what should the nether scaling be for the nether factorys? + NETHER_SCALE = config.getInt("nether_general.nether_scale",8); + //Should we Disable regular portals? + DISABLE_PORTALS = config.getBoolean("nether_general.disable_portals", true); + //Allow reinforcement above nether factory teleport platforms. + ALLOW_REINFORCEMENT_CREATION_ABOVE_TELEPORT_PLATFORM = config.getBoolean("nether_general.allow_reinforcement_creation_above_teleport_platform", false); + //Allow people to place blocks above nether factory teleport platforms. + ALLOW_BLOCK_PLACEMENT_ABOVE_TELEPORT_PLATFORM = config.getBoolean("nether_general.allow_block_placement_above_teleport_platform", false); + //Make teleport platforms unbreakable + TELEPORT_PLATFORM_INVUNERABLE = config.getBoolean("nether_general.teleport_platform_invunerable",false); + //Right before a player get's teleported, should the teleport platform be regenerated? + REGENERATE_TELEPORT_BLOCK_ON_TELEPORT = config.getBoolean("nether_general.regenerate_teleport_block_on_teleport", false); + //Right before a player get's teleported, should the blocks above the portal be destroyed(ignotes citadel)? + REMOVE_BLOCK_ABOVE_TELEPORT_PLATFORM_ON_TELEPORT = config.getBoolean("nether_general.remove_blocks_above_teleport_platform_on_teleport", false); + //what's the name of the overworld? + WORLD_NAME = config.getString("nether_general.world_name", "world"); + //what's the name of the overworld? + NETHER_NAME = config.getString("nether_general.nether_name", "world_nether"); + //how often should the managers save? + SAVE_CYCLE = config.getInt("general.save_cycle",15)*60*20; + //what's the material of the center block of factorys? + CENTRAL_BLOCK_MATERIAL = Material.getMaterial(config.getString("general.central_block")); + //what's the material of the nether portal teleportation platforms? + NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL = Material.getMaterial(config.getString("nether_general.teleport_platform_material_nether_factory")); + //what's the material of the marker blocks for nether factorys? + NETHER_FACTORY_MARKER_MATERIAL = Material.getMaterial(config.getString("nether_general.marker_material_nether_factory")); + //how far from the factory can the marker be? + NETHER_MARKER_MAX_DISTANCE = config.getInt("nether_general.marker_max_distance"); + //Return the build materials upon destruction of factory. + RETURN_BUILD_MATERIALS = config.getBoolean("general.return_build_materials",false); + //is citadel enabled? + CITADEL_ENABLED = config.getBoolean("general.citadel_enabled",true); + //what's the tool that we use to interact with the factorys? + FACTORY_INTERACTION_MATERIAL = Material.getMaterial(config.getString("general.factory_interaction_material","STICK")); + //If factories are removed upon destruction of their blocks + DESTRUCTIBLE_FACTORIES=config.getBoolean("general.destructible_factories",false); + //Check if XP drops should be disabled + DISABLE_EXPERIENCE=config.getBoolean("general.disable_experience",false); + //How frequently factories are updated + PRODUCER_UPDATE_CYCLE = config.getInt("production_general.update_cycle",20); + //Period of days before a factory is removed after it falls into disrepair + DISREPAIR_PERIOD= config.getLong("general.disrepair_period",14)*24*60*60*1000; + //The length of time it takes a factory to go to 0% health + REPAIR_PERIOD = config.getLong("production_general.repair_period",28)*24*60*60*1000; + //Disable recipes which result in the following items + //Do we output the running state with a lever? + LEVER_OUTPUT_ENABLED = config.getBoolean("general.lever_output_enabled",true); + //Do we allow factories to be started with redstone? + REDSTONE_START_ENABLED = config.getBoolean("general.redstone_start_enabled",true); int g = 0; Iterator disabledRecipes=config.getStringList("crafting.disable").iterator(); while(disabledRecipes.hasNext()) @@ -257,7 +298,9 @@ public void initConfig() } ConfigurationSection configPrintingPresses=config.getConfigurationSection("printing_presses"); + ConfigurationSection configNetherFactory=config.getConfigurationSection("nether_factory"); printingPressProperties = PrintingPressProperties.fromConfig(this, configPrintingPresses); + netherFactoryProperties = NetherFactoryProperties.fromConfig(this, configNetherFactory); } private List getEnchantments(ConfigurationSection configEnchantments) @@ -415,4 +458,8 @@ public static void sendConsoleMessage(String message) public PrintingPressProperties getPrintingPressProperties() { return printingPressProperties; } + + public NetherFactoryProperties getNetherFactoryProperties() { + return netherFactoryProperties; + } } diff --git a/src/com/github/igotyou/FactoryMod/FactoryObject.java b/src/com/github/igotyou/FactoryMod/FactoryObject.java index d55d102a..c8e59375 100644 --- a/src/com/github/igotyou/FactoryMod/FactoryObject.java +++ b/src/com/github/igotyou/FactoryMod/FactoryObject.java @@ -2,11 +2,13 @@ import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Chest; import org.bukkit.block.Furnace; import org.bukkit.inventory.Inventory; import com.github.igotyou.FactoryMod.interfaces.Properties; + import java.util.Date; //original file: @@ -30,7 +32,8 @@ public class FactoryObject public enum FactoryType { PRODUCTION, - PRINTING_PRESS + PRINTING_PRESS, + NETHER_FACTORY } @@ -58,7 +61,7 @@ public FactoryObject(Location factoryLocation, Location factoryInventoryLocation this.factoryType = factoryType; this.subFactoryType = subFactoryType; this.upgraded = false; - if (this.isWhole()) + if (this.isWhole(true)) { initializeInventory(); } @@ -78,7 +81,7 @@ public FactoryObject(Location factoryLocation, Location factoryInventoryLocation this.factoryType = factoryType; this.subFactoryType = subFactoryType; this.upgraded = false; - if (this.isWhole()) + if (this.isWhole(true)) { initializeInventory(); } @@ -161,6 +164,10 @@ public Inventory getInventory() */ public Inventory getPowerSourceInventory() { + if (!(factoryPowerSourceLocation.getBlock().getType() == Material.FURNACE || factoryPowerSourceLocation.getBlock().getType() == Material.BURNING_FURNACE)) + { + return null; + } Furnace furnaceBlock = (Furnace)factoryPowerSourceLocation.getBlock().getState(); factoryPowerInventory = furnaceBlock.getInventory(); return factoryPowerInventory; @@ -186,7 +193,7 @@ public boolean getActive() /** * returns true if all factory blocks are occupied with the correct blocks */ - public boolean isWhole() + public boolean isWhole(boolean initCall) { //Check if power source exists if(factoryPowerSourceLocation.getBlock().getType().getId()== 61 || factoryPowerSourceLocation.getBlock().getType().getId()== 62) diff --git a/src/com/github/igotyou/FactoryMod/Factorys/BaseFactory.java b/src/com/github/igotyou/FactoryMod/Factorys/BaseFactory.java index 0d7e9a84..1f651a3f 100644 --- a/src/com/github/igotyou/FactoryMod/Factorys/BaseFactory.java +++ b/src/com/github/igotyou/FactoryMod/Factorys/BaseFactory.java @@ -441,7 +441,7 @@ public void destroy(Location destroyLocation) /* * Repairs the factory */ - private void repair(int amountRepaired) + protected void repair(int amountRepaired) { currentRepair-=amountRepaired; if(currentRepair<0) diff --git a/src/com/github/igotyou/FactoryMod/Factorys/NetherFactory.java b/src/com/github/igotyou/FactoryMod/Factorys/NetherFactory.java new file mode 100644 index 00000000..0ff2fe92 --- /dev/null +++ b/src/com/github/igotyou/FactoryMod/Factorys/NetherFactory.java @@ -0,0 +1,605 @@ +package com.github.igotyou.FactoryMod.Factorys; + +import static com.untamedears.citadel.Utility.getReinforcement; +import static com.untamedears.citadel.Utility.isReinforced; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.github.igotyou.FactoryMod.FactoryModPlugin; +import com.github.igotyou.FactoryMod.managers.NetherFactoryManager; +import com.github.igotyou.FactoryMod.properties.NetherFactoryProperties; +import com.github.igotyou.FactoryMod.utility.InteractionResponse; +import com.github.igotyou.FactoryMod.utility.InteractionResponse.InteractionResult; +import com.github.igotyou.FactoryMod.utility.ItemList; +import com.github.igotyou.FactoryMod.utility.NamedItemStack; +import com.untamedears.citadel.entity.PlayerReinforcement; + +import java.util.ArrayList; +import java.util.List; + +public class NetherFactory extends BaseFactory +{ + + private NetherFactoryProperties netherFactoryProperties;//the properties of the production factory + private Location netherTeleportPlatform; + private Location overworldTeleportPlatform; + private NetherOperationMode mode; + private NetherFactoryManager netherManager; + public NetherOperationMode getMode() { + return mode; + } + + /** + * Constructor called when creating portal + */ + public NetherFactory (Location factoryLocation, Location factoryInventoryLocation, Location factoryPowerSource, Location nTeleportPlatform, Location oTeleportPlatform, + NetherFactoryProperties netherFactoryProperties, NetherFactoryManager netherManager) + { + super(factoryLocation, factoryInventoryLocation, factoryPowerSource, FactoryType.NETHER_FACTORY, "Nether factory"); + this.netherTeleportPlatform = nTeleportPlatform; + this.overworldTeleportPlatform = oTeleportPlatform; + this.netherFactoryProperties = netherFactoryProperties; + this.mode = NetherOperationMode.REPAIR; + this.netherManager = netherManager; + } + + /** + * Constructor + */ + public NetherFactory (Location factoryLocation, Location factoryInventoryLocation, Location factoryPowerSource, Location nTeleportPlatform, Location oTeleportPlatform, + boolean active, double currentMaintenance, + long timeDisrepair, NetherOperationMode mode, NetherFactoryProperties netherFactoryProperties, + NetherFactoryManager netherManager) + { + super(factoryLocation, factoryInventoryLocation, factoryPowerSource, FactoryType.NETHER_FACTORY, active, "Nether factory", 0 , 0, currentMaintenance, timeDisrepair); + this.netherFactoryProperties = netherFactoryProperties; + this.netherTeleportPlatform = nTeleportPlatform; + this.overworldTeleportPlatform = oTeleportPlatform; + this.mode = mode; + this.netherManager = netherManager; + } + + @Override + public boolean isRepairing() { + return mode == NetherOperationMode.REPAIR; + } + + @Override + public void destroy(Location destroyLocation) + { + if (destroyLocation.equals(overworldTeleportPlatform) || destroyLocation.equals(netherTeleportPlatform)) + { + powerOff(); + } + else if (destroyLocation.equals(factoryLocation) || destroyLocation.equals(factoryInventoryLocation) || destroyLocation.equals(factoryPowerSourceLocation)) + { + powerOff(); + currentRepair=getMaxRepair(); + timeDisrepair=System.currentTimeMillis(); + } + } + + /** + * Returns either a success or error message. + * Called by the blockListener when a player left clicks the center block, with the InteractionMaterial + */ + @Override + public void update() + { + if (mode == NetherOperationMode.REPAIR) + { + //if factory is turned on + if (active) + { + //if the materials required to produce the current recipe are in the factory inventory + if (checkHasMaterials()) + { + //if the factory has been working for less than the required time for the recipe + if (currentProductionTimer < getProductionTime()) + { + //if the factory power source inventory has enough fuel for at least 1 energyCycle + if (isFuelAvailable()) + { + //if the time since fuel was last consumed is equal to how often fuel needs to be consumed + if (currentEnergyTimer == getEnergyTime()-1) + { + //remove one fuel. + getFuel().removeFrom(getPowerSourceInventory()); + //0 seconds since last fuel consumption + currentEnergyTimer = 0; + fuelConsumed(); + } + //if we don't need to consume fuel, just increment the energy timer + else + { + currentEnergyTimer++; + } + //increment the production timer + currentProductionTimer ++; + postUpdate(); + } + //if there is no fuel Available turn off the factory + else + { + powerOff(); + } + } + + //if the production timer has reached the recipes production time remove input from chest, and add output material + else if (currentProductionTimer >= getProductionTime()) + { + consumeInputs(); + produceOutputs(); + //Repairs the factory + repair(getRepairs().removeMaxFrom(getInventory(),(int)currentRepair)); + recipeFinished(); + + currentProductionTimer = 0; + powerOff(); + } + } + else + { + powerOff(); + } + } + } + else if (mode == NetherOperationMode.TELEPORT) + { + if(!isFuelAvailable()) + { + togglePower(); + } + } + } + + public List getTeleportationBlockResponse(Player player, Location clickedBlock) + { + List responses=new ArrayList(); + //does the player have acsess to the nether factory via ciatdel? + if ((!FactoryModPlugin.CITADEL_ENABLED || (FactoryModPlugin.CITADEL_ENABLED && !isReinforced(factoryLocation))) || + (((PlayerReinforcement) getReinforcement(factoryLocation)).isAccessible(player))) + { + if (mode == NetherOperationMode.TELEPORT) + { + if (active) + { + if (isFuelAvailable() || !netherFactoryProperties.getUseFuelOnTeleport()) + { + Location playerLocation = player.getLocation(); + if ( playerLocation.getBlockX() == clickedBlock.getBlockX() + && (playerLocation.getBlockY()-1) == clickedBlock.getBlockY() + && playerLocation.getBlockZ() == clickedBlock.getBlockZ()) + { + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "Commencing teleportation...")); + if (clickedBlock.getWorld().getName().equalsIgnoreCase(FactoryModPlugin.WORLD_NAME)) + { + if (FactoryModPlugin.REMOVE_BLOCK_ABOVE_TELEPORT_PLATFORM_ON_TELEPORT) + { + removeBlocksAboveTeleportPlatform(netherTeleportPlatform); + } + Location destination = new Location(netherTeleportPlatform.getWorld(), netherTeleportPlatform.getX(), netherTeleportPlatform.getY(), netherTeleportPlatform.getZ(), playerLocation.getYaw(), playerLocation.getPitch()); + destination.add(0.5, 1.5, 0.5); + player.teleport(destination); + if (netherFactoryProperties.getUseFuelOnTeleport()) + { + getFuel().removeFrom(getPowerSourceInventory()); + } + } + else if (clickedBlock.getWorld().getName().equalsIgnoreCase(FactoryModPlugin.NETHER_NAME)) + { + if (FactoryModPlugin.REMOVE_BLOCK_ABOVE_TELEPORT_PLATFORM_ON_TELEPORT) + { + removeBlocksAboveTeleportPlatform(overworldTeleportPlatform); + } + Location destination = new Location(overworldTeleportPlatform.getWorld(), overworldTeleportPlatform.getX(), overworldTeleportPlatform.getY(), overworldTeleportPlatform.getZ(), playerLocation.getYaw(), playerLocation.getPitch()); + destination.add(0.5, 1.5, 0.5); + player.teleport(destination); + if (netherFactoryProperties.getUseFuelOnTeleport()) + { + getFuel().removeFrom(getPowerSourceInventory()); + } + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, you must stand on the teleportation block!")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, factory is missing fuel! ("+getFuel().getMultiple(1).toString()+")")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, factory is turned off!")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, factory is not in teleport mode.")); + } + return responses; + } + else + { + //is the player potentialy holding a security note/ticket? + ItemStack itemInHand = player.getItemInHand(); + if (itemInHand.getType() == Material.PAPER) + { + if (isInTicketMode()) + { + int ticketCheck = checkTicket(itemInHand); + if (ticketCheck > 0) + { + if (mode == NetherOperationMode.TELEPORT) + { + if (active) + { + if (isFuelAvailable()) + { + Location playerLocation = player.getLocation(); + if ( playerLocation.getBlockX() == clickedBlock.getBlockX() + && (playerLocation.getBlockY()-1) == clickedBlock.getBlockY() + && playerLocation.getBlockZ() == clickedBlock.getBlockZ()) + { + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "Commencing teleportation...")); + if (clickedBlock.getWorld().getName().equalsIgnoreCase(FactoryModPlugin.WORLD_NAME)) + { + if (FactoryModPlugin.REMOVE_BLOCK_ABOVE_TELEPORT_PLATFORM_ON_TELEPORT) + { + removeBlocksAboveTeleportPlatform(netherTeleportPlatform); + } + Location destination = new Location(netherTeleportPlatform.getWorld(), netherTeleportPlatform.getX(), netherTeleportPlatform.getY(), netherTeleportPlatform.getZ(), playerLocation.getYaw(), playerLocation.getPitch()); + destination.add(0.5, 1.5, 0.5); + player.teleport(destination); + if (ticketCheck == 2) + { + transferTicket(player, itemInHand); + } + if (netherFactoryProperties.getUseFuelOnTeleport()) + { + getFuel().removeFrom(getPowerSourceInventory()); + } + } + else if (clickedBlock.getWorld().getName().equalsIgnoreCase(FactoryModPlugin.NETHER_NAME)) + { + if (FactoryModPlugin.REMOVE_BLOCK_ABOVE_TELEPORT_PLATFORM_ON_TELEPORT) + { + removeBlocksAboveTeleportPlatform(overworldTeleportPlatform); + } + Location destination = new Location(overworldTeleportPlatform.getWorld(), overworldTeleportPlatform.getX(), overworldTeleportPlatform.getY(), overworldTeleportPlatform.getZ(), playerLocation.getYaw(), playerLocation.getPitch()); + destination.add(0.5, 1.5, 0.5); + player.teleport(destination); + if (ticketCheck == 2) + { + transferTicket(player, itemInHand); + } + if (netherFactoryProperties.getUseFuelOnTeleport()) + { + getFuel().removeFrom(getPowerSourceInventory()); + } + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, you must stand on the teleportation block!")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, factory is missing fuel! ("+getFuel().getMultiple(1).toString()+")")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, factory is turned off!")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Can't teleport, factory is not in teleport mode.")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "Your ticket does not match any in the factory.")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "You don't have permission to use this factory.")); + } + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "You don't have permission to use this factory.")); + } + } + return responses; + } + + @Override + public List getCentralBlockResponse() + { + List responses=new ArrayList(); + //Is the factory off + if (!active) + { + //is the recipe is initiated + if (mode == null) + { + mode = NetherOperationMode.REPAIR; + } + else + { + mode = mode.getNext(); + } + + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "-----------------------------------------------------")); + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "Switched mode to: " + mode.getDescription()+".")); + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "Next mode is: "+mode.getNext().getDescription()+".")); + } + else + { + responses.add(new InteractionResponse(InteractionResult.FAILURE, "You can't change modes while the nether factory is on! Turn it off first.")); + } + return responses; + } + + @Override + public ItemList getFuel() { + return netherFactoryProperties.getFuel(); + } + + /** + * Returns the factory's properties + */ + public NetherFactoryProperties getProperties() + { + return netherFactoryProperties; + } + + @Override + public List getChestResponse() + { + List responses=new ArrayList(); + String status=active ? "On" : "Off"; + //Name: Status with XX% health. + int maxRepair = netherFactoryProperties.getRepair(); + boolean maintenanceActive = maxRepair!=0; + int health =(!maintenanceActive) ? 100 : (int) Math.round(100*(1-currentRepair/(maxRepair))); + responses.add(new InteractionResponse(InteractionResult.SUCCESS, netherFactoryProperties.getName()+": "+status+" with "+String.valueOf(health)+"% health.")); + //Current mode: mode description + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "Current mode: " + mode.getDescription())); + //Overworld side teleport platform is at X: Y: Z: + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "Overworld side teleport platform is:" + overworldTeleportPlatform.getBlockX() + " Y:" + overworldTeleportPlatform.getBlockY() + " Z:" + overworldTeleportPlatform.getBlockZ())); + //Nether side teleport platform is at X: Y: Z: + responses.add(new InteractionResponse(InteractionResult.SUCCESS, "Nether side teleport platform is:" + netherTeleportPlatform.getBlockX() + " Y:" + netherTeleportPlatform.getBlockY() + " Z:" + netherTeleportPlatform.getBlockZ())); + //[Will repair XX% of the factory] + if(!getRepairs().isEmpty()&&maintenanceActive) + { + int amountAvailable=getRepairs().amountAvailable(getInventory()); + int amountRepaired=amountAvailable>currentRepair ? (int) Math.ceil(currentRepair) : amountAvailable; + int percentRepaired=(int) (( (double) amountRepaired)/netherFactoryProperties.getRepair()*100); + responses.add(new InteractionResponse(InteractionResult.SUCCESS,"Will repair "+String.valueOf(percentRepaired)+"% of the factory with "+getRepairs().getMultiple(amountRepaired).toString()+".")); + } + return responses; + } + + protected void recipeFinished() { + } + + @Override + public ItemList getInputs() { + if(mode == NetherOperationMode.REPAIR) + { + return new ItemList(); + } + else + { + return new ItemList(); + } + } + + @Override + public ItemList getOutputs() { + return new ItemList(); + } + + @Override + public ItemList getRepairs() { + ItemList repairMaterials = new ItemList(); + switch(mode) { + case REPAIR: + repairMaterials.addAll(netherFactoryProperties.getRepairMaterials()); + repairMaterials = repairMaterials.getMultiple(netherManager.getScalingFactor(factoryLocation)); + break; + default: + break; + } + return repairMaterials; + } + + @Override + public double getEnergyTime() { + return netherFactoryProperties.getEnergyTime(); + } + + @Override + public double getProductionTime() { + switch(mode) { + case REPAIR: + return netherFactoryProperties.getRepairTime(); + default: + return 1; + } + } + + @Override + public int getMaxRepair() { + return netherFactoryProperties.getRepair(); + } + + public Location getNetherTeleportPlatform() + { + return netherTeleportPlatform; + } + + + public Location getOverworldTeleportPlatform() + { + return overworldTeleportPlatform; + } + + @Override + public boolean isWhole(boolean initCall) + { + //Check if power source exists + if(factoryPowerSourceLocation.getBlock().getType().getId()== 61 || factoryPowerSourceLocation.getBlock().getType().getId()== 62) + { + //Check inventory location + if(factoryInventoryLocation.getBlock().getType().getId()== 54) + { + //Check Interaction block location + if(factoryLocation.getBlock().getType()==FactoryModPlugin.CENTRAL_BLOCK_MATERIAL) + { + if (netherTeleportPlatform == null && overworldTeleportPlatform == null && initCall) + { + return true; + } + else + { + if (netherTeleportPlatform.getBlock().getType() == FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL) + { + if (overworldTeleportPlatform.getBlock().getType() == FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL) + { + return true; + } + } + } + } + } + } + return false; + } + + public boolean isInTicketMode() + { + for (ItemStack itemSlot : getInventory().getContents()) + { + if (itemSlot != null && itemSlot.getType() == Material.PAPER) + { + return true; + } + } + return false; + } + + public int checkTicket(ItemStack ticket) + { + int amount = 0; + for(ItemStack itemStack: getInventory().getContents()) + { + if (itemStack == null) + { + continue; + } + if (itemStack.isSimilar(ticket)) + { + amount = amount+itemStack.getAmount(); + } + } + if (amount == 1) + { + return 1; + } + else if (amount >= 2) + { + return 2; + } + else + { + return 0; + } + } + + public void removeBlocksAboveTeleportPlatform(Location teleportPlatform) + { + Location netherLocation1 = teleportPlatform.clone(); + netherLocation1.add(0, 1, 0); + Location netherLocation2 = teleportPlatform.clone(); + netherLocation2.add(0, 2, 0); + Location netherLocation3 = teleportPlatform.clone(); + netherLocation3.add(0, 3, 0); + netherLocation1.getBlock().setType(Material.AIR); + netherLocation1.getBlock().getState().update(true); + netherLocation2.getBlock().setType(Material.AIR); + netherLocation2.getBlock().getState().update(true); + netherLocation3.getBlock().setType(Material.AIR); + netherLocation3.getBlock().getState().update(true); + } + + public void regenerateTeleportBlock(Location location) + { + if (location.equals(overworldTeleportPlatform)) + { + netherTeleportPlatform.getBlock().setType(FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL); + netherTeleportPlatform.getBlock().getState().update(true); + } + else if(location.equals(netherTeleportPlatform)) + { + overworldTeleportPlatform.getBlock().setType(FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL); + overworldTeleportPlatform.getBlock().getState().update(true); + } + + } + + public void transferTicket(Player player, ItemStack ticket) + { + ItemStack clonedTicket = ticket.clone(); + clonedTicket.setAmount(1); + ticket.setAmount(ticket.getAmount()-1); + player.setItemInHand(ticket); + getInventory().addItem(clonedTicket); + } + + public enum NetherOperationMode { + REPAIR(0, "Repair"), + TELEPORT(1, "Teleport"); + + private static final int MAX_ID = 2; + private int id; + private String description; + + private NetherOperationMode(int id, String description) { + this.id = id; + this.description = description; + } + + public String getDescription() { + return description; + } + + public static NetherOperationMode byId(int id) { + for (NetherOperationMode mode : NetherOperationMode.values()) { + if (mode.getId() == id) + return mode; + } + return null; + } + + public int getId() { + return id; + } + + public NetherOperationMode getNext() { + int nextId = (getId() + 1) % MAX_ID; + return NetherOperationMode.byId(nextId); + } + } +} \ No newline at end of file diff --git a/src/com/github/igotyou/FactoryMod/listeners/FactoryModListener.java b/src/com/github/igotyou/FactoryMod/listeners/FactoryModListener.java index 20d0b4e8..c46b8d7a 100644 --- a/src/com/github/igotyou/FactoryMod/listeners/FactoryModListener.java +++ b/src/com/github/igotyou/FactoryMod/listeners/FactoryModListener.java @@ -18,6 +18,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import com.github.igotyou.FactoryMod.FactoryModPlugin; +import com.github.igotyou.FactoryMod.Factorys.NetherFactory; import com.github.igotyou.FactoryMod.Factorys.PrintingPress; import com.github.igotyou.FactoryMod.Factorys.ProductionFactory; import com.github.igotyou.FactoryMod.interfaces.Factory; @@ -27,6 +28,7 @@ import com.github.igotyou.FactoryMod.utility.InteractionResponse; import com.github.igotyou.FactoryMod.utility.InteractionResponse.InteractionResult; import com.untamedears.citadel.entity.PlayerReinforcement; + import org.bukkit.event.entity.ExpBottleEvent; import org.bukkit.event.player.PlayerExpChangeEvent; @@ -247,6 +249,49 @@ else if (clicked.getType() == Material.CHEST) } } + else if (clicked.getType() == FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL) + { + if (factoryMan.factoryExistsAt(clicked.getLocation())) + { + if(factoryMan.getFactory(clicked.getLocation()).getClass() == NetherFactory.class) + { + NetherFactory netherFactory = (NetherFactory) factoryMan.getFactory(clicked.getLocation()); + if (FactoryModPlugin.REGENERATE_TELEPORT_BLOCK_ON_TELEPORT) + { + netherFactory.regenerateTeleportBlock(clicked.getLocation()); + } + if(factoryMan.factoryWholeAt(clicked.getLocation())) + { + //toggle the recipe, and print the returned message. + InteractionResponse.messagePlayerResults(player, netherFactory.getTeleportationBlockResponse(player, clicked.getLocation())); + e.setCancelled(true); + } + } + } + } + } + else if (player.getItemInHand().getType() == Material.PAPER) + { + if (clicked.getType() == FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL) + { + if (factoryMan.factoryExistsAt(clicked.getLocation())) + { + if(factoryMan.getFactory(clicked.getLocation()).getClass() == NetherFactory.class) + { + NetherFactory netherFactory = (NetherFactory) factoryMan.getFactory(clicked.getLocation()); + if (FactoryModPlugin.REGENERATE_TELEPORT_BLOCK_ON_TELEPORT) + { + netherFactory.regenerateTeleportBlock(clicked.getLocation()); + } + if(factoryMan.factoryWholeAt(clicked.getLocation())) + { + //toggle the recipe, and print the returned message. + InteractionResponse.messagePlayerResults(player, netherFactory.getTeleportationBlockResponse(player, clicked.getLocation())); + e.setCancelled(true); + } + } + } + } } } /* Section commented out since there exists range of bugs that circumvent diff --git a/src/com/github/igotyou/FactoryMod/listeners/NoteStackListener.java b/src/com/github/igotyou/FactoryMod/listeners/NoteStackListener.java index 86152bf1..16ba9d11 100644 --- a/src/com/github/igotyou/FactoryMod/listeners/NoteStackListener.java +++ b/src/com/github/igotyou/FactoryMod/listeners/NoteStackListener.java @@ -19,8 +19,6 @@ import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; -import sun.misc.Regexp; - import com.github.igotyou.FactoryMod.FactoryModPlugin; public class NoteStackListener implements Listener { diff --git a/src/com/github/igotyou/FactoryMod/managers/FactoryModManager.java b/src/com/github/igotyou/FactoryMod/managers/FactoryModManager.java index 2e327ece..ceff2ab7 100644 --- a/src/com/github/igotyou/FactoryMod/managers/FactoryModManager.java +++ b/src/com/github/igotyou/FactoryMod/managers/FactoryModManager.java @@ -64,6 +64,7 @@ private void initializeManagers() //if (FactoryModPlugin.PRODUCTION_ENEABLED) //{ initializeProductionManager(); + initializeNetherFactoryManager(); initializePrintingPressManager(); //} } @@ -88,6 +89,13 @@ private void initializePrintingPressManager() managers.add(printingMan); } + private void initializeNetherFactoryManager() + { + NetherFactoryManager netherMan = new NetherFactoryManager(plugin); + + managers.add(netherMan); + } + /** * When plugin disabled, this is called. */ diff --git a/src/com/github/igotyou/FactoryMod/managers/NetherFactoryManager.java b/src/com/github/igotyou/FactoryMod/managers/NetherFactoryManager.java new file mode 100644 index 00000000..dd4a3765 --- /dev/null +++ b/src/com/github/igotyou/FactoryMod/managers/NetherFactoryManager.java @@ -0,0 +1,407 @@ +package com.github.igotyou.FactoryMod.managers; + +import static com.untamedears.citadel.Utility.isReinforced; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.inventory.Inventory; + +import com.github.igotyou.FactoryMod.FactoryModPlugin; +import com.github.igotyou.FactoryMod.Factorys.NetherFactory; +import com.github.igotyou.FactoryMod.Factorys.NetherFactory.NetherOperationMode; +import com.github.igotyou.FactoryMod.interfaces.Factory; +import com.github.igotyou.FactoryMod.interfaces.Manager; +import com.github.igotyou.FactoryMod.properties.NetherFactoryProperties; +import com.github.igotyou.FactoryMod.utility.InteractionResponse; +import com.github.igotyou.FactoryMod.utility.InteractionResponse.InteractionResult; +import com.github.igotyou.FactoryMod.utility.ItemList; +import com.github.igotyou.FactoryMod.utility.NamedItemStack; + +import java.util.Iterator; + +//original file: +/** +* Manager.java +* Purpose: Interface for Manager objects for basic manager functionality +* +* @author MrTwiggy +* @version 0.1 1/08/13 +*/ +//edited version: +/** +* Manager.java +* Purpose: Interface for Manager objects for basic manager functionality +* @author igotyou +* +*/ + +public class NetherFactoryManager implements Manager +{ + private FactoryModPlugin plugin; + private List netherFactorys; + private long repairTime; + + public NetherFactoryManager(FactoryModPlugin plugin) + { + this.plugin = plugin; + netherFactorys = new ArrayList(); + //Set maintenance clock to 0 + updateFactorys(); + } + + public void save(File file) throws IOException + { + //Takes difference between last repair update and current one and scales repair accordingly + updateRepair(System.currentTimeMillis()-repairTime); + repairTime=System.currentTimeMillis(); + FileOutputStream fileOutputStream = new FileOutputStream(file); + ObjectOutputStream oos = new ObjectOutputStream(fileOutputStream); + int version = 1; + oos.writeInt(version); + oos.writeInt(netherFactorys.size()); + for (NetherFactory factory : netherFactorys) + { + Location centerlocation = factory.getCenterLocation(); + Location inventoryLocation = factory.getInventoryLocation(); + Location powerLocation = factory.getPowerSourceLocation(); + Location netherTeleportPlatformLocation = factory.getNetherTeleportPlatform(); + Location overworldTeleportPlatformLocation = factory.getOverworldTeleportPlatform(); + + oos.writeUTF(centerlocation.getWorld().getName()); + + oos.writeInt(centerlocation.getBlockX()); + oos.writeInt(centerlocation.getBlockY()); + oos.writeInt(centerlocation.getBlockZ()); + + oos.writeInt(inventoryLocation.getBlockX()); + oos.writeInt(inventoryLocation.getBlockY()); + oos.writeInt(inventoryLocation.getBlockZ()); + + oos.writeInt(powerLocation.getBlockX()); + oos.writeInt(powerLocation.getBlockY()); + oos.writeInt(powerLocation.getBlockZ()); + + oos.writeInt(overworldTeleportPlatformLocation.getBlockX()); + oos.writeInt(overworldTeleportPlatformLocation.getBlockY()); + oos.writeInt(overworldTeleportPlatformLocation.getBlockZ()); + + oos.writeUTF(netherTeleportPlatformLocation.getWorld().getName()); + oos.writeInt(netherTeleportPlatformLocation.getBlockX()); + oos.writeInt(netherTeleportPlatformLocation.getBlockY()); + oos.writeInt(netherTeleportPlatformLocation.getBlockZ()); + + oos.writeBoolean(factory.getActive()); + oos.writeInt(factory.getMode().getId()); + oos.writeDouble(factory.getCurrentRepair()); + oos.writeLong(factory.getTimeDisrepair()); + + } + oos.flush(); + fileOutputStream.close(); + } + + public void load(File file) throws IOException + { + try { + repairTime=System.currentTimeMillis(); + FileInputStream fileInputStream = new FileInputStream(file); + ObjectInputStream ois = new ObjectInputStream(fileInputStream); + int version = ois.readInt(); + assert(version == 1); + int count = ois.readInt(); + int i = 0; + for (i = 0; i < count; i++) + { + String worldName = ois.readUTF(); + World world = plugin.getServer().getWorld(worldName); + + Location centerLocation = new Location(world, ois.readInt(), ois.readInt(), ois.readInt()); + Location inventoryLocation = new Location(world, ois.readInt(), ois.readInt(), ois.readInt()); + Location powerLocation = new Location(world, ois.readInt(), ois.readInt(), ois.readInt()); + Location overworldTeleportPlatformLocation = new Location(world, ois.readInt(), ois.readInt(), ois.readInt()); + + String worldName2 = ois.readUTF(); + World world2 = plugin.getServer().getWorld(worldName2); + + Location netherTeleportPlatformLocation = new Location(world2, ois.readInt(), ois.readInt(), ois.readInt()); + + boolean active = ois.readBoolean(); + NetherOperationMode mode = NetherFactory.NetherOperationMode.byId(ois.readInt()); + double currentRepair = ois.readDouble(); + long timeDisrepair = ois.readLong(); + + NetherFactory factory = new NetherFactory(centerLocation, inventoryLocation, powerLocation, netherTeleportPlatformLocation, overworldTeleportPlatformLocation, + active, currentRepair, timeDisrepair, + mode, + plugin.getNetherFactoryProperties(), this); + addFactory(factory); + } + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void updateFactorys() + { + plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() + { + @Override + public void run() + { + for (NetherFactory factory: netherFactorys) + { + factory.update(); + } + } + }, 0L, FactoryModPlugin.PRODUCER_UPDATE_CYCLE); + } + + public InteractionResponse createFactory(Location factoryLocation, Location inventoryLocation, Location powerSourceLocation) + { + NetherFactoryProperties netherFactoryProperties = plugin.getNetherFactoryProperties(); + Block inventoryBlock = inventoryLocation.getBlock(); + Chest chest = (Chest) inventoryBlock.getState(); + Inventory chestInventory = chest.getInventory(); + ItemList constructionMaterials = netherFactoryProperties.getConstructionMaterials(); + if(constructionMaterials.oneIn(chestInventory)) + { + if (factoryLocation.getWorld().getName().equalsIgnoreCase(FactoryModPlugin.WORLD_NAME)) + { + if (factoryLocation.getBlock().getType().equals(FactoryModPlugin.CENTRAL_BLOCK_MATERIAL)) + { + if (!factoryExistsAt(factoryLocation)) + { + double scalingFactor = getScalingFactor(factoryLocation); + if (scalingFactor < 10000) + { + constructionMaterials = constructionMaterials.getMultiple(scalingFactor); + boolean hasMaterials = constructionMaterials.allIn(chestInventory); + if (hasMaterials) + { + boolean markerFound = false; + Location markerLocation = factoryLocation.clone(); + int blockY = markerLocation.getBlockY(); + for (int centerY = blockY-plugin.NETHER_MARKER_MAX_DISTANCE; centerY <= blockY+plugin.NETHER_MARKER_MAX_DISTANCE && !markerFound; centerY++) + { + markerLocation.setY(centerY); + Location oneUp = markerLocation.clone(); + oneUp.setY(centerY+1); + if (markerLocation.getBlock().getType() == FactoryModPlugin.NETHER_FACTORY_MARKER_MATERIAL && oneUp.getBlock().getType() == FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL) + { + markerFound = true; + } + } + if (markerFound) + { + int nether_scale = FactoryModPlugin.NETHER_SCALE; + boolean locationOk = false; + int startX = Math.round(factoryLocation.getBlockX()/nether_scale); + int startY = factoryLocation.getBlockY(); + int startZ = Math.round(factoryLocation.getBlockZ()/nether_scale); + Location netherLocation = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), startX,startY,startZ); + Location netherLocation1 = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), startX,startY+1,startZ); + Location netherLocation2 = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), startX,startY+2,startZ); + Location netherLocation3 = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), startX,startY+3,startZ); + if (FactoryModPlugin.CITADEL_ENABLED && (isReinforced(netherLocation) || isReinforced(netherLocation1) || isReinforced(netherLocation2) || isReinforced(netherLocation3))) + { + for(int scanX = startX-1; scanX <= startX+1 && !locationOk; scanX++) + { + + for(int scanZ = startZ-1; scanZ <= startZ+1 && !locationOk; scanZ++) + { + for(int scanY = startY; scanY <= 250 && !locationOk; scanY++) + { + netherLocation = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), scanX,scanY,scanZ); + netherLocation1 = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), scanX,scanY+1,scanZ); + netherLocation2 = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), scanX,scanY+2,scanZ); + netherLocation3 = new Location(Bukkit.getWorld(FactoryModPlugin.NETHER_NAME), scanX,scanY+3,scanZ); + if(!isReinforced(netherLocation) && !isReinforced(netherLocation1) && !isReinforced(netherLocation2) && !isReinforced(netherLocation3)) + { + locationOk = true; + + } + } + } + } + } + if (!factoryExistsAt(netherLocation)) + { + netherLocation.getBlock().setType(FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL); + netherLocation.getBlock().getState().update(true); + netherLocation1.getBlock().setType(Material.AIR); + netherLocation1.getBlock().getState().update(true); + netherLocation2.getBlock().setType(Material.AIR); + netherLocation2.getBlock().getState().update(true); + netherLocation3.getBlock().setType(Material.AIR); + netherLocation3.getBlock().getState().update(true); + if(netherLocation.getBlock().getType() != (FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL) && + netherLocation1.getBlock().getType() != Material.AIR && + netherLocation2.getBlock().getType() != Material.AIR && + netherLocation3.getBlock().getType() != Material.AIR) + { + return new InteractionResponse(InteractionResult.FAILURE, "For some reason the nether side obsidian block did not generate...blame bukkit"); + } + Location oneUp = markerLocation.clone(); + oneUp.add(0,1,0); + NetherFactory netherFactory = new NetherFactory(factoryLocation, inventoryLocation, powerSourceLocation, netherLocation, oneUp, plugin.getNetherFactoryProperties(), this); + if (constructionMaterials.removeFrom(netherFactory.getInventory())) + { + addFactory(netherFactory); + return new InteractionResponse(InteractionResult.SUCCESS, "Successfully created " + netherFactoryProperties.getName()); + } + } + else + { + return new InteractionResponse(InteractionResult.FAILURE, "There is a other " + netherFactoryProperties.getName() + " too close."); + } + } + else + { + return new InteractionResponse(InteractionResult.FAILURE, "No marker found. Place a " + FactoryModPlugin.NETHER_FACTORY_MARKER_MATERIAL + " 1-20 blocks above the center block of the nether factory with a " + FactoryModPlugin.NETHER_FACTORY_TELEPORT_PLATFORM_MATERIAL + " right above."); + } + } + return new InteractionResponse(InteractionResult.FAILURE, "Not enough materials in chest! You need " + constructionMaterials.toString()); + } + else + { + return new InteractionResponse(InteractionResult.FAILURE, "Factory is too close to a other nether factory!"); + } + } + return new InteractionResponse(InteractionResult.FAILURE, "There is already a " + netherFactoryProperties.getName() + " there!"); + } + else + { + return new InteractionResponse(InteractionResult.FAILURE, "Wrong center block!"); + } + } + else + { + return new InteractionResponse(InteractionResult.FAILURE, netherFactoryProperties.getName() + "'s can only be built in the overworld"); + } + } + return new InteractionResponse(InteractionResult.FAILURE, "No factory was identified!"); + } + + public InteractionResponse addFactory(Factory factory) + { + NetherFactory netherFactory = (NetherFactory) factory; + if (netherFactory.getCenterLocation().getBlock().getType().equals(FactoryModPlugin.CENTRAL_BLOCK_MATERIAL) && + (!factoryExistsAt(netherFactory.getCenterLocation()) + || !factoryExistsAt(netherFactory.getInventoryLocation()) + || !factoryExistsAt(netherFactory.getPowerSourceLocation()) + || !factoryExistsAt(netherFactory.getNetherTeleportPlatform()) + || !factoryExistsAt(netherFactory.getOverworldTeleportPlatform()) )) + { + netherFactorys.add(netherFactory); + return new InteractionResponse(InteractionResult.SUCCESS, ""); + } + else + { + return new InteractionResponse(InteractionResult.FAILURE, ""); + } + } + + public NetherFactory getFactory(Location factoryLocation) + { + for (NetherFactory factory : netherFactorys) + { + if (factory.getCenterLocation().equals(factoryLocation) + || factory.getInventoryLocation().equals(factoryLocation) + || factory.getPowerSourceLocation().equals(factoryLocation) + || factory.getNetherTeleportPlatform().equals(factoryLocation) + || factory.getOverworldTeleportPlatform().equals(factoryLocation)) + return factory; + } + return null; + } + + public boolean factoryExistsAt(Location factoryLocation) + { + boolean returnValue = false; + if (getFactory(factoryLocation) != null) + { + returnValue = true; + } + return returnValue; + } + + public boolean factoryWholeAt(Location factoryLocation) + { + boolean returnValue = false; + if (getFactory(factoryLocation) != null) + { + returnValue = getFactory(factoryLocation).isWhole(false); + } + return returnValue; + } + + public void removeFactory(Factory factory) + { + netherFactorys.remove((NetherFactory)factory); + } + + public void updateRepair(long time) + { + for (NetherFactory factory: netherFactorys) + { + factory.updateRepair(time/((double)FactoryModPlugin.REPAIR_PERIOD)); + } + long currentTime=System.currentTimeMillis(); + Iterator itr=netherFactorys.iterator(); + while(itr.hasNext()) + { + NetherFactory factory=itr.next(); + if(currentTime>(factory.getTimeDisrepair()+FactoryModPlugin.DISREPAIR_PERIOD)) + { + itr.remove(); + } + } + } + + public String getSavesFileName() + { + return FactoryModPlugin.NETHER_FACTORY_SAVE_FILE; + } + + public double getScalingFactor(Location location) + { + double scalingFactor = 1; + NetherFactoryProperties properties = plugin.getNetherFactoryProperties(); + for (NetherFactory factory : netherFactorys) + { + Location factoryLoc = factory.getCenterLocation(); + if(factory.getCenterLocation().equals(location)) + { + continue; + } + //the distance function uses square root, which is quite expensive, let's check if it's even realistic that it's within range first. + if ((location.getBlockX()-factoryLoc.getBlockX()) < properties.getScalingRadius() || (location.getBlockX()-factoryLoc.getBlockX()) > -(properties.getScalingRadius())) + { + if ((location.getBlockZ()-factoryLoc.getBlockZ()) < properties.getScalingRadius() || (location.getBlockZ()-factoryLoc.getBlockZ()) > -(properties.getScalingRadius())) + { + double distance = location.distance(factoryLoc); + if (distance <= properties.getScalingRadius()) + { + scalingFactor = scalingFactor * Math.exp(1/(distance/properties.getCostScalingRadius())); + } + } + } + } + return scalingFactor; + } + +} \ No newline at end of file diff --git a/src/com/github/igotyou/FactoryMod/managers/PrintingPressManager.java b/src/com/github/igotyou/FactoryMod/managers/PrintingPressManager.java index a9b99d7d..464cdfaa 100644 --- a/src/com/github/igotyou/FactoryMod/managers/PrintingPressManager.java +++ b/src/com/github/igotyou/FactoryMod/managers/PrintingPressManager.java @@ -254,7 +254,7 @@ public boolean factoryWholeAt(Location factoryLocation) boolean returnValue = false; if (getFactory(factoryLocation) != null) { - returnValue = getFactory(factoryLocation).isWhole(); + returnValue = getFactory(factoryLocation).isWhole(false); } return returnValue; } diff --git a/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java b/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java index 05a7e5a8..0085443f 100644 --- a/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java +++ b/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java @@ -302,7 +302,7 @@ public boolean factoryWholeAt(Location factoryLocation) boolean returnValue = false; if (getFactory(factoryLocation) != null) { - returnValue = getFactory(factoryLocation).isWhole(); + returnValue = getFactory(factoryLocation).isWhole(false); } return returnValue; } diff --git a/src/com/github/igotyou/FactoryMod/properties/NetherFactoryProperties.java b/src/com/github/igotyou/FactoryMod/properties/NetherFactoryProperties.java new file mode 100644 index 00000000..b5378da8 --- /dev/null +++ b/src/com/github/igotyou/FactoryMod/properties/NetherFactoryProperties.java @@ -0,0 +1,119 @@ +package com.github.igotyou.FactoryMod.properties; + + +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; + +import com.github.igotyou.FactoryMod.FactoryModPlugin; +import com.github.igotyou.FactoryMod.utility.ItemList; +import com.github.igotyou.FactoryMod.utility.NamedItemStack; + + +public class NetherFactoryProperties +{ + private ItemList constructionMaterials; + private ItemList fuel; + private ItemList repairMaterials; + private int energyTime; + private String name; + private int repair; + private double repairTime; + private int scalingMode; + private int scalingRadius; + private int costScalingRadius; + private boolean useFuelOnTeleport; + + public NetherFactoryProperties(ItemList constructionMaterials, ItemList fuel, ItemList repairMaterials, + int energyTime, String name,int repair, double repairTime, int scalingRadius, boolean useFuelOnTeleport, int costScalingRadius) + { + this.constructionMaterials = constructionMaterials; + this.fuel = fuel; + this.repairMaterials = repairMaterials; + this.energyTime = energyTime; + this.name = name; + this.repair=repair; + this.repairTime=repairTime; + this.scalingRadius = scalingRadius; + this.costScalingRadius = costScalingRadius; + this.useFuelOnTeleport = useFuelOnTeleport; + } + + public int getRepair() + { + return repair; + } + + public int getScalingRadius() + { + return scalingRadius; + } + + public int getCostScalingRadius() + { + return costScalingRadius; + } + + //0 == no scaling, 1==linear scaling, 2==exponential scaling + public int getScalingMode() + { + return scalingMode; + } + + public ItemList getConstructionMaterials() + { + return constructionMaterials; + } + + public ItemList getFuel() + { + return fuel; + } + + public ItemList getRepairMaterials() + { + return repairMaterials; + } + + public int getEnergyTime() + { + return energyTime; + } + + public String getName() + { + return name; + } + + public static NetherFactoryProperties fromConfig(FactoryModPlugin plugin, ConfigurationSection configNetherFactory) + { + ItemList nfFuel=plugin.getItems(configNetherFactory.getConfigurationSection("fuel")); + if(nfFuel.isEmpty()) + { + nfFuel=new ItemList(); + nfFuel.add(new NamedItemStack(Material.getMaterial("COAL"),1,(short)1,"Charcoal")); + } + ConfigurationSection costs = configNetherFactory.getConfigurationSection("costs"); + ItemList nfConstructionCost=plugin.getItems(costs.getConfigurationSection("construction")); + ItemList nfRepairCost=plugin.getItems(costs.getConfigurationSection("repair")); + int nfEnergyTime = configNetherFactory.getInt("fuel_time", 10); + int nfRepair = costs.getInt("repair_multiple",1); + String nfName = configNetherFactory.getString("name", "Nether Factory"); + int repairTime = configNetherFactory.getInt("repair_time",12); + int nfScalingRadius = configNetherFactory.getInt("scaling_radius", 5000); + int costScalingRadius = configNetherFactory.getInt("scaling_radius", 5000); + boolean nfUseFuelOnTeleport = configNetherFactory.getBoolean("use_fuel_on_teleport", false); + return new NetherFactoryProperties(nfConstructionCost, nfFuel, nfRepairCost, nfEnergyTime, nfName, nfRepair, repairTime, nfScalingRadius,nfUseFuelOnTeleport, costScalingRadius); + + } + + public double getRepairTime() + { + return repairTime; + } + + public boolean getUseFuelOnTeleport() + { + return useFuelOnTeleport; + } + +} \ No newline at end of file diff --git a/src/com/github/igotyou/FactoryMod/utility/ItemList.java b/src/com/github/igotyou/FactoryMod/utility/ItemList.java index a9dc723f..68807640 100644 --- a/src/com/github/igotyou/FactoryMod/utility/ItemList.java +++ b/src/com/github/igotyou/FactoryMod/utility/ItemList.java @@ -281,4 +281,25 @@ public ItemList getMultiple(int multiplier) } return multipliedItemList; } + public ItemList getMultiple(double multiplier) + { + ItemList multipliedItemList=new ItemList(); + for (NamedItemStack itemStack:this) + { + NamedItemStack itemStackClone=itemStack.clone(); + long newAmount = (long) Math.round(itemStackClone.getAmount()*multiplier); + if (newAmount > 64) + { + for (;newAmount > 64; newAmount = newAmount-64) + { + NamedItemStack newItemStack = itemStack.clone(); + newItemStack.setAmount(64); + multipliedItemList.add(newItemStack); + } + } + itemStackClone.setAmount((int) newAmount); + multipliedItemList.add(itemStackClone); + } + return multipliedItemList; + } }