Implement powered lighting.

This commit is contained in:
Alistair Buxton 2017-10-13 18:40:36 +01:00 committed by drcrazy
parent db9da00fec
commit 642e6b0f2b
10 changed files with 407 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -43,6 +43,7 @@ import techreborn.blocks.generator.*;
import techreborn.blocks.generator.solarpanel.BlockSolarPanel; import techreborn.blocks.generator.solarpanel.BlockSolarPanel;
import techreborn.blocks.iron_machines.BlockIronAlloyFurnace; import techreborn.blocks.iron_machines.BlockIronAlloyFurnace;
import techreborn.blocks.iron_machines.BlockIronFurnace; import techreborn.blocks.iron_machines.BlockIronFurnace;
import techreborn.blocks.lighting.BlockLamp;
import techreborn.blocks.machine.*; import techreborn.blocks.machine.*;
import techreborn.blocks.storage.*; import techreborn.blocks.storage.*;
import techreborn.blocks.tier1.*; import techreborn.blocks.tier1.*;
@ -58,6 +59,7 @@ import techreborn.tiles.generator.*;
import techreborn.tiles.idsu.TileInterdimensionalSU; import techreborn.tiles.idsu.TileInterdimensionalSU;
import techreborn.tiles.lesu.TileLSUStorage; import techreborn.tiles.lesu.TileLSUStorage;
import techreborn.tiles.lesu.TileLapotronicSU; import techreborn.tiles.lesu.TileLapotronicSU;
import techreborn.tiles.lighting.TileLamp;
import techreborn.tiles.multiblock.*; import techreborn.tiles.multiblock.*;
import techreborn.tiles.storage.TileHighVoltageSU; import techreborn.tiles.storage.TileHighVoltageSU;
import techreborn.tiles.storage.TileLowVoltageSU; import techreborn.tiles.storage.TileLowVoltageSU;
@ -148,6 +150,10 @@ public class ModBlocks {
public static Block COMPUTER_CUBE; public static Block COMPUTER_CUBE;
public static Block PLASMA_GENERATOR; public static Block PLASMA_GENERATOR;
public static Block LAMP_INCANDESCENT;
public static Block LAMP_LED;
public static Block LAMP_LED_LARGE;
/** /**
* Register blocks * Register blocks
*/ */
@ -414,6 +420,14 @@ public class ModBlocks {
registerBlock(PLASMA_GENERATOR, "plasma_generator"); registerBlock(PLASMA_GENERATOR, "plasma_generator");
GameRegistry.registerTileEntity(TilePlasmaGenerator.class, "TilePlasmalGeneratorTR"); 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 //TODO enable when done
// flare = new BlockFlare(); // flare = new BlockFlare();
// registerBlock(flare, "flare"); // registerBlock(flare, "flare");

View file

@ -172,6 +172,10 @@ public class CraftingTableRecipes extends RecipeMethods {
registerShaped(getStack(ModBlocks.QUANTUM_TANK), "EPE", "PCP", "EPE", 'P', "platePlatinum", 'E', "circuitAdvanced", 'C', getStack(ModBlocks.QUANTUM_CHEST)); 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 //Parts
registerShaped(getMaterial("iridium_alloy", Type.INGOT), "IAI", "ADA", "IAI", 'I', "ingotIridium", 'D', "dustDiamond", 'A', "plateAdvancedAlloy"); 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)); registerShaped(getStack(ModItems.RE_BATTERY), " W ", "TRT", "TRT", 'T', "ingotTin", 'R', "dustRedstone", 'W', getStack(IC2Duplicates.CABLE_ICOPPER));

View file

@ -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;
}
}

View file

@ -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"
}
}
}
}
}

View file

@ -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"
}
}
}
}
}

View file

@ -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] }
}
}
]
}

View file

@ -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] }
}
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B