Finished electric lights for now.

Fixed stairs lighting bug.
This commit is contained in:
brad-c committed 2013-08-20 20:21:28 +08:00
1 parent 68b6c2e81e
commit 980cb6fd5d
10 files changed
+133 -143

No files matched your search

@@ -21,7 +21,7 @@ public class MachineRecipes {
ItemStack red = new ItemStack(Item.dyePowder, 1, 1);
ItemStack green = new ItemStack(Item.dyePowder, 1, 2);
ItemStack blue = new ItemStack(Item.dyePowder, 1, 4);
//System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MachineRecipes.addRecipes: Adding painter recipe with output for item stack of " + painter.itemID);
GameRegistry.addShapedRecipe(painter, "bbb", "RGB", "bcb", 'b', industialBinder, 'R', red, 'G', green, 'B', blue, 'c', capacitor);
ItemStack reservoir = new ItemStack(blockReservoir.actualId, 1, 0);
@@ -37,6 +37,13 @@ public class MachineRecipes {
ItemStack fusedQuartz = new ItemStack(ModObject.blockFusedQuartz.actualId, 1, 0);
GameRegistry.addShapedRecipe(solarPanel, "qqq", "gig", "bcb", 'q', fusedQuartz, 'g', activatedGold, 'i', activatedIron, 'b', industialBinder,'c', capacitor);
ItemStack electricLight = new ItemStack(blockElectricLight.actualId,1,0);
ItemStack glowstone = new ItemStack(Item.glowstone);
GameRegistry.addShapedRecipe(electricLight, "bqb", "bgb", "bcb", 'q', fusedQuartz, 'g', glowstone, 'b', industialBinder,'c', capacitor);
}
}
@@ -11,6 +11,7 @@ import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.*;
@@ -57,6 +58,11 @@ public class BlockElectricLight extends Block implements ITileEntityProvider {
GameRegistry.registerBlock(this, ModObject.blockElectricLight.unlocalisedName);
GameRegistry.registerTileEntity(TileElectricLight.class, ModObject.blockElectricLight.unlocalisedName + "TileEntity");
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
return null;
}
@Override
public void registerIcons(IconRegister iconRegister) {
@@ -73,7 +79,8 @@ public class BlockElectricLight extends Block implements ITileEntityProvider {
if (te instanceof TileElectricLight) {
ForgeDirection onFace = ((TileElectricLight) te).getFace();
if(side == (onFace.offsetX == 0 ? onFace.getOpposite().ordinal() : onFace.ordinal())) {
return ((TileElectricLight) te).isOn() ? blockIcon : blockIconOff;
boolean on = blockAccess.getBlockMetadata(x, y, z) != 0;
return on ? blockIcon : blockIconOff;
}
return blockIconSide;
}
@@ -186,25 +193,14 @@ public class BlockElectricLight extends Block implements ITileEntityProvider {
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
System.out.println("BlockLightNode.breakBlock: ");
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
TileElectricLight te = (TileElectricLight) world.getBlockTileEntity(x, y, z);
if (te != null) {
System.out.println("BlockElectricLight.breakBlock: Got tile entity");
if (te != null) {
te.onBlockRemoved();
} else {
System.out.println("BlockElectricLight.breakBlock: No tile entity");
}
}
world.removeBlockTileEntity(x, y, z);
}
// @Override
// public boolean canPlaceBlockOnSide(World par1World, int x, int y, int z, int side) {
// ForgeDirection dir = ForgeDirection.getOrientation(side);
// ForgeDirection op = dir.getOpposite();
// return par1World.isBlockSolidOnSide(x + op.offsetX, y + op.offsetY, z + op.offsetZ, dir);
// }
@Override
public TileEntity createNewTileEntity(World world) {
return new TileElectricLight();
@@ -40,7 +40,7 @@ public class BlockLightNode extends Block implements ITileEntityProvider {
setLightOpacity(0);
setLightValue(0);
//setBlockBounds(0.45f, 0.45F, 0.45f, 0.55f, 0.55f, 0.55f);
setBlockBounds(0,0,0,0,0,0);
setBlockBounds(0, 0, 0, 0, 0, 0);
}
@Override
@@ -49,23 +49,24 @@ public class BlockLightNode extends Block implements ITileEntityProvider {
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess par1iBlockAccess, int par2, int par3, int par4) {
setBlockBounds(0,0,0,0,0,0);
}
@Override
public void setBlockBoundsForItemRender() {
setBlockBounds(0,0,0,0,0,0);
}
@Override
public boolean isBlockSolid(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) {
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) {
return false;
public boolean isBlockSolid(IBlockAccess iblockaccess, int x, int y, int z, int l) {
int blockID = iblockaccess.getBlockId(x, y, z);
if (blockID == this.blockID) {
return false;
} else {
return super.isBlockSolid(iblockaccess, x, y, z, l);
}
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
return null;
}
@Override
@@ -73,54 +74,6 @@ public class BlockLightNode extends Block implements ITileEntityProvider {
return true;
}
// @Override
// public MovingObjectPosition collisionRayTrace(World world, int x, int y,
// int z, Vec3 origin, Vec3 direction) {
// return null;
// }
// @Override
// public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int
// y, int z) {
// return null;
// }
public boolean canCollideCheck(int par1, boolean par2) {
return false;
}
public boolean isCollidable() {
return false;
}
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z,
AxisAlignedBB axisalignedbb, @SuppressWarnings("rawtypes") List arraylist,
Entity par7Entity) {
setBlockBounds(0,0,0,0,0,0);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist,
par7Entity);
setBlockBounds(0,0,0,0,0,0);
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int x, int y, int z) {
return AxisAlignedBB.getBoundingBox(x, y ,z , x, y , z);
}
@Override
@SideOnly(Side.CLIENT)
public boolean addBlockHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
return true;
}
@Override
@SideOnly(Side.CLIENT)
public boolean addBlockDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
return true;
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
TileLightNode te = (TileLightNode) world.getBlockTileEntity(x, y, z);
@@ -133,10 +86,16 @@ public class BlockLightNode extends Block implements ITileEntityProvider {
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
Block block = blocksList[world.getBlockId(x, y, z)];
if (block != null && block != this) {
if (block != null && block.blockID != blockID) {
return block.getLightValue(world, x, y, z);
}
return world.getBlockMetadata(x, y, z) > 0 ? 15 : 0;
int onVal = 15;
// TileEntity te = world.getBlockTileEntity(x, y, z);
// if(te instanceof TileLightNode && ((TileLightNode)te).isDiagnal) {
// System.out.println("BlockLightNode.getLightValue: ");
// onVal = 5;
// }
return world.getBlockMetadata(x, y, z) > 0 ? onVal : 0;
}
@Override
@@ -153,11 +112,6 @@ public class BlockLightNode extends Block implements ITileEntityProvider {
GameRegistry.registerTileEntity(TileLightNode.class, ModObject.blockLightNode.unlocalisedName + "TileEntity");
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public void registerIcons(IconRegister iconRegister) {
blockIcon = iconRegister.registerIcon("enderio:blockElectricLightFace");
@@ -17,21 +17,23 @@ public class ElectricLightRenderer implements ISimpleBlockRenderingHandler {
@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
// this is highly non thread safe but atm all rendereding is single threaded
// so it should be fine, i just really dont like it
// int renderId = EnderIO.blockElectricLight.renderId;
// EnderIO.blockElectricLight.renderId = 0;
// renderer.renderBlockAsItem(EnderIO.blockElectricLight, metadata, modelID)
// ;
// EnderIO.blockElectricLight.renderId = renderId;
BoundingBox bb = new BoundingBox(0, 0, 0, 1, 0.2, 1);
boolean doDraw = false;
if (!Tessellator.instance.isDrawing) {
doDraw = true;
Tessellator.instance.startDrawingQuads();
}
CubeRenderer.render(bb, block.getBlockTextureFromSide(0));
}
Icon[] textures = new Icon[6];
textures[0] = block.getBlockTextureFromSide(ForgeDirection.NORTH.ordinal());
textures[1] = block.getBlockTextureFromSide(ForgeDirection.SOUTH.ordinal());
textures[2] = block.getBlockTextureFromSide(ForgeDirection.DOWN.ordinal());
textures[3] = block.getBlockTextureFromSide(ForgeDirection.UP.ordinal());
textures[4] = block.getBlockTextureFromSide(ForgeDirection.WEST.ordinal());
textures[5] = block.getBlockTextureFromSide(ForgeDirection.EAST.ordinal());
CubeRenderer.render(bb, textures, null);
if (doDraw) {
Tessellator.instance.draw();
}
@@ -46,8 +48,7 @@ public class ElectricLightRenderer implements ISimpleBlockRenderingHandler {
bb = bb.translate(x, y, z);
RenderUtil.setTesselatorBrightness(world, x, y, z);
Icon[] textures = new Icon[6];
Icon[] textures = new Icon[6];
textures[0] = block.getBlockTexture(world, x, y, z, ForgeDirection.NORTH.ordinal());
textures[1] = block.getBlockTexture(world, x, y, z, ForgeDirection.SOUTH.ordinal());
textures[2] = block.getBlockTexture(world, x, y, z, ForgeDirection.UP.ordinal());
@@ -17,6 +17,7 @@ import crazypants.vecmath.Vector3d;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@@ -24,7 +25,7 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
private ForgeDirection face = ForgeDirection.DOWN;
public static final float MJ_USE_PER_TICK = 0.2f;
public static final float MJ_USE_PER_TICK = 0.05f;
protected PowerHandler powerHandler;
@@ -35,28 +36,23 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
private int[] lightNodeCoords;
private boolean updatingLightNodes = false;
private boolean lastActive = false;
public TileElectricLight() {
powerHandler = PowerHandlerUtil.createHandler(new BasicCapacitor(1, 6), this, Type.MACHINE);
powerHandler = PowerHandlerUtil.createHandler(Capacitors.BASIC_CAPACITOR.capacitor, this, Type.MACHINE);
}
public void onNeighborBlockChange(int blockID) {
//if (!updatingLightNodes) {
// updateLightNodes();
//}
init = true;
}
public void nodeNeighbourChanged(TileLightNode tileLightNode) {
//if (!updatingLightNodes) {
// updateLightNodes();
//}
init = true;
}
public void nodeRemoved(TileLightNode tileLightNode) {
if (!updatingLightNodes) {
//updateLightNodes();
init = true;
}
}
@@ -69,10 +65,6 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
this.face = face;
}
public boolean isOn() {
return blockMetadata > 0;
}
@Override
public void updateEntity() {
if (worldObj.isRemote) {
@@ -80,7 +72,10 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
}
boolean hasRedstone = hasRedstoneSignal();
float stored = powerHandler.getEnergyStored();
powerHandler.update();
powerHandler.setEnergy(stored);
if (hasRedstone) {
powerHandler.setEnergy(Math.max(0, powerHandler.getEnergyStored() - MJ_USE_PER_TICK));
}
@@ -91,14 +86,19 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
updateLightNodes();
}
if (isActivated && !isOn() || !isActivated && isOn() || init) {
if (isActivated && !lastActive || init) {
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, isActivated ? 1 : 0, 2);
for (TileLightNode ln : lightNodes) {
if (ln != null) {
worldObj.setBlockMetadataWithNotify(ln.xCoord, ln.yCoord, ln.zCoord, isActivated ? 1 : 0, 2);
worldObj.markBlockForUpdate(ln.xCoord, ln.yCoord, ln.zCoord);
worldObj.updateLightByType(EnumSkyBlock.Block, ln.xCoord, ln.yCoord, ln.zCoord);
}
}
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord);
init = false;
lastActive = isActivated;
}
}
@@ -171,35 +171,43 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
Vector3d offset = new Vector3d();
offset.set(diags[0]);
offset.add(diags[1]);
addNodeInDirection(offset.add(trans));
addNodeInDirection(offset.add(trans), true);
offset.set(diags[0]);
offset.sub(diags[1]);
addNodeInDirection(offset.add(trans));
addNodeInDirection(offset.add(trans), true);
offset.set(new Vector3d(diags[0]).negate());
offset.add(diags[1]);
addNodeInDirection(offset.add(trans));
addNodeInDirection(offset.add(trans), true);
offset.set(new Vector3d(diags[0]).negate());
offset.sub(diags[1]);
addNodeInDirection(offset.add(trans));
addNodeInDirection(offset.add(trans), true);
}
private void addNodeInDirection(Vector3d offset) {
private void addNodeInDirection(Vector3d offset) {
addNodeInDirection(offset, false);
}
private void addNodeInDirection(Vector3d offset, boolean isDiag) {
boolean isAir = isAir(offset);
boolean isTransp = isTranparent(offset);
if (isAir || isTransp) {
offset.scale(2);
if (isAir(offset)) {
addLightNode(offset);
if (isAir(offset)) {
addLightNode(offset, isDiag);
} else if (isAir) {
offset.scale(0.5);
addLightNode(offset);
offset.scale(0.5);
addLightNode(offset, isDiag);
}
}
}
private boolean isLightNode(Vector3d offset) {
return worldObj.getBlockId(xCoord + (int) offset.x, yCoord + (int) offset.y, zCoord + (int) offset.z) == ModObject.blockLightNode.actualId;
}
private void clearLightNodes() {
@@ -211,15 +219,26 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
}
}
private void addLightNode(Vector3d offset) {
worldObj.setBlock(xCoord + (int) offset.x, yCoord + (int) offset.y, zCoord + (int) offset.z, ModObject.blockLightNode.actualId);
TileLightNode ln = (TileLightNode)worldObj.getBlockTileEntity(xCoord + (int) offset.x, yCoord + (int) offset.y, zCoord + (int) offset.z);
private void addLightNode(Vector3d offset, boolean isDiag) {
int x = xCoord + (int) offset.x;
int y = yCoord + (int) offset.y;
int z = zCoord + (int) offset.z;
if(isLightNode(offset)) {
TileLightNode te = (TileLightNode)worldObj.getBlockTileEntity(x,y,z);
if(te.parentX != xCoord || te.parentY != yCoord || te.parentZ != zCoord) {
//its somebody else's so leave it alone
return;
}
}
worldObj.setBlock(x,y,z, ModObject.blockLightNode.actualId);
TileLightNode ln = (TileLightNode)worldObj.getBlockTileEntity(x,y,z);
ln.parentX = xCoord;
ln.parentY = yCoord;
ln.parentZ = zCoord;
boolean isActivated = hasPower() && hasRedstoneSignal();
worldObj.setBlockMetadataWithNotify(ln.xCoord, ln.yCoord, ln.zCoord, isActivated ? 1 : 0, 2);
ln.isDiagnal = isDiag;
lightNodes.add(ln);
}
@@ -229,8 +248,7 @@ public class TileElectricLight extends TileEntity implements IInternalPowerRecep
}
private boolean isAir(Vector3d offset) {
return worldObj.isAirBlock(xCoord + (int) offset.x, yCoord + (int) offset.y, zCoord + (int) offset.z) ||
worldObj.getBlockId(xCoord + (int) offset.x, yCoord + (int) offset.y, zCoord + (int) offset.z) == ModObject.blockLightNode.actualId;
return worldObj.isAirBlock(xCoord + (int) offset.x, yCoord + (int) offset.y, zCoord + (int) offset.z) || isLightNode(offset);
}
@Override
@@ -3,6 +3,7 @@ package crazypants.enderio.machine.light;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
@@ -14,22 +15,35 @@ public class TileLightNode extends TileEntity {
int parentY;
int parentZ;
boolean isDiagnal = false;
public TileElectricLight getParent() {
TileEntity te = worldObj.getBlockTileEntity(parentX, parentY, parentZ);
if(te instanceof TileElectricLight) {
return (TileElectricLight)te;
}
return null;
}
@Override
public void updateEntity() {
if(worldObj.isRemote) {
return;
}
if(worldObj.getWorldTime() % 42 == 0) {
if(worldObj.getBlockId(parentX, parentY, parentZ) != ModObject.blockElectricLight.actualId) {
System.out.println("TileLightNode.updateEntity: ");
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
}
}
// public int getLightValue() {
// TileElectricLight p = getParent();
// if(p == null) {
// return 0;
// }
// return EnderIO.blockElectricLight.getLightValue(worldObj, parentX, parentY, parentZ);
// }
public void onNeighbourChanged() {
TileElectricLight p = getParent();
if(p != null) {
@@ -50,6 +64,7 @@ public class TileLightNode extends TileEntity {
parentX = root.getInteger("parentX");
parentY = root.getInteger("parentY");
parentZ = root.getInteger("parentZ");
isDiagnal = root.getBoolean("isDiagnal");
}
@Override
@@ -58,17 +73,15 @@ public class TileLightNode extends TileEntity {
root.setInteger("parentX", parentX);
root.setInteger("parentY", parentY);
root.setInteger("parentZ", parentZ);
root.setBoolean("isDiagnal", isDiagnal);
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox() {
return null;
public String toString() {
return "TileLightNode [parentX=" + parentX + ", parentY=" + parentY + ", parentZ=" + parentZ + ", isDiagnal=" + isDiagnal + ", xCoord=" + xCoord
+ ", yCoord=" + yCoord + ", zCoord=" + zCoord + ", tileEntityInvalid=" + tileEntityInvalid + "]";
}
}
@@ -28,6 +28,7 @@ public class BlockCustomStair extends BlockStairs implements ITileEntityProvider
super(ModObject.blockCustomStair.actualId, Block.brick, 0);
setCreativeTab(null);
setUnlocalizedName(ModObject.blockCustomStair.unlocalisedName);
setLightOpacity(0);
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 396 B

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 B

After

Width:  |  Height:  |  Size: 276 B