diff --git a/src/main/java/techreborn/blocks/lighting/BlockLamp.java b/src/main/java/techreborn/blocks/lighting/BlockLamp.java new file mode 100644 index 000000000..619f6e919 --- /dev/null +++ b/src/main/java/techreborn/blocks/lighting/BlockLamp.java @@ -0,0 +1,172 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.blocks.lighting; + +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyBool; +import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.block.state.BlockFaceShape; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import prospector.shootingstar.ShootingStar; +import prospector.shootingstar.model.ModelCompound; +import reborncore.common.BaseTileBlock; +import techreborn.client.TechRebornCreativeTab; +import techreborn.lib.ModInfo; +import techreborn.tiles.lighting.TileLamp; + +public class BlockLamp extends BaseTileBlock { + + public static PropertyDirection FACING; + public static PropertyBool ACTIVE; + + private static AxisAlignedBB[] GenBoundingBoxes(double depth, double width) { + AxisAlignedBB[] bb = { + new AxisAlignedBB(width, 1.0 - depth, width, 1.0 - width, 1.0D, 1.0 - width), + new AxisAlignedBB(width, 0.0D, width, 1.0 - width, depth, 1.0 - width), + new AxisAlignedBB(width, width, 1.0 - depth, 1.0 - width, 1.0 - width, 1.0D), + new AxisAlignedBB(width, width, 0.0D, 1.0 - width, 1.0 - width, depth), + new AxisAlignedBB(1.0 - depth, width, width, 1.0D, 1.0 - width, 1.0 - width), + new AxisAlignedBB(0.0D, width, width, depth, 1.0 - width, 1.0 - width), + }; + return bb; + } + + private AxisAlignedBB[] bbs; + + private int cost; + private int brightness; + + public BlockLamp(int brightness, int cost, double depth, double width) { + super(Material.REDSTONE_LIGHT); + this.setCreativeTab(TechRebornCreativeTab.instance); + this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, false)); + this.bbs = GenBoundingBoxes(depth, width); + this.cost = cost; + this.brightness = brightness; + ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/lighting")); + } + + protected BlockStateContainer createBlockState() { + FACING = PropertyDirection.create("facing"); + ACTIVE = PropertyBool.create("active"); + return new BlockStateContainer(this, FACING, ACTIVE); + } + + @Override + public TileEntity createNewTileEntity(final World world, final int meta) { + return new TileLamp(); + } + + @Override + public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, + float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { + return this.getDefaultState().withProperty(FACING, facing); + } + + @Override + public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) { + return state.getValue(ACTIVE) ? brightness : 0; + } + + @Override + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.CUTOUT; + } + + @Override + public boolean isOpaqueCube(IBlockState state) { + return false; + } + + @Override + public boolean isFullBlock(IBlockState state) { + return false; + } + + @Override + public boolean isFullCube(IBlockState state) { + return false; + } + + @Override + public BlockFaceShape getBlockFaceShape(IBlockAccess access, IBlockState state, BlockPos pos, EnumFacing facing) { + // This makes only the back face of lamps connect to fences. + if (getFacing(state).getOpposite() == facing) + return BlockFaceShape.SOLID; + else + return BlockFaceShape.UNDEFINED; + } + + @Override + public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { + return this.bbs[getFacing(state).getIndex()]; + } + + @Override + public int getMetaFromState(IBlockState state) { + int facingInt = state.getValue(FACING).getIndex(); + int activeInt = state.getValue(ACTIVE) ? 8 : 0; + return facingInt + activeInt; + } + + @Override + public IBlockState getStateFromMeta(int meta) { + Boolean active = (meta&8)==8; + EnumFacing facing = EnumFacing.getFront(meta&7); + return this.getDefaultState().withProperty(FACING, facing).withProperty(ACTIVE, active); + } + + public static boolean isActive(IBlockState state) { + return state.getValue(ACTIVE); + } + + public static EnumFacing getFacing(IBlockState state) { + return (EnumFacing)state.getValue(FACING); + } + + public static void setFacing(EnumFacing facing, World world, BlockPos pos) { + world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing)); + } + + public static void setActive(Boolean active, World world, BlockPos pos) { + EnumFacing facing = (EnumFacing)world.getBlockState(pos).getValue(FACING); + IBlockState state = world.getBlockState(pos).withProperty(ACTIVE, active).withProperty(FACING, facing); + world.setBlockState(pos, state, 3); + } + + public int getCost() { + return cost; + } +} diff --git a/src/main/java/techreborn/init/ModBlocks.java b/src/main/java/techreborn/init/ModBlocks.java index 82f0272e2..f03b88326 100644 --- a/src/main/java/techreborn/init/ModBlocks.java +++ b/src/main/java/techreborn/init/ModBlocks.java @@ -43,6 +43,7 @@ import techreborn.blocks.generator.*; import techreborn.blocks.generator.solarpanel.BlockSolarPanel; import techreborn.blocks.iron_machines.BlockIronAlloyFurnace; import techreborn.blocks.iron_machines.BlockIronFurnace; +import techreborn.blocks.lighting.BlockLamp; import techreborn.blocks.machine.*; import techreborn.blocks.storage.*; import techreborn.blocks.tier1.*; @@ -58,6 +59,7 @@ import techreborn.tiles.generator.*; import techreborn.tiles.idsu.TileInterdimensionalSU; import techreborn.tiles.lesu.TileLSUStorage; import techreborn.tiles.lesu.TileLapotronicSU; +import techreborn.tiles.lighting.TileLamp; import techreborn.tiles.multiblock.*; import techreborn.tiles.storage.TileHighVoltageSU; import techreborn.tiles.storage.TileLowVoltageSU; @@ -148,6 +150,10 @@ public class ModBlocks { public static Block COMPUTER_CUBE; public static Block PLASMA_GENERATOR; + public static Block LAMP_INCANDESCENT; + public static Block LAMP_LED; + public static Block LAMP_LED_LARGE; + /** * Register blocks */ @@ -414,6 +420,14 @@ public class ModBlocks { registerBlock(PLASMA_GENERATOR, "plasma_generator"); GameRegistry.registerTileEntity(TilePlasmaGenerator.class, "TilePlasmalGeneratorTR"); + LAMP_INCANDESCENT = new BlockLamp( 14, 4, 0.625, 0.25); + registerBlock(LAMP_INCANDESCENT, "lamp_incandescent"); + + LAMP_LED = new BlockLamp( 15, 1, 0.0625, 0.125); + registerBlock(LAMP_LED, "lamp_led"); + + GameRegistry.registerTileEntity(TileLamp.class, "TileLampTR"); + //TODO enable when done // flare = new BlockFlare(); // registerBlock(flare, "flare"); diff --git a/src/main/java/techreborn/init/recipes/CraftingTableRecipes.java b/src/main/java/techreborn/init/recipes/CraftingTableRecipes.java index 3f8a46ea4..1e561d5a8 100644 --- a/src/main/java/techreborn/init/recipes/CraftingTableRecipes.java +++ b/src/main/java/techreborn/init/recipes/CraftingTableRecipes.java @@ -166,12 +166,16 @@ public class CraftingTableRecipes extends RecipeMethods { registerShaped(getStack(IC2Duplicates.SOLAR_PANEL), "DLD", "LDL", "CGC", 'D', "dustCoal", 'L', "blockGlass", 'G', getStack(IC2Duplicates.GENERATOR), 'C', "circuitBasic"); registerShapeless(getStack(IC2Duplicates.FREQ_TRANSMITTER), getStack(IC2Duplicates.CABLE_ICOPPER), "circuitBasic"); } - + if (!CompatManager.isQuantumStorageLoaded) { registerShaped(getStack(ModBlocks.QUANTUM_CHEST), "DCD", "ATA", "DQD", 'D', getMaterial("dataOrb", Type.PART), 'C', getMaterial("computerMonitor", Type.PART), 'A', getMaterial("highly_advanced_machine", Type.MACHINE_FRAME), 'Q', getStack(ModBlocks.DIGITAL_CHEST), 'T', getStack(IC2Duplicates.COMPRESSOR)); registerShaped(getStack(ModBlocks.QUANTUM_TANK), "EPE", "PCP", "EPE", 'P', "platePlatinum", 'E', "circuitAdvanced", 'C', getStack(ModBlocks.QUANTUM_CHEST)); } + //Lighting + registerShaped(getStack(ModBlocks.LAMP_INCANDESCENT), "GGG", "TCT", "GGG", 'G', "paneGlass", 'T', getMaterial("copper", Type.CABLE), 'C', getMaterial("carbon_fiber", Type.PART)); + registerShaped(getStack(ModBlocks.LAMP_LED), "GGG", "TLT", "GGG", 'G', "paneGlass", 'T', getMaterial("tin", Type.CABLE), 'L', "dustGlowstone"); + //Parts registerShaped(getMaterial("iridium_alloy", Type.INGOT), "IAI", "ADA", "IAI", 'I', "ingotIridium", 'D', "dustDiamond", 'A', "plateAdvancedAlloy"); registerShaped(getStack(ModItems.RE_BATTERY), " W ", "TRT", "TRT", 'T', "ingotTin", 'R', "dustRedstone", 'W', getStack(IC2Duplicates.CABLE_ICOPPER)); diff --git a/src/main/java/techreborn/tiles/lighting/TileLamp.java b/src/main/java/techreborn/tiles/lighting/TileLamp.java new file mode 100644 index 000000000..1b1d6a589 --- /dev/null +++ b/src/main/java/techreborn/tiles/lighting/TileLamp.java @@ -0,0 +1,85 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2017 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.tiles.lighting; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; +import reborncore.common.powerSystem.TilePowerAcceptor; +import techreborn.blocks.lighting.BlockLamp; + +public class TileLamp extends TilePowerAcceptor + implements ITickable { + + private static int capacity = 33; + + @Override + public void update() { + super.update(); + if (world != null && !world.isRemote) { + IBlockState state = world.getBlockState(pos); + Block b = state.getBlock(); + if (b instanceof BlockLamp) { + double cost = getEuPerTick(((BlockLamp)b).getCost()); + if (this.getEnergy() > cost) { + useEnergy(getEuPerTick(cost)); + if (!BlockLamp.isActive(state)) + BlockLamp.setActive(true, world, pos); + } else if (BlockLamp.isActive(state)) { + BlockLamp.setActive(false, world, pos); + } + } + } + } + + @Override + public double getBaseMaxPower() { + return capacity; + } + + @Override + public boolean canAcceptEnergy(final EnumFacing direction) { + EnumFacing me = BlockLamp.getFacing(world.getBlockState(pos)).getOpposite(); + return direction == me; + } + + @Override + public boolean canProvideEnergy(final EnumFacing direction) { + return false; + } + + @Override + public double getBaseMaxOutput() { + return 0; + } + + @Override + public double getBaseMaxInput() { + return 32; + } + + +} diff --git a/src/main/resources/assets/techreborn/blockstates/machines/lighting/lamp_incandescent.json b/src/main/resources/assets/techreborn/blockstates/machines/lighting/lamp_incandescent.json new file mode 100644 index 000000000..135be13e4 --- /dev/null +++ b/src/main/resources/assets/techreborn/blockstates/machines/lighting/lamp_incandescent.json @@ -0,0 +1,39 @@ +{ + "forge_marker": 1, + "defaults": { + "transform": "forge:default-block", + "model": "techreborn:lamp_incandescent", + "textures": { + "particle": "#lamp" + } + }, + "variants": { + "inventory": { + "transform": "forge:default-block", + "model": "techreborn:lamp_incandescent", + "textures": { + "lamp": "techreborn:blocks/machines/lighting/lamp" + } + }, + "facing": { + "down": { "x": 180 }, + "up": { "transform": "forge:default-block" }, + "north": { "x": 90 }, + "south": { "x": 270 }, + "west": { "x": 90, "y": 270 }, + "east": { "x": 90, "y": 90 } + }, + "active": { + "true": { + "textures": { + "lamp": "techreborn:blocks/machines/lighting/lamp_lit" + } + }, + "false": { + "textures": { + "lamp": "techreborn:blocks/machines/lighting/lamp" + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/blockstates/machines/lighting/lamp_led.json b/src/main/resources/assets/techreborn/blockstates/machines/lighting/lamp_led.json new file mode 100644 index 000000000..363aca230 --- /dev/null +++ b/src/main/resources/assets/techreborn/blockstates/machines/lighting/lamp_led.json @@ -0,0 +1,39 @@ +{ + "forge_marker": 1, + "defaults": { + "transform": "forge:default-block", + "model": "techreborn:lamp_led", + "textures": { + "particle": "#lamp" + } + }, + "variants": { + "inventory": { + "transform": "forge:default-block", + "model": "techreborn:lamp_led", + "textures": { + "lamp": "techreborn:blocks/machines/lighting/lamp" + } + }, + "facing": { + "down": { "x": 180 }, + "up": { "transform": "forge:default-block" }, + "north": { "x": 90 }, + "south": { "x": 270 }, + "west": { "x": 90, "y": 270 }, + "east": { "x": 90, "y": 90 } + }, + "active": { + "true": { + "textures": { + "lamp": "techreborn:blocks/machines/lighting/lamp_lit" + } + }, + "false": { + "textures": { + "lamp": "techreborn:blocks/machines/lighting/lamp" + } + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/models/block/lamp_incandescent.json b/src/main/resources/assets/techreborn/models/block/lamp_incandescent.json new file mode 100644 index 000000000..b2ec82714 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/block/lamp_incandescent.json @@ -0,0 +1,33 @@ +{ + "textures": { + "0": "#lamp" + }, + "elements": [ + { + "name": "Lamp", + "from": [ 5, 0, 5 ], + "to": [ 11, 2, 11 ], + "faces": { + "down": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] }, + "up": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] }, + "north": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] }, + "south": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] }, + "west": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] }, + "east": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] } + } + }, + { + "name": "Lamp", + "from": [ 4, 2, 4 ], + "to": [ 12, 10, 12 ], + "faces": { + "down": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] }, + "up": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] }, + "north": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] }, + "south": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] }, + "west": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] }, + "east": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/models/block/lamp_led.json b/src/main/resources/assets/techreborn/models/block/lamp_led.json new file mode 100644 index 000000000..51b6f4970 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/block/lamp_led.json @@ -0,0 +1,20 @@ +{ + "textures": { + "0": "#lamp" + }, + "elements": [ + { + "name": "Lamp", + "from": [ 2, 0, 2 ], + "to": [ 14, 1, 14 ], + "faces": { + "down": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] }, + "up": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] }, + "north": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] }, + "south": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] }, + "west": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] }, + "east": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/textures/blocks/machines/lighting/lamp.png b/src/main/resources/assets/techreborn/textures/blocks/machines/lighting/lamp.png new file mode 100644 index 000000000..c2321c48e Binary files /dev/null and b/src/main/resources/assets/techreborn/textures/blocks/machines/lighting/lamp.png differ diff --git a/src/main/resources/assets/techreborn/textures/blocks/machines/lighting/lamp_lit.png b/src/main/resources/assets/techreborn/textures/blocks/machines/lighting/lamp_lit.png new file mode 100644 index 000000000..900672e0a Binary files /dev/null and b/src/main/resources/assets/techreborn/textures/blocks/machines/lighting/lamp_lit.png differ