diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index b4d5d29e6..638c667a9 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -336,8 +336,11 @@ public class ModBlocks { public static Block lantern_behemoth; public static Block spotlight_incandescent; + public static Block spotlight_incandescent_off; public static Block spotlight_fluoro; + public static Block spotlight_fluoro_off; public static Block spotlight_halogen; + public static Block spotlight_halogen_off; public static Block spotlight_beam; public static Block reinforced_stone; @@ -1565,9 +1568,12 @@ public class ModBlocks { lantern = new BlockLantern().setBlockName("lantern").setStepSound(Block.soundTypeMetal).setCreativeTab(MainRegistry.blockTab).setLightLevel(1F).setHardness(3.0F).setBlockTextureName(RefStrings.MODID + ":block_steel"); lantern_behemoth = new BlockLanternBehemoth().setBlockName("lantern_behemoth").setStepSound(Block.soundTypeMetal).setCreativeTab(null).setHardness(3.0F).setBlockTextureName(RefStrings.MODID + ":block_rust"); - spotlight_incandescent = new Spotlight(Material.iron, 2, LightType.INCANDESCENT).setBlockName("spotlight_incandescent").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":cage_lamp"); - spotlight_fluoro = new SpotlightModular(Material.iron, 8, LightType.FLUORESCENT).setBlockName("spotlight_fluoro").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":fluorescent_lamp"); - spotlight_halogen = new Spotlight(Material.iron, 32, LightType.HALOGEN).setBlockName("spotlight_halogen").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":flood_lamp"); + spotlight_incandescent = new Spotlight(Material.iron, 2, LightType.INCANDESCENT, true).setBlockName("spotlight_incandescent").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":cage_lamp"); + spotlight_incandescent_off = new Spotlight(Material.iron, 2, LightType.INCANDESCENT, false).setBlockName("spotlight_incandescent_off").setBlockTextureName(RefStrings.MODID + ":cage_lamp_off"); + spotlight_fluoro = new SpotlightModular(Material.iron, 8, LightType.FLUORESCENT, true).setBlockName("spotlight_fluoro").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":fluorescent_lamp"); + spotlight_fluoro_off = new SpotlightModular(Material.iron, 8, LightType.FLUORESCENT, false).setBlockName("spotlight_fluoro_off").setBlockTextureName(RefStrings.MODID + ":fluorescent_lamp_off"); + spotlight_halogen = new Spotlight(Material.iron, 32, LightType.HALOGEN, true).setBlockName("spotlight_halogen").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":flood_lamp"); + spotlight_halogen_off = new Spotlight(Material.iron, 32, LightType.HALOGEN, false).setBlockName("spotlight_halogen_off").setBlockTextureName(RefStrings.MODID + ":flood_lamp_off"); spotlight_beam = new SpotlightBeam().setBlockName("spotlight_beam"); reinforced_stone = new BlockGeneric(Material.rock).setBlockName("reinforced_stone").setCreativeTab(MainRegistry.blockTab).setHardness(15.0F).setResistance(100.0F).setBlockTextureName(RefStrings.MODID + ":reinforced_stone"); @@ -2749,8 +2755,11 @@ public class ModBlocks { GameRegistry.registerBlock(lantern, lantern.getUnlocalizedName()); GameRegistry.registerBlock(lantern_behemoth, lantern_behemoth.getUnlocalizedName()); GameRegistry.registerBlock(spotlight_incandescent, spotlight_incandescent.getUnlocalizedName()); + GameRegistry.registerBlock(spotlight_incandescent_off, spotlight_incandescent_off.getUnlocalizedName()); GameRegistry.registerBlock(spotlight_fluoro, spotlight_fluoro.getUnlocalizedName()); + GameRegistry.registerBlock(spotlight_fluoro_off, spotlight_fluoro_off.getUnlocalizedName()); GameRegistry.registerBlock(spotlight_halogen, spotlight_halogen.getUnlocalizedName()); + GameRegistry.registerBlock(spotlight_halogen_off, spotlight_halogen_off.getUnlocalizedName()); GameRegistry.registerBlock(spotlight_beam, spotlight_beam.getUnlocalizedName()); //Reinforced Blocks diff --git a/src/main/java/com/hbm/blocks/generic/ReinforcedLamp.java b/src/main/java/com/hbm/blocks/generic/ReinforcedLamp.java index b2de460b3..a3a7819b6 100644 --- a/src/main/java/com/hbm/blocks/generic/ReinforcedLamp.java +++ b/src/main/java/com/hbm/blocks/generic/ReinforcedLamp.java @@ -77,7 +77,7 @@ public class ReinforcedLamp extends Block { return new ItemStack(getOff()); } - private Block getOff() { + protected Block getOff() { if(this == ModBlocks.reinforced_lamp_on) return ModBlocks.reinforced_lamp_off; @@ -89,7 +89,7 @@ public class ReinforcedLamp extends Block { return this; } - private Block getOn() { + protected Block getOn() { if(this == ModBlocks.reinforced_lamp_off) return ModBlocks.reinforced_lamp_on; diff --git a/src/main/java/com/hbm/blocks/machine/Spotlight.java b/src/main/java/com/hbm/blocks/machine/Spotlight.java index f722c7ff4..1a5bf2fed 100644 --- a/src/main/java/com/hbm/blocks/machine/Spotlight.java +++ b/src/main/java/com/hbm/blocks/machine/Spotlight.java @@ -1,13 +1,20 @@ package com.hbm.blocks.machine; import com.hbm.blocks.ModBlocks; + +import java.util.Random; + import com.hbm.blocks.BlockEnums.LightType; import com.hbm.main.ResourceManager; import cpw.mods.fml.client.registry.RenderingRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockSlab; import net.minecraft.block.material.Material; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -16,15 +23,22 @@ import net.minecraftforge.common.util.ForgeDirection; public class Spotlight extends Block { + // I'd be extending the ReinforcedLamp class if it wasn't for the inverted behaviour of these specific lights + // I want these blocks to be eminently useful, so removing the need for redstone by default is desired, + // these act more like redstone torches, in that applying a signal turns them off + public boolean isOn; + public int beamLength; public LightType type; - public Spotlight(Material mat, int beamLength, LightType type) { + public Spotlight(Material mat, int beamLength, LightType type, boolean isOn) { super(mat); - setLightLevel(1.0F); - + this.beamLength = beamLength; this.type = type; + this.isOn = isOn; + + if (isOn) setLightLevel(1.0F); } public static int renderID = RenderingRegistry.getNextAvailableRenderId(); @@ -104,9 +118,25 @@ public class Spotlight extends Block { @Override public void onBlockAdded(World world, int x, int y, int z) { if (world.isRemote) return; + + if (updatePower(world, x, y, z)) return; + updateBeam(world, x, y, z); } + private boolean updatePower(World world, int x, int y, int z) { + boolean isPowered = world.isBlockIndirectlyGettingPowered(x, y, z); + if (isOn && isPowered) { + world.scheduleBlockUpdate(x, y, z, this, 4); + return true; + } else if (!isOn && !isPowered) { + world.setBlock(x, y, z, getOn(), world.getBlockMetadata(x, y, z), 2); + return true; + } + + return false; + } + @Override public void breakBlock(World world, int x, int y, int z, Block block, int metadata) { ForgeDirection dir = getDirection(metadata); @@ -117,6 +147,15 @@ public class Spotlight extends Block { unpropagateBeam(world, x, y, z, dir); } + @Override + public void updateTick(World world, int x, int y, int z, Random p_149674_5_) { + if (world.isRemote) return; + + if (isOn && world.isBlockIndirectlyGettingPowered(x, y, z)) { + world.setBlock(x, y, z, getOff(), world.getBlockMetadata(x, y, z), 2); + } + } + // Repropagate the beam if we've become unblocked @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) { @@ -131,6 +170,8 @@ public class Spotlight extends Block { return; } + if (updatePower(world, x, y, z)) return; + updateBeam(world, x, y, z); } @@ -161,6 +202,8 @@ public class Spotlight extends Block { } private void updateBeam(World world, int x, int y, int z) { + if (!isOn) return; + ForgeDirection dir = getDirection(world, x, y, z); propagateBeam(world, x, y, z, dir, beamLength); } @@ -174,6 +217,22 @@ public class Spotlight extends Block { return ForgeDirection.getOrientation(metadata >> 1); } + @Override + public Item getItemDropped(int i, Random r, int j) { + return Item.getItemFromBlock(getOn()); + } + + @Override + @SideOnly(Side.CLIENT) + public Item getItem(World world, int x, int y, int z) { + return Item.getItemFromBlock(getOn()); + } + + @Override + protected ItemStack createStackedBlock(int e) { + return new ItemStack(getOn()); + } + // Recursively add beam blocks, updating any that already exist with new incoming light directions public static void propagateBeam(World world, int x, int y, int z, ForgeDirection dir, int distance) { distance--; @@ -230,5 +289,27 @@ public class Spotlight extends Block { backPropagate(world, x, y, z, dir); } + + protected Block getOff() { + if(this == ModBlocks.spotlight_incandescent) + return ModBlocks.spotlight_incandescent_off; + if(this == ModBlocks.spotlight_fluoro) + return ModBlocks.spotlight_fluoro_off; + if(this == ModBlocks.spotlight_halogen) + return ModBlocks.spotlight_halogen_off; + + return this; + } + + protected Block getOn() { + if(this == ModBlocks.spotlight_incandescent_off) + return ModBlocks.spotlight_incandescent; + if(this == ModBlocks.spotlight_fluoro_off) + return ModBlocks.spotlight_fluoro; + if(this == ModBlocks.spotlight_halogen_off) + return ModBlocks.spotlight_halogen; + + return this; + } } diff --git a/src/main/java/com/hbm/blocks/machine/SpotlightModular.java b/src/main/java/com/hbm/blocks/machine/SpotlightModular.java index c5244d242..5a0cddc2b 100644 --- a/src/main/java/com/hbm/blocks/machine/SpotlightModular.java +++ b/src/main/java/com/hbm/blocks/machine/SpotlightModular.java @@ -7,8 +7,8 @@ import net.minecraft.world.IBlockAccess; public class SpotlightModular extends Spotlight { - public SpotlightModular(Material mat, int beamLength, LightType type) { - super(mat, beamLength, type); + public SpotlightModular(Material mat, int beamLength, LightType type, boolean isOn) { + super(mat, beamLength, type, isOn); } @Override diff --git a/src/main/java/com/hbm/main/NEIConfig.java b/src/main/java/com/hbm/main/NEIConfig.java index 45c3fdb6e..8ee671107 100644 --- a/src/main/java/com/hbm/main/NEIConfig.java +++ b/src/main/java/com/hbm/main/NEIConfig.java @@ -131,6 +131,9 @@ public class NEIConfig implements IConfigureNEI { API.hideItem(new ItemStack(ModBlocks.pink_double_slab)); API.hideItem(new ItemStack(ModBlocks.pink_stairs)); + API.hideItem(new ItemStack(ModBlocks.spotlight_incandescent_off)); + API.hideItem(new ItemStack(ModBlocks.spotlight_fluoro_off)); + API.hideItem(new ItemStack(ModBlocks.spotlight_halogen_off)); API.hideItem(new ItemStack(ModBlocks.spotlight_beam)); API.registerHighlightIdentifier(ModBlocks.ore_random, new IHighlightHandler() { diff --git a/src/main/resources/assets/hbm/textures/blocks/cage_lamp.png b/src/main/resources/assets/hbm/textures/blocks/cage_lamp.png index 8932b2ffa..f78cb205e 100644 Binary files a/src/main/resources/assets/hbm/textures/blocks/cage_lamp.png and b/src/main/resources/assets/hbm/textures/blocks/cage_lamp.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/cage_lamp_off.png b/src/main/resources/assets/hbm/textures/blocks/cage_lamp_off.png new file mode 100644 index 000000000..c2bf59718 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/cage_lamp_off.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/flood_lamp_off.png b/src/main/resources/assets/hbm/textures/blocks/flood_lamp_off.png new file mode 100644 index 000000000..b79c23c1d Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/flood_lamp_off.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/fluorescent_lamp_off.png b/src/main/resources/assets/hbm/textures/blocks/fluorescent_lamp_off.png new file mode 100644 index 000000000..edc0193a7 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/fluorescent_lamp_off.png differ