diff --git a/resources/assets/enderio/textures/blocks/poweredSpawnerFront.png b/resources/assets/enderio/textures/blocks/poweredSpawnerFront.png new file mode 100644 index 00000000..146c1fc9 Binary files /dev/null and b/resources/assets/enderio/textures/blocks/poweredSpawnerFront.png differ diff --git a/resources/assets/enderio/textures/blocks/poweredSpawnerFrontActive.png b/resources/assets/enderio/textures/blocks/poweredSpawnerFrontActive.png new file mode 100644 index 00000000..358d32f1 Binary files /dev/null and b/resources/assets/enderio/textures/blocks/poweredSpawnerFrontActive.png differ diff --git a/src/main/java/crazypants/enderio/Config.java b/src/main/java/crazypants/enderio/Config.java index fda14ccc..d2992aae 100644 --- a/src/main/java/crazypants/enderio/Config.java +++ b/src/main/java/crazypants/enderio/Config.java @@ -34,7 +34,7 @@ public final class Config { public static File configDirectory; public static boolean useHardRecipes = false; - + public static boolean useSteelInChassi = false; public static boolean detailedPowerTrackingEnabled = false; @@ -105,7 +105,7 @@ public final class Config { public static int darkSteelPickEffeciencyObsidian = 50; public static int darkSteelPickPowerUsePerDamagePoint = 750; public static float darkSteelPickEffeciencyBoostWhenPowered = 2; - + public static int darkSteelAxePowerUsePerDamagePoint = 750; public static int darkSteelAxePowerUsePerDamagePointMultiHarvest = 1500; public static float darkSteelAxeEffeciencyBoostWhenPowered = 2; @@ -118,14 +118,13 @@ public final class Config { public static int fireWaterPowerPerCycle = 8; public static int fireWaterPowerTotalBurnTime = 15000; public static float vatPowerUserPerTick = 2; - + public static double maxPhotovoltaicOutput = 1.0; public static double maxPhotovoltaicAdvancedOutput = 4.0; - + public static double zombieGeneratorMjPerTick = 8.0; public static int zombieGeneratorTicksPerBucketFuel = 10000; - public static boolean combustionGeneratorUseOpaqueModel = true; public static boolean addFuelTooltipsToAllFluidContainers = true; @@ -140,18 +139,26 @@ public final class Config { public static float farmContinuousEnergyUse = 4; public static float farmActionEnergyUse = 50; public static int farmDefaultSize = 3; - + public static int magnetPowerUsePerSecondRF = 1; public static int magnetPowerCapacityRF = 100000; public static int magnetRange = 5; - + public static boolean useCombustionGenModel = false; - + public static int crafterMjPerCraft = 250; - + public static int capacitorBankMaxIoMJ = 100; public static int capacitorBankMaxStorageMJ = 500000; + public static int poweredSpawnerMinDelayTicks = 200; + public static int poweredSpawnerMaxDelayTicks = 800; + public static float poweredSpawnerLevelOnePowerPerTick = 4; + public static float poweredSpawnerLevelTwoPowerPerTick = 16; + public static float poweredSpawnerLevelThreePowerPerTick = 64; + public static int poweredSpawnerMaxPlayerDistance = 0; + public static boolean poweredSpawnerUseVanillaSpawChecks = false; + public static void load(FMLPreInitializationEvent event) { configDirectory = new File(event.getModConfigurationDirectory(), "enderio"); if(!configDirectory.exists()) { @@ -175,17 +182,18 @@ public final class Config { public static void processConfig(Configuration config) { useRfAsDefault = config.get("Power Settings", "displayPowerAsRedstoneFlux", useRfAsDefault, "If true, all power is displayed in RF, otherwise MJ is used.") .getBoolean(useRfAsDefault); - + capacitorBankMaxIoMJ = config.get("Power Settings", "capacitorBankMaxIoMJ", capacitorBankMaxIoMJ, "The maximum IO for a single capacitor in MJ/t") .getInt(capacitorBankMaxIoMJ); - capacitorBankMaxStorageMJ = config.get("Power Settings", "capacitorBankMaxStorageMJ", capacitorBankMaxStorageMJ, "The maximum storage for a single capacitor in MJ") + capacitorBankMaxStorageMJ = config.get("Power Settings", "capacitorBankMaxStorageMJ", capacitorBankMaxStorageMJ, + "The maximum storage for a single capacitor in MJ") .getInt(capacitorBankMaxStorageMJ); useHardRecipes = config.get("Recipe Settings", "useHardRecipes", useHardRecipes, "When enabled machines cost significantly more.") .getBoolean(useHardRecipes); - + useSteelInChassi = config.get("Recipe Settings", "useSteelInChassi", useSteelInChassi, "When enabled machine chassis will require steel instead of iron.") - .getBoolean(useSteelInChassi); + .getBoolean(useSteelInChassi); numConduitsPerRecipe = config.get("Recipe Settings", "numConduitsPerRecipe", numConduitsPerRecipe, "The number of conduits crafted per recipe.").getInt(numConduitsPerRecipe); @@ -196,7 +204,7 @@ public final class Config { maxPhotovoltaicOutput = config.get("Power Settings", "maxPhotovoltaicOutput", maxPhotovoltaicOutput, "Maximum output in MJ/t of the Photovoltaic Panels.").getDouble(maxPhotovoltaicOutput); - maxPhotovoltaicAdvancedOutput= config.get("Power Settings", "maxPhotovoltaicAdvancedOutput", maxPhotovoltaicAdvancedOutput, + maxPhotovoltaicAdvancedOutput = config.get("Power Settings", "maxPhotovoltaicAdvancedOutput", maxPhotovoltaicAdvancedOutput, "Maximum output in MJ/t of the Advanced Photovoltaic Panels.").getDouble(maxPhotovoltaicAdvancedOutput); useAlternateBinderRecipe = config.get("Recipe Settings", "useAlternateBinderRecipe", false, "Create conduit binder in crafting table instead of furnace") @@ -221,12 +229,10 @@ public final class Config { enderFluidConduitExtractRate = config.get("Efficiency Settings", "enderFluidConduitExtractRate", enderFluidConduitExtractRate, "Number of millibuckects per tick extracted by ender fluid conduits auto extracting").getInt(enderFluidConduitExtractRate); - + enderFluidConduitMaxIoRate = config.get("Efficiency Settings", "enderFluidConduitMaxIoRate", enderFluidConduitMaxIoRate, "Number of millibuckects per tick that can pass through a single connection to an ender fluid conduit.").getInt(enderFluidConduitMaxIoRate); - - useAlternateTesseractModel = config.get("Aesthetic Settings", "useAlternateTransceiverModel", useAlternateTesseractModel, "Use TheKazador's alternatice model for the Dimensional Transceiver") .getBoolean(false); @@ -288,7 +294,8 @@ public final class Config { "If set to false: the travel staff will not be craftable.").getBoolean(travelStaffEnabled); travelStaffBlinkEnabled = config.get("Item Enabling", "travelStaffBlinkEnabled", travelStaffBlinkEnabled, "If set to false: the travel staff can not be used to shift-right click teleport, or blink.").getBoolean(travelStaffBlinkEnabled); - travelStaffBlinkThroughSolidBlocksEnabled = config.get("Item Enabling", "travelStaffBlinkThroughSolidBlocksEnabled", travelStaffBlinkThroughSolidBlocksEnabled, + travelStaffBlinkThroughSolidBlocksEnabled = config.get("Item Enabling", "travelStaffBlinkThroughSolidBlocksEnabled", + travelStaffBlinkThroughSolidBlocksEnabled, "If set to false: the travel staff can be used to blink through any block.").getBoolean(travelStaffBlinkThroughSolidBlocksEnabled); travelStaffBlinkThroughClearBlocksEnabled = config .get("Item Enabling", "travelStaffBlinkThroughClearBlocksEnabled", travelStaffBlinkThroughClearBlocksEnabled, @@ -357,7 +364,8 @@ public final class Config { "Base amount of power used per jump (RF) dark steel boots. The second jump in a 'double jump' uses 2x this etc").getInt(darkSteelBootsJumpPowerCost); darkSteelSwordSkullChance = (float) config.get("Dark Steel", "darkSteelSwordSkullChance", darkSteelSwordSkullChance, - "The base chance that a skull will be dropped when using a powered dark steel sword (0 = no chance, 1 = 100% chance)").getDouble(darkSteelSwordSkullChance); + "The base chance that a skull will be dropped when using a powered dark steel sword (0 = no chance, 1 = 100% chance)").getDouble( + darkSteelSwordSkullChance); darkSteelSwordSkullLootingModifier = (float) config.get("Dark Steel", "darkSteelSwordSkullLootingModifier", darkSteelSwordSkullLootingModifier, "The chance per looting level that a skull will be dropped when using a powered dark steel sword (0 = no chance, 1 = 100% chance)").getDouble( darkSteelSwordSkullLootingModifier); @@ -390,10 +398,11 @@ public final class Config { "Power use (RF) per damage/durability point avoided.").getInt(darkSteelPickPowerUsePerDamagePoint); darkSteelPickEffeciencyBoostWhenPowered = (float) config.get("Dark Steel", "darkSteelPickEffeciencyBoostWhenPowered", darkSteelPickEffeciencyBoostWhenPowered, "The increase in effciency when powered.").getDouble(darkSteelPickEffeciencyBoostWhenPowered); - + darkSteelAxePowerUsePerDamagePoint = config.get("Dark Steel", "darkSteelAxePowerUsePerDamagePoint", darkSteelAxePowerUsePerDamagePoint, "Power use (RF) per damage/durability point avoided.").getInt(darkSteelAxePowerUsePerDamagePoint); - darkSteelAxePowerUsePerDamagePointMultiHarvest = config.get("Dark Steel", "darkSteelPickAxeUsePerDamagePointMultiHarvest", darkSteelAxePowerUsePerDamagePointMultiHarvest, + darkSteelAxePowerUsePerDamagePointMultiHarvest = config.get("Dark Steel", "darkSteelPickAxeUsePerDamagePointMultiHarvest", + darkSteelAxePowerUsePerDamagePointMultiHarvest, "Power use (RF) per damage/durability point avoided when shift-harvesting multiple logs").getInt(darkSteelAxePowerUsePerDamagePointMultiHarvest); darkSteelAxeSpeedPenaltyMultiHarvest = (float) config.get("Dark Steel", "darkSteelAxeSpeedPenaltyMultiHarvest", darkSteelAxeSpeedPenaltyMultiHarvest, "How much slower shift-harvesting logs is.").getDouble(darkSteelAxeSpeedPenaltyMultiHarvest); @@ -419,39 +428,54 @@ public final class Config { "The amount of power generated per tick.").getDouble(zombieGeneratorMjPerTick); zombieGeneratorTicksPerBucketFuel = config.get("Power Settings", "zombieGeneratorTicksPerMbFuel", zombieGeneratorTicksPerBucketFuel, "The number of ticks one bucket of fuel lasts.").getInt(zombieGeneratorTicksPerBucketFuel); - + addFuelTooltipsToAllFluidContainers = config.get("Personal Settings", "addFuelTooltipsToAllFluidContainers", addFuelTooltipsToAllFluidContainers, "If true, the MJ/t and burn time of the fuel will be displayed in all tooltips for fluid containers with fuel.").getBoolean( - addFuelTooltipsToAllFluidContainers); + addFuelTooltipsToAllFluidContainers); addDurabilityTootip = config.get("Personal Settings", "addDurabilityTootip", addFuelTooltipsToAllFluidContainers, "If true, adds durability tooltips to tools and armor").getBoolean( - addDurabilityTootip); + addDurabilityTootip); addFurnaceFuelTootip = config.get("Personal Settings", "addFurnaceFuelTootip", addFuelTooltipsToAllFluidContainers, "If true, adds burn duration tooltips to furnace fuels").getBoolean(addFurnaceFuelTootip); - - farmContinuousEnergyUse = (float)config.get("Farm Settings", "farmContinuousEnergyUse", farmContinuousEnergyUse, + farmContinuousEnergyUse = (float) config.get("Farm Settings", "farmContinuousEnergyUse", farmContinuousEnergyUse, "The amount of power used by a farm per tick ").getDouble(farmContinuousEnergyUse); - farmActionEnergyUse = (float)config.get("Farm Settings", "farmActionEnergyUse", farmActionEnergyUse, + farmActionEnergyUse = (float) config.get("Farm Settings", "farmActionEnergyUse", farmActionEnergyUse, "The amount of power used by a farm per action (eg plant, till, harvest) ").getDouble(farmActionEnergyUse); farmDefaultSize = config.get("Farm Settings", "farmDefaultSize", farmDefaultSize, "The number of blocks a farm will extend from its center").getInt(farmDefaultSize); - + combustionGeneratorUseOpaqueModel = config.get("Aesthetic Settings", "combustionGeneratorUseOpaqueModel", combustionGeneratorUseOpaqueModel, - "If set to true: fluid will not be shown in combustion generator tanks. Improves FPS. ").getBoolean(combustionGeneratorUseOpaqueModel); - + "If set to true: fluid will not be shown in combustion generator tanks. Improves FPS. ").getBoolean(combustionGeneratorUseOpaqueModel); + magnetPowerUsePerSecondRF = config.get("Magnet Settings", "magnetPowerUsePerTickRF", magnetPowerUsePerSecondRF, - "The amount of RF power used per tick when the magnet is active").getInt(magnetPowerUsePerSecondRF); + "The amount of RF power used per tick when the magnet is active").getInt(magnetPowerUsePerSecondRF); magnetPowerCapacityRF = config.get("Magnet Settings", "magnetPowerCapacityRF", magnetPowerCapacityRF, - "Amount of RF power stored in a fully charged magnet").getInt(magnetPowerCapacityRF); + "Amount of RF power stored in a fully charged magnet").getInt(magnetPowerCapacityRF); magnetRange = config.get("Magnet Settings", "magnetRange", magnetRange, "Range of the magnet in blocks.").getInt(magnetRange); - + useCombustionGenModel = config.get("Aesthetic Settings", "useCombustionGenModel", useCombustionGenModel, "If set to true: WIP Combustion Generator model will be used").getBoolean(useCombustionGenModel); - - crafterMjPerCraft= config.get("AutoCrafter Settings", "crafterMjPerCraft", crafterMjPerCraft, + + crafterMjPerCraft = config.get("AutoCrafter Settings", "crafterMjPerCraft", crafterMjPerCraft, "MJ used per autocrafted recipe").getInt(crafterMjPerCraft); + + poweredSpawnerMinDelayTicks = config.get("PoweredSpawner Settings", "poweredSpawnerMinDelayTicks", poweredSpawnerMinDelayTicks, + "Min tick delay between spawns for a non-upgraded spawner").getInt(poweredSpawnerMinDelayTicks); + poweredSpawnerMaxDelayTicks = config.get("PoweredSpawner Settings", "poweredSpawnerMaxDelayTicks", poweredSpawnerMaxDelayTicks, + "Min tick delay between spawns for a non-upgraded spawner").getInt(poweredSpawnerMaxDelayTicks); + poweredSpawnerLevelOnePowerPerTick = (float)config.get("PoweredSpawner Settings", "poweredSpawnerLevelOnePowerPerTick", poweredSpawnerLevelOnePowerPerTick, + "MJ per tick for a level 1 (non-upgraded) spawner").getDouble(poweredSpawnerLevelOnePowerPerTick); + poweredSpawnerLevelTwoPowerPerTick = (float)config.get("PoweredSpawner Settings", "poweredSpawnerLevelTwoPowerPerTick", poweredSpawnerLevelTwoPowerPerTick, + "MJ per tick for a level 2 spawner").getDouble(poweredSpawnerLevelTwoPowerPerTick); + poweredSpawnerLevelThreePowerPerTick = (float)config.get("PoweredSpawner Settings", "poweredSpawnerLevelThreePowerPerTick", poweredSpawnerLevelThreePowerPerTick, + "MJ per tick for a level 3 spawner").getDouble(poweredSpawnerLevelThreePowerPerTick); + poweredSpawnerMaxPlayerDistance = config.get("PoweredSpawner Settings", "poweredSpawnerMaxPlayerDistance", poweredSpawnerMaxPlayerDistance, + "Max distance of the closest player for the spawner to be active. A zero value will remove the player check").getInt(poweredSpawnerMaxPlayerDistance); + poweredSpawnerUseVanillaSpawChecks = config.get("PoweredSpawner Settings", "poweredSpawnerUseVanillaSpawChecks", poweredSpawnerUseVanillaSpawChecks, + "If true, regular spawn checks such as lighting level and dimension will be made before spawning mobs").getBoolean(poweredSpawnerUseVanillaSpawChecks); + } private Config() { diff --git a/src/main/java/crazypants/enderio/EnderIO.java b/src/main/java/crazypants/enderio/EnderIO.java index db8ab01f..dbbff232 100644 --- a/src/main/java/crazypants/enderio/EnderIO.java +++ b/src/main/java/crazypants/enderio/EnderIO.java @@ -78,6 +78,7 @@ import crazypants.enderio.machine.painter.BlockPainter; import crazypants.enderio.machine.power.BlockCapacitorBank; import crazypants.enderio.machine.reservoir.BlockReservoir; import crazypants.enderio.machine.solar.BlockSolarPanel; +import crazypants.enderio.machine.spawner.BlockPoweredSpawner; import crazypants.enderio.machine.still.BlockVat; import crazypants.enderio.machine.still.VatRecipeManager; import crazypants.enderio.machine.tank.BlockTank; @@ -166,6 +167,7 @@ public class EnderIO { public static BlockFarmStation blockFarmStation; public static BlockTank blockTank; public static BlockCrafter blockCrafter; + public static BlockPoweredSpawner blockPoweredSpawner; public static BlockElectricLight blockElectricLight; public static BlockLightNode blockLightNode; @@ -232,6 +234,7 @@ public class EnderIO { blockVat = BlockVat.create(); blockPowerMonitor = BlockPowerMonitor.create(); blockFarmStation = BlockFarmStation.create(); + blockPoweredSpawner = BlockPoweredSpawner.create(); blockCapacitorBank = BlockCapacitorBank.create(); blockPainter = BlockPainter.create(); diff --git a/src/main/java/crazypants/enderio/GuiHandler.java b/src/main/java/crazypants/enderio/GuiHandler.java index 9446f17b..a92bb186 100644 --- a/src/main/java/crazypants/enderio/GuiHandler.java +++ b/src/main/java/crazypants/enderio/GuiHandler.java @@ -38,6 +38,7 @@ public class GuiHandler implements IGuiHandler { public static final int GUI_ID_TANK = 86; public static final int GUI_ID_CRAFTER = 87; public static final int GUI_ID_ZOMBIE_GEN = 71; + public static final int GUI_ID_POWERED_SPAWNER = 88; protected final Map guiHandlers = new HashMap(); diff --git a/src/main/java/crazypants/enderio/ModObject.java b/src/main/java/crazypants/enderio/ModObject.java index d9742499..2e71a9f1 100644 --- a/src/main/java/crazypants/enderio/ModObject.java +++ b/src/main/java/crazypants/enderio/ModObject.java @@ -47,6 +47,7 @@ public enum ModObject { blockFarmStation, blockTank, blockCrafter, + blockPoweredSpawner, blockElectricLight, blockLightNode, diff --git a/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java b/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java index 4fbb8fa5..278a3d37 100644 --- a/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java +++ b/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java @@ -326,7 +326,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi requiresClientSync |= prevRedCheck != redstoneCheckPassed; requiresClientSync |= processTasks(redstoneCheckPassed); - + boolean powerChanged = (lastSyncPowerStored != storedEnergy && worldObj.getTotalWorldTime() % 5 == 0); if(requiresClientSync) { diff --git a/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java b/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java index 6a229591..2de9c517 100644 --- a/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java +++ b/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java @@ -103,10 +103,8 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity { // Then see if we need to start a new one IMachineRecipe nextRecipe = canStartNextTask(chance); if(nextRecipe != null) { - boolean started = startNextTask(nextRecipe, chance); - if(started != startFailed) { - PacketHandler.sendToAllAround(new PacketCurrentTask(this), this); - } + boolean started = startNextTask(nextRecipe, chance); + PacketHandler.sendToAllAround(new PacketCurrentTask(this), this); startFailed = !started; } else { startFailed = true; diff --git a/src/main/java/crazypants/enderio/machine/PacketCurrentTask.java b/src/main/java/crazypants/enderio/machine/PacketCurrentTask.java index 16c9241a..8151700d 100644 --- a/src/main/java/crazypants/enderio/machine/PacketCurrentTask.java +++ b/src/main/java/crazypants/enderio/machine/PacketCurrentTask.java @@ -19,11 +19,11 @@ public class PacketCurrentTask extends MessageTileEntity { + + public static BlockPoweredSpawner create() { + + MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPoweredSpawner.unlocalisedName, new DummyRecipe()); + + BlockPoweredSpawner res = new BlockPoweredSpawner(); + res.init(); + return res; + } + + protected BlockPoweredSpawner() { + super(ModObject.blockPoweredSpawner, TilePoweredSpawner.class); + } + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + return null; + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + return null; + } + + @Override + protected int getGuiId() { + return GuiHandler.GUI_ID_POWERED_SPAWNER; + } + + @Override + protected String getMachineFrontIconKey(boolean active) { + if(active) { + return "enderio:poweredSpawnerFrontActive"; + } + return "enderio:poweredSpawnerFront"; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + +} diff --git a/src/main/java/crazypants/enderio/machine/spawner/DummyRecipe.java b/src/main/java/crazypants/enderio/machine/spawner/DummyRecipe.java new file mode 100644 index 00000000..968158eb --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/spawner/DummyRecipe.java @@ -0,0 +1,62 @@ +package crazypants.enderio.machine.spawner; + +import java.util.Collections; +import java.util.List; + +import net.minecraft.item.ItemStack; +import crazypants.enderio.ModObject; +import crazypants.enderio.crafting.IEnderIoRecipe; +import crazypants.enderio.machine.IMachineRecipe; +import crazypants.enderio.machine.MachineRecipeInput; +import crazypants.enderio.machine.IMachineRecipe.ResultStack; +import crazypants.enderio.power.Capacitors; + +public class DummyRecipe implements IMachineRecipe { + + @Override + public String getUid() { + return "PoweredTaskRecipe"; + } + + @Override + public float getEnergyRequired(MachineRecipeInput... inputs) { + //NB: This value is not actually used, see createTask in the tile + return TilePoweredSpawner.POWER_PER_TICK_ONE * 800; + } + + @Override + public boolean isRecipe(MachineRecipeInput... inputs) { + return true; + } + + @Override + public ResultStack[] getCompletedResult(float randomChance, MachineRecipeInput... inputs) { + return new ResultStack[0]; + } + + @Override + public float getExperianceForOutput(ItemStack output) { + return 0; + } + + @Override + public boolean isValidInput(MachineRecipeInput input) { + return false; + } + + @Override + public String getMachineName() { + return ModObject.blockPoweredSpawner.unlocalisedName; + } + + @Override + public List getQuantitiesConsumed(MachineRecipeInput[] inputs) { + return Collections.emptyList(); + } + + @Override + public List getAllRecipes() { + return Collections.emptyList(); + } + +} \ No newline at end of file diff --git a/src/main/java/crazypants/enderio/machine/spawner/TilePoweredSpawner.java b/src/main/java/crazypants/enderio/machine/spawner/TilePoweredSpawner.java new file mode 100644 index 00000000..15e5d755 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/spawner/TilePoweredSpawner.java @@ -0,0 +1,268 @@ +package crazypants.enderio.machine.spawner; + + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.MobSpawnerBaseLogic; +import net.minecraft.tileentity.TileEntityMobSpawner; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import crazypants.enderio.Config; +import crazypants.enderio.EnderIO; +import crazypants.enderio.ModObject; +import crazypants.enderio.machine.AbstractMachineEntity; +import crazypants.enderio.machine.AbstractPoweredTaskEntity; +import crazypants.enderio.machine.IMachineRecipe; +import crazypants.enderio.machine.IPoweredTask; +import crazypants.enderio.machine.PoweredTask; +import crazypants.enderio.machine.SlotDefinition; +import crazypants.enderio.power.Capacitors; + +public class TilePoweredSpawner extends AbstractPoweredTaskEntity { + + public static final int MIN_SPAWN_DELAY_BASE = Config.poweredSpawnerMinDelayTicks; + public static final int MAX_SPAWN_DELAY_BASE = Config.poweredSpawnerMaxDelayTicks; + public static final float POWER_PER_TICK_ONE = Config.poweredSpawnerLevelOnePowerPerTick; + public static final float POWER_PER_TICK_TWO = Config.poweredSpawnerLevelTwoPowerPerTick; + public static final float POWER_PER_TICK_THREE = Config.poweredSpawnerLevelThreePowerPerTick; + public static final int MIN_PLAYER_DISTANCE = Config.poweredSpawnerMaxPlayerDistance; + public static final boolean USE_VANILLA_SPAWN_CHECKS = Config.poweredSpawnerUseVanillaSpawChecks; + + private final MobSpawnerBaseLogic logic = new SpawnerLogic(); + + public TilePoweredSpawner() { + super(new SlotDefinition(0, 0)); + //logic.setEntityName("Zombie"); + logic.setEntityName("Skeleton"); + } + + @Override + protected void taskComplete() { + super.taskComplete(); + logic.spawnDelay = 0; + } + + @Override + public String getMachineName() { + return ModObject.blockPoweredSpawner.unlocalisedName; + } + + @Override + protected boolean isMachineItemValidForSlot(int i, ItemStack itemstack) { + return false; + } + + @Override + protected IMachineRecipe canStartNextTask(float chance) { + return new DummyRecipe(); + } + + @Override + protected boolean startNextTask(IMachineRecipe nextRecipe, float chance) { + return super.startNextTask(nextRecipe, chance); + } + + @Override + public float getPowerUsePerTick() { + if(capacitorType.ordinal() == 0) { + return POWER_PER_TICK_ONE; + } else if(capacitorType.ordinal() == 1) { + return POWER_PER_TICK_TWO; + } + return POWER_PER_TICK_THREE; + } + + @Override + protected boolean hasInputStacks() { + return true; + } + + @Override + protected boolean canInsertResult(float chance, IMachineRecipe nextRecipe) { + return true; + } + + public void readCustomNBT(NBTTagCompound nbtRoot) { + super.readCustomNBT(nbtRoot); + logic.readFromNBT(nbtRoot); + } + + public void writeCustomNBT(NBTTagCompound nbtRoot) { + super.writeCustomNBT(nbtRoot); + logic.writeToNBT(nbtRoot); + } + + public void updateEntity() { + logic.updateSpawner(); + super.updateEntity(); + } + + /** + * Called when a client event is received with the event number and argument, + * see World.sendClientEvent + */ + public boolean receiveClientEvent(int p_145842_1_, int p_145842_2_) { + return logic.setDelayToMin(p_145842_1_) ? true : super.receiveClientEvent(p_145842_1_, p_145842_2_); + } + + protected IPoweredTask createTask(IMachineRecipe nextRecipe, float chance) { + PoweredTask res = new PoweredTask(nextRecipe, chance, getInputs()); + + int ticksDelay = TilePoweredSpawner.MIN_SPAWN_DELAY_BASE + (int)Math.round((TilePoweredSpawner.MAX_SPAWN_DELAY_BASE - TilePoweredSpawner.MIN_SPAWN_DELAY_BASE) * Math.random()); + if(capacitorType.ordinal() == 1) { + ticksDelay /= 2; + } else if(capacitorType.ordinal() == 2) { + ticksDelay /= 4; + } + int powerPerTick = (int)getPowerUsePerTick(); + res.setRequiredEnergy(powerPerTick * ticksDelay); + return res; + } + + protected boolean canSpawnEntity(EntityLiving entityliving) { + boolean spaceClear = worldObj.checkNoEntityCollision(entityliving.boundingBox) && worldObj.getCollidingBoundingBoxes(entityliving, entityliving.boundingBox).isEmpty() && !worldObj.isAnyLiquid(entityliving.boundingBox); + if(spaceClear && USE_VANILLA_SPAWN_CHECKS) { + //Full checks for lighting, dimension etc + spaceClear = entityliving.getCanSpawnHere(); + } + return spaceClear; + } + + class SpawnerLogic extends MobSpawnerBaseLogic { + + private int spawnCount = 4; + private int maxNearbyEntities = 6; + private int spawnRange = 4; + + public void func_98267_a(int par1) { + worldObj.addBlockEvent(xCoord, yCoord, zCoord, EnderIO.blockPoweredSpawner, par1, 0); + } + + public World getSpawnerWorld() { + return worldObj; + } + + public int getSpawnerX() { + return xCoord; + } + + public int getSpawnerY() { + return yCoord; + } + + public int getSpawnerZ() { + return zCoord; + } + + public void setRandomEntity(MobSpawnerBaseLogic.WeightedRandomMinecart par1WeightedRandomMinecart) { + super.setRandomEntity(par1WeightedRandomMinecart); + if(getSpawnerWorld() != null) { + getSpawnerWorld().markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + /** + * Returns true if there's a player close enough to this mob spawner to + * activate it. + */ + public boolean isActivated() { + if(MIN_PLAYER_DISTANCE > 0) { + //TODO: Add this to main 'hasPower' like check so turn of the machine if the player is out of range? + boolean playerInRange = worldObj.getClosestPlayer((double)getSpawnerX() + 0.5D, (double)getSpawnerY() + 0.5D, (double)getSpawnerZ() + 0.5D, (double)MIN_PLAYER_DISTANCE) != null; + if(!playerInRange) { + return false; + } + } + return isActive(); + } + + public void updateSpawner() { + + if(isActivated()) { + double d2; + + if(getSpawnerWorld().isRemote) { + double d0 = (double) ((float) getSpawnerX() + getSpawnerWorld().rand.nextFloat()); + double d1 = (double) ((float) getSpawnerY() + getSpawnerWorld().rand.nextFloat()); + d2 = (double) ((float) getSpawnerZ() + getSpawnerWorld().rand.nextFloat()); + getSpawnerWorld().spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D); + getSpawnerWorld().spawnParticle("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D); + + if(spawnDelay > 0) + { + --spawnDelay; + } + + field_98284_d = field_98287_c; + field_98287_c = (field_98287_c + (double) (1000.0F / ((float) spawnDelay + 200.0F))) % 360.0D; + } else { + + if(spawnDelay == -1) { + resetTimer(); + } + if(spawnDelay > 0) { + --spawnDelay; + return; + } + + boolean doTimerReset = false; + + for (int i = 0; i < spawnCount; ++i) { + + Entity entity = EntityList.createEntityByName(getEntityNameToSpawn(), getSpawnerWorld()); + + if(entity == null) { + return; + } + + int j = getSpawnerWorld().getEntitiesWithinAABB( + entity.getClass(), + AxisAlignedBB + .getAABBPool() + .getAABB((double) getSpawnerX(), (double) getSpawnerY(), (double) getSpawnerZ(), (double) (getSpawnerX() + 1), + (double) (getSpawnerY() + 1), (double) (getSpawnerZ() + 1)).expand((double) (spawnRange * 2), 4.0D, (double) (spawnRange * 2))).size(); + + if(j >= maxNearbyEntities) { + resetTimer(); + return; + } + + d2 = (double) getSpawnerX() + (getSpawnerWorld().rand.nextDouble() - getSpawnerWorld().rand.nextDouble()) * (double) spawnRange; + double d3 = (double) (getSpawnerY() + getSpawnerWorld().rand.nextInt(3) - 1); + double d4 = (double) getSpawnerZ() + (getSpawnerWorld().rand.nextDouble() - getSpawnerWorld().rand.nextDouble()) * (double) spawnRange; + EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving) entity : null; + entity.setLocationAndAngles(d2, d3, d4, getSpawnerWorld().rand.nextFloat() * 360.0F, 0.0F); + + if(entityliving == null || canSpawnEntity(entityliving)) { + func_98265_a(entity); + getSpawnerWorld().playAuxSFX(2004, getSpawnerX(), getSpawnerY(), getSpawnerZ(), 0); + + if(entityliving != null) + { + entityliving.spawnExplosionParticle(); + } + + doTimerReset = true; + } + } + + if(doTimerReset) { + resetTimer(); + } + } + } + } + + void resetTimer() { + spawnDelay = Integer.MAX_VALUE; + } + + } + +} diff --git a/src/main/java/crazypants/enderio/machine/tank/BlockTank.java b/src/main/java/crazypants/enderio/machine/tank/BlockTank.java index f5e39250..11e71e66 100644 --- a/src/main/java/crazypants/enderio/machine/tank/BlockTank.java +++ b/src/main/java/crazypants/enderio/machine/tank/BlockTank.java @@ -37,14 +37,14 @@ import crazypants.util.Util; public class BlockTank extends AbstractMachineBlock implements IAdvancedTooltipProvider { public static BlockTank create() { - PacketHandler.INSTANCE.registerMessage(PacketTank.class, PacketTank.class, PacketHandler.nextID(), Side.CLIENT); + PacketHandler.INSTANCE.registerMessage(PacketTank.class, PacketTank.class, PacketHandler.nextID(), Side.CLIENT); BlockTank res = new BlockTank(); res.init(); return res; } protected BlockTank() { - super(ModObject.blockTank, TileTank.class); + super(ModObject.blockTank, TileTank.class); setStepSound(Block.soundTypeGlass); } @@ -57,12 +57,12 @@ public class BlockTank extends AbstractMachineBlock implements IAdvanc EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TANK, this); setLightOpacity(0); } - + @Override public int damageDropped(int par1) { return par1; } - + @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) { @@ -131,8 +131,6 @@ public class BlockTank extends AbstractMachineBlock implements IAdvanc return super.onBlockActivated(world, x, y, z, entityPlayer, par6, par7, par8, par9); } - - @Override public TileEntity createNewTileEntity(World var1, int var2) { return new TileTank(var2); @@ -144,7 +142,7 @@ public class BlockTank extends AbstractMachineBlock implements IAdvanc if(!(te instanceof TileTank)) { return null; } - return new ContainerTank(player.inventory, (TileTank)te); + return new ContainerTank(player.inventory, (TileTank) te); } @Override @@ -153,7 +151,7 @@ public class BlockTank extends AbstractMachineBlock implements IAdvanc if(!(te instanceof TileTank)) { return null; } - return new GuiTank(player.inventory, (TileTank)te); + return new GuiTank(player.inventory, (TileTank) te); } //Causes crashes in 1.7 on some machines @@ -168,17 +166,16 @@ public class BlockTank extends AbstractMachineBlock implements IAdvanc // return pass == 1; //} -@Override -public boolean isOpaqueCube() { - return false; -} - + @Override + public boolean isOpaqueCube() { + return false; + } + @Override protected int getGuiId() { return GuiHandler.GUI_ID_TANK; } - - + @Override public IIcon getIcon(IBlockAccess world, int x, int y, int z, int blockSide) { @@ -203,7 +200,6 @@ public boolean isOpaqueCube() { int offset = MathHelper.clamp_int(blockMeta, 0, 1) == 0 ? 0 : 6; return iconBuffer[0][blockSide + offset]; } - @Override protected String getMachineFrontIconKey(boolean pressurized) { @@ -212,18 +208,18 @@ public boolean isOpaqueCube() { } return "enderio:blockTank"; } - + protected String getSideIconKey(boolean active) { return getMachineFrontIconKey(active); } - + protected String getBackIconKey(boolean active) { return getMachineFrontIconKey(active); } - + @Override protected String getTopIconKey(boolean pressurized) { - if(pressurized) { + if(pressurized) { return "enderio:blockTankTopAdvanced"; } return "enderio:machineTop"; @@ -244,17 +240,17 @@ public boolean isOpaqueCube() { return super.getExplosionResistance(par1Entity); } } - + @Override @SideOnly(Side.CLIENT) - public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) { - if(itemstack.stackTagCompound != null && itemstack.stackTagCompound.hasKey("tankContents")) { + public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) { + if(itemstack.stackTagCompound != null && itemstack.stackTagCompound.hasKey("tankContents")) { FluidStack fl = FluidStack.loadFluidStackFromNBT((NBTTagCompound) itemstack.stackTagCompound.getTag("tankContents")); if(fl != null && fl.getFluid() != null) { String str = fl.amount + " " + Lang.localize("fluid.millibucket.abr") + " " + PowerDisplayUtil.ofStr() + " " + fl.getFluid().getLocalizedName(); - list.add(str); - } - } + list.add(str); + } + } } @Override @@ -265,11 +261,11 @@ public boolean isOpaqueCube() { list.add(EnumChatFormatting.ITALIC + Lang.localize("blastResistant")); } } - + @Override public String getUnlocalizedNameForTooltip(ItemStack stack) { System.out.println("BlockTank.getUnlocalizedNameForTooltip: "); return stack.getUnlocalizedName(); } - + }