Added Light Detector

This commit is contained in:
AlgorithmX2 2014-07-15 20:26:04 -05:00
parent 9c9598c6fb
commit 862c89e1f0
7 changed files with 134 additions and 11 deletions

View file

@ -12,6 +12,7 @@ import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.misc.BlockLightDetector;
import appeng.block.misc.BlockSkyCompass;
import appeng.block.networking.BlockWireless;
import appeng.client.render.ItemRenderer;
@ -63,7 +64,15 @@ public class AEBaseItemBlock extends ItemBlock
if ( blockType.hasBlockTileEntity() )
{
if ( blockType instanceof BlockWireless || blockType instanceof BlockSkyCompass )
if ( blockType instanceof BlockLightDetector )
{
up = ForgeDirection.getOrientation( side );
if ( up == ForgeDirection.UP || up == ForgeDirection.DOWN )
forward = ForgeDirection.SOUTH;
else
forward = ForgeDirection.UP;
}
else if ( blockType instanceof BlockWireless || blockType instanceof BlockSkyCompass )
{
forward = ForgeDirection.getOrientation( side );
if ( forward == ForgeDirection.UP || forward == ForgeDirection.DOWN )
@ -123,7 +132,7 @@ public class AEBaseItemBlock extends ItemBlock
if ( super.placeBlockAt( stack, player, w, x, y, z, side, hitX, hitY, hitZ, metadata ) )
{
if ( blockType.hasBlockTileEntity() )
if ( blockType.hasBlockTileEntity() && !(blockType instanceof BlockLightDetector) )
{
AEBaseTile tile = blockType.getTileEntity( w, x, y, z );
ori = tile;

View file

@ -0,0 +1,48 @@
package appeng.block.misc;
import java.util.EnumSet;
import java.util.Random;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import appeng.core.features.AEFeature;
import appeng.tile.misc.TileLightDetector;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockLightDetector extends BlockQuartzTorch
{
public BlockLightDetector() {
super( BlockLightDetector.class );
setfeature( EnumSet.of( AEFeature.LightDetector ) );
setTileEntiy( TileLightDetector.class );
}
@Override
public void onNeighborChange(IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ)
{
super.onNeighborChange( world, x, y, z, tileX, tileY, tileZ );
TileLightDetector tld = getTileEntity( world, x, y, z );
if ( tld != null )
tld.updateLight();
}
@Override
public int isProvidingWeakPower(IBlockAccess w, int x, int y, int z, int side)
{
if ( w instanceof World && ((TileLightDetector) getTileEntity( w, x, y, z )).isReady() )
return (int) ((World) w).getBlockLightValue( x, y, z ) - 6;
return 0;
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World w, int x, int y, int z, Random r)
{
// cancel out lightning
}
}

View file

@ -31,14 +31,18 @@ import cpw.mods.fml.relauncher.SideOnly;
public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, ICustomCollision
{
public BlockQuartzTorch() {
super( BlockQuartzTorch.class, Material.circuits );
setfeature( EnumSet.of( AEFeature.DecorativeLights ) );
protected BlockQuartzTorch(Class which) {
super( which, Material.circuits );
setLightOpacity( 0 );
setLightLevel( 0.9375F );
isFullSize = isOpaque = false;
}
public BlockQuartzTorch() {
this( BlockQuartzTorch.class );
setfeature( EnumSet.of( AEFeature.DecorativeLights ) );
setLightLevel( 0.9375F );
}
@Override
protected Class<? extends BaseBlockRender> getRenderer()
{
@ -100,9 +104,8 @@ public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, I
public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e)
{/*
* double xOff = -0.15 * getUp().offsetX; double yOff = -0.15 * getUp().offsetY; double zOff = -0.15 *
* getUp().offsetZ; out.add( AxisAlignedBB.getBoundingBox( xOff + (double) x + 0.15, yOff + (double) y +
* 0.15, zOff + (double) z + 0.15,// ahh xOff + (double) x + 0.85, yOff + (double) y + 0.85, zOff + (double) z +
* 0.85 ) );
* getUp().offsetZ; out.add( AxisAlignedBB.getBoundingBox( xOff + (double) x + 0.15, yOff + (double) y + 0.15, zOff
* + (double) z + 0.15,// ahh xOff + (double) x + 0.85, yOff + (double) y + 0.85, zOff + (double) z + 0.85 ) );
*/
}

View file

@ -10,6 +10,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseBlock;
import appeng.block.misc.BlockQuartzTorch;
import appeng.client.render.BaseBlockRender;
@ -78,7 +79,7 @@ public class RenderQuartzTorch extends BaseBlockRender
{
BlockQuartzTorch blk = (BlockQuartzTorch) block;
IOrientable te = getOrientable( block, world, x, y, z );
IOrientable te = ((IOrientableBlock) block).getOrientable( world, x, y, z );
float Point2 = 6.0f / 16.0f;
float Point3 = 7.0f / 16.0f;

View file

@ -42,6 +42,7 @@ import appeng.block.misc.BlockCharger;
import appeng.block.misc.BlockCondenser;
import appeng.block.misc.BlockInscriber;
import appeng.block.misc.BlockInterface;
import appeng.block.misc.BlockLightDetector;
import appeng.block.misc.BlockQuartzGrowthAccelerator;
import appeng.block.misc.BlockQuartzTorch;
import appeng.block.misc.BlockSecurity;
@ -310,6 +311,7 @@ public class Registration
blocks.blockQuartzPiller = addFeature( BlockQuartzPillar.class );
blocks.blockQuartzChiseled = addFeature( BlockQuartzChiseled.class );
blocks.blockQuartzTorch = addFeature( BlockQuartzTorch.class );
blocks.blockLightDetector = addFeature( BlockLightDetector.class );
blocks.blockCharger = addFeature( BlockCharger.class );
blocks.blockQuartzGrowthAccelerator = addFeature( BlockQuartzGrowthAccelerator.class );

View file

@ -52,7 +52,7 @@ public enum AEFeature
enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false),
AlphaPass("Rendering"), PaintBalls("Tools"), PacketLogging("Misc", false), CraftingLog("Misc", false), InterfaceTerminal("Crafting");
AlphaPass("Rendering"), PaintBalls("Tools"), PacketLogging("Misc", false), CraftingLog("Misc", false), InterfaceTerminal("Crafting"), LightDetector("Misc");
String Category;
boolean visible = true;

View file

@ -0,0 +1,60 @@
package appeng.tile.misc;
import appeng.tile.AEBaseTile;
import appeng.tile.events.AETileEventHandler;
import appeng.tile.events.TileEventType;
import appeng.util.Platform;
public class TileLightDetector extends AEBaseTile
{
int lastCheck = 30;
int lastLight = 0;
public boolean isReady()
{
return lastLight > 0;
}
class LightDetectorHandler extends AETileEventHandler
{
public LightDetectorHandler() {
super( TileEventType.TICK );
}
@Override
public void Tick()
{
lastCheck++;
if ( lastCheck > 30 )
{
lastCheck = 0;
updateLight();
}
}
};
public TileLightDetector() {
addNewHandler( new LightDetectorHandler() );
}
public void updateLight()
{
int val = worldObj.getBlockLightValue( xCoord, yCoord, zCoord );
if ( lastLight != val )
{
lastLight = val;
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord );
}
}
@Override
public boolean canBeRotated()
{
return false;
}
}