From f483197a69c9975a542eab87d3efa87bd8f90862 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 7 Jul 2015 11:31:13 +0200 Subject: [PATCH] Added Lamp Powerer, doesn't work yet though --- .../blocks/BlockColoredLamp.java | 2 +- .../blocks/BlockLampPowerer.java | 122 ++++++++++++++++++ .../actuallyadditions/blocks/InitBlocks.java | 3 + .../assets/actuallyadditions/lang/en_US.lang | 1 + 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/blocks/BlockLampPowerer.java diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockColoredLamp.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockColoredLamp.java index 1277735c7..a74b825a1 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/BlockColoredLamp.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockColoredLamp.java @@ -148,7 +148,7 @@ public class BlockColoredLamp extends Block implements INameableItem{ @SuppressWarnings("unchecked") @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) { - BlockUtil.addInformation(InitBlocks.blockColoredLamp, list, 2, ""); + BlockUtil.addInformation(InitBlocks.blockColoredLamp, list, 3, ""); } @Override diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockLampPowerer.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockLampPowerer.java new file mode 100644 index 000000000..cd25088d9 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockLampPowerer.java @@ -0,0 +1,122 @@ +package ellpeck.actuallyadditions.blocks; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.util.BlockUtil; +import ellpeck.actuallyadditions.util.INameableItem; +import ellpeck.actuallyadditions.util.ModUtil; +import ellpeck.actuallyadditions.util.WorldUtil; +import net.minecraft.block.Block; +import net.minecraft.block.BlockPistonBase; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.List; + +public class BlockLampPowerer extends Block implements INameableItem{ + + private IIcon frontIcon; + private IIcon topIcon; + + public BlockLampPowerer(){ + super(Material.rock); + this.setHarvestLevel("pickaxe", 0); + this.setHardness(1.5F); + this.setResistance(10.0F); + this.setStepSound(soundTypeStone); + } + + @Override + public String getName(){ + return "blockLampPowerer"; + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack){ + int rotation = BlockPistonBase.determineOrientation(world, x, y, z, player); + world.setBlockMetadataWithNotify(x, y, z, rotation, 2); + } + + @Override + public IIcon getIcon(int side, int meta){ + if(side == 0 || side == 1) return this.topIcon; + if(side == 3) return this.frontIcon; + return this.blockIcon; + } + + @Override + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side){ + int meta = world.getBlockMetadata(x, y, z); + if(side != meta && (side == 0 || side == 1)) return this.topIcon; + if(side == meta) return this.frontIcon; + return this.blockIcon; + } + + @Override + public void onBlockAdded(World world, int x, int y, int z){ + this.updateLamp(world, x, y, z); + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block block){ + this.updateLamp(world, x, y, z); + } + + private void updateLamp(World world, int x, int y, int z){ + if(!world.isRemote){ + ChunkCoordinates coords = WorldUtil.getCoordsFromSide(ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)), x, y, z); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg){ + this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName()); + this.frontIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName() + "Front"); + this.topIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName() + "Top"); + } + + public static class TheItemBlock extends ItemBlock{ + + private Block theBlock; + + public TheItemBlock(Block block){ + super(block); + this.theBlock = block; + this.setHasSubtypes(false); + this.setMaxDamage(0); + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return EnumRarity.uncommon; + } + + @Override + public String getUnlocalizedName(ItemStack stack){ + return this.getUnlocalizedName(); + } + + @Override + @SuppressWarnings("unchecked") + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) { + BlockUtil.addInformation(theBlock, list, 1, ""); + } + + @Override + public int getMetadata(int meta){ + return meta; + } + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java index 78d6897a4..ea50203cc 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/InitBlocks.java @@ -76,6 +76,7 @@ public class InitBlocks{ public static Block blockColoredLamp; public static Block blockColoredLampOn; + public static Block blockLampPowerer; public static void init(){ ModUtil.LOGGER.info("Initializing Blocks..."); @@ -97,6 +98,8 @@ public class InitBlocks{ BlockUtil.register(blockColoredLamp, BlockColoredLamp.TheItemBlock.class); blockColoredLampOn = new BlockColoredLamp(true); BlockUtil.register(blockColoredLampOn, BlockColoredLamp.TheItemBlock.class, false); + blockLampPowerer = new BlockLampPowerer(); + BlockUtil.register(blockLampPowerer, BlockLampPowerer.TheItemBlock.class); blockEnergizer = new BlockEnergizer(true); BlockUtil.register(blockEnergizer, BlockEnergizer.TheItemBlock.class); diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 619cc7d47..5c2916356 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -63,6 +63,7 @@ tooltip.actuallyadditions.blockCoalGenerator.desc=Produces Energy from Coal and tooltip.actuallyadditions.blockColoredLamp.desc.1=Sneak-Right-Click to turn me on! tooltip.actuallyadditions.blockColoredLamp.desc.2=Right-Click me with a Dye to dye me! +tooltip.actuallyadditions.blockColoredLamp.desc.3=Use a Lamp Powerer to toggle me with Redstone! tile.actuallyadditions.blockColoredLampWhite.name=White Lamp tile.actuallyadditions.blockColoredLampOrange.name=Orange Lamp