diff options
| author | Foghrye4 <foghrye4@gmail.com> | 2017-03-21 17:34:07 +0300 |
|---|---|---|
| committer | Foghrye4 <foghrye4@gmail.com> | 2017-03-21 17:34:07 +0300 |
| commit | 7305ba719930ea3fbf8aa987aeec48b33cdbd82e (patch) | |
| tree | 2307517925d965cd9228c8649013b07639987846 /ihl/enviroment | |
| parent | 5cb4c6e24033cf337812390d99a6817d24d21eab (diff) | |
Oregen
Diffstat (limited to 'ihl/enviroment')
| -rw-r--r-- | ihl/enviroment/LightBulbBlock.java | 185 | ||||
| -rw-r--r-- | ihl/enviroment/LightBulbTileEntity.java | 361 | ||||
| -rw-r--r-- | ihl/enviroment/SpotlightTileEntity.java | 4 |
3 files changed, 236 insertions, 314 deletions
diff --git a/ihl/enviroment/LightBulbBlock.java b/ihl/enviroment/LightBulbBlock.java index d78b667..77ee8f8 100644 --- a/ihl/enviroment/LightBulbBlock.java +++ b/ihl/enviroment/LightBulbBlock.java @@ -13,30 +13,26 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
-public class LightBulbBlock extends Block implements ITileEntityProvider
-{
+public class LightBulbBlock extends Block implements ITileEntityProvider {
public static GlowningAirBlock glowningAir;
-
- public LightBulbBlock(String unlocalizedName1)
- {
- super(Material.glass);
- this.setStepSound(soundTypeGlass);
+
+ public LightBulbBlock(String unlocalizedName1) {
+ super(Material.glass);
+ this.setStepSound(soundTypeGlass);
this.setBlockName(unlocalizedName1);
- GameRegistry.registerBlock(this,IHLItemBlock.class, unlocalizedName1);
- this.setHardness(0.3F);
- this.setResistance(0.5F);
- this.setCreativeTab(IHLCreativeTab.tab);
- this.setBlockTextureName("glass");
- }
-
+ GameRegistry.registerBlock(this, IHLItemBlock.class, unlocalizedName1);
+ this.setHardness(0.3F);
+ this.setResistance(0.5F);
+ this.setCreativeTab(IHLCreativeTab.tab);
+ this.setBlockTextureName("glass");
+ }
+
@Override
- public boolean hasTileEntity(int metadata)
- {
- return true;
+ public boolean hasTileEntity(int metadata) {
+ return true;
}
-
- public static void init()
- {
+
+ public static void init() {
glowningAir = new GlowningAirBlock();
new LightBulbBlock("lightBulb");
new SpotlightBlock("spotlight");
@@ -46,88 +42,77 @@ public class LightBulbBlock extends Block implements ITileEntityProvider SpotlightTileEntity.createLightSphereVectors();
}
- /**
- * Returns the quantity of items to drop on block destruction.
- */
- @Override
- public int quantityDropped(Random random)
- {
- return 0;
- }
-
- @Override
- public boolean renderAsNormalBlock()
- {
- return false;
- }
-
- /**
- * The type of render function that is called for this block
- */
- @Override
- public int getRenderType()
- {
- return -2;
- }
-
- @Override
- public void setBlockBoundsBasedOnState(IBlockAccess iBlockAccess, int x, int y, int z)
- {
- TileEntity te = iBlockAccess.getTileEntity(x, y, z);
- if(te!=null && te instanceof LightBulbTileEntity)
- {
- LightBulbTileEntity ate = (LightBulbTileEntity) te;
- setBlockBoundsBasedOnFacing(ate.getFacing());
- }
- }
-
- private void setBlockBoundsBasedOnFacing(int facing)
- {
- int var2 = facing & 7;
- float var6 = 0.1875F;
- float var7 = 0.5F;
-
- if (var2 == 0)
- {
- this.setBlockBounds(0.5F - var6, 1.0F - var7, 0.5F - var6, 0.5F + var6, 1.0F, 0.5F + var6);
- }
- else if (var2 == 1)
- {
- this.setBlockBounds(0.5F - var6, 0.0F, 0.5F - var6, 0.5F + var6, var7, 0.5F + var6);
- }
- else if (var2 == 2)
- {
- this.setBlockBounds(0.5F - var6, 0.5F - var6, 1.0F - var7, 0.5F + var6, 0.5F + var6, 1.0F);
- }
- else if (var2 == 3)
- {
- this.setBlockBounds(0.5F - var6, 0.5F - var6, 0.0F, 0.5F + var6, 0.5F + var6, var7);
- }
- else if (var2 == 4)
- {
- this.setBlockBounds(1.0F - var7, 0.5F - var6, 0.5F - var6, 1.0F, 0.5F + var6, 0.5F + var6);
- }
- else if (var2 == 5)
- {
- this.setBlockBounds(0.0F, 0.5F - var6, 0.5F - var6, var7, 0.5F + var6, 0.5F + var6);
- }
- }
-
- @Override
- public boolean isOpaqueCube()
- {
- return false;
- }
-
- @Override
- public boolean isNormalCube()
- {
- return false;
- }
+ /**
+ * Returns the quantity of items to drop on block destruction.
+ */
+ @Override
+ public int quantityDropped(Random random) {
+ return 0;
+ }
+
+ @Override
+ public boolean renderAsNormalBlock() {
+ return false;
+ }
+
+ /**
+ * The type of render function that is called for this block
+ */
+ @Override
+ public int getRenderType() {
+ return -2;
+ }
+
+ @Override
+ public void setBlockBoundsBasedOnState(IBlockAccess iBlockAccess, int x, int y, int z) {
+ TileEntity te = iBlockAccess.getTileEntity(x, y, z);
+ if (te != null && te instanceof LightBulbTileEntity) {
+ LightBulbTileEntity ate = (LightBulbTileEntity) te;
+ setBlockBoundsBasedOnFacing(ate.getFacing());
+ }
+ }
+
+ private void setBlockBoundsBasedOnFacing(int facing) {
+ int var2 = facing & 7;
+ float var6 = 0.1875F;
+ float var7 = 0.5F;
+
+ if (var2 == 0) {
+ this.setBlockBounds(0.5F - var6, 1.0F - var7, 0.5F - var6, 0.5F + var6, 1.0F, 0.5F + var6);
+ } else if (var2 == 1) {
+ this.setBlockBounds(0.5F - var6, 0.0F, 0.5F - var6, 0.5F + var6, var7, 0.5F + var6);
+ } else if (var2 == 2) {
+ this.setBlockBounds(0.5F - var6, 0.5F - var6, 1.0F - var7, 0.5F + var6, 0.5F + var6, 1.0F);
+ } else if (var2 == 3) {
+ this.setBlockBounds(0.5F - var6, 0.5F - var6, 0.0F, 0.5F + var6, 0.5F + var6, var7);
+ } else if (var2 == 4) {
+ this.setBlockBounds(1.0F - var7, 0.5F - var6, 0.5F - var6, 1.0F, 0.5F + var6, 0.5F + var6);
+ } else if (var2 == 5) {
+ this.setBlockBounds(0.0F, 0.5F - var6, 0.5F - var6, var7, 0.5F + var6, 0.5F + var6);
+ }
+ }
@Override
- public TileEntity createNewTileEntity(World arg0, int arg1)
- {
+ public boolean isOpaqueCube() {
+ return false;
+ }
+
+ @Override
+ public boolean isNormalCube() {
+ return false;
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World arg0, int arg1) {
return new LightBulbTileEntity();
}
+
+ public int getLightValue(IBlockAccess world, int x, int y, int z) {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (te != null && te instanceof LightBulbTileEntity) {
+ LightBulbTileEntity ate = (LightBulbTileEntity) te;
+ return ate.getActive() ? 15 : 0;
+ }
+ return 0;
+ }
}
diff --git a/ihl/enviroment/LightBulbTileEntity.java b/ihl/enviroment/LightBulbTileEntity.java index c82bc57..283a72f 100644 --- a/ihl/enviroment/LightBulbTileEntity.java +++ b/ihl/enviroment/LightBulbTileEntity.java @@ -3,7 +3,6 @@ package ihl.enviroment; import java.util.List;
import java.util.Vector;
-import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -20,229 +19,176 @@ import ic2.core.IC2; import ic2.core.ITickCallback;
import ihl.utils.IHLUtils;
-public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWrenchable, INetworkDataProvider
-{
- private boolean active = false;
- private short facing = 0;
- public boolean prevActive = false;
- public short prevFacing = 0;
- private double maxEnergy=1.1d;
+public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWrenchable, INetworkDataProvider {
+ private boolean active = false;
+ private short facing = 0;
+ public boolean prevActive = false;
+ public short prevFacing = 0;
private double energy;
- public boolean addedToEnergyNet = false;
+ public boolean addedToEnergyNet = false;
private boolean loaded = false;
private int ticker;
- @Override
- public void readFromNBT(NBTTagCompound nbttagcompound)
- {
- super.readFromNBT(nbttagcompound);
- this.energy = nbttagcompound.getDouble("energy");
- this.facing = nbttagcompound.getShort("facing");
- }
+ @Override
+ public void readFromNBT(NBTTagCompound nbttagcompound) {
+ super.readFromNBT(nbttagcompound);
+ this.energy = nbttagcompound.getDouble("energy");
+ this.facing = nbttagcompound.getShort("facing");
+ }
- @Override
- public void writeToNBT(NBTTagCompound nbttagcompound)
- {
- super.writeToNBT(nbttagcompound);
- nbttagcompound.setDouble("energy", this.energy);
- nbttagcompound.setShort("facing", this.facing);
- }
+ @Override
+ public void writeToNBT(NBTTagCompound nbttagcompound) {
+ super.writeToNBT(nbttagcompound);
+ nbttagcompound.setDouble("energy", this.energy);
+ nbttagcompound.setShort("facing", this.facing);
+ }
- /**
- * validates a tile entity
- */
- @Override
- public void validate()
- {
- super.validate();
- IC2.tickHandler.addSingleTickCallback(this.worldObj, new ITickCallback()
- {
- @SuppressWarnings("unchecked")
+ /**
+ * validates a tile entity
+ */
+ @Override
+ public void validate() {
+ super.validate();
+ IC2.tickHandler.addSingleTickCallback(this.worldObj, new ITickCallback() {
+ @SuppressWarnings("unchecked")
@Override
- public void tickCallback(World world)
- {
- if (!LightBulbTileEntity.this.isInvalid() && world.blockExists(LightBulbTileEntity.this.xCoord, LightBulbTileEntity.this.yCoord, LightBulbTileEntity.this.zCoord))
- {
- LightBulbTileEntity.this.onLoaded();
+ public void tickCallback(World world) {
+ if (!LightBulbTileEntity.this.isInvalid() && world.blockExists(LightBulbTileEntity.this.xCoord,
+ LightBulbTileEntity.this.yCoord, LightBulbTileEntity.this.zCoord)) {
+ LightBulbTileEntity.this.onLoaded();
+
+ if (LightBulbTileEntity.this.enableUpdateEntity()) {
+ world.loadedTileEntityList.add(LightBulbTileEntity.this);
+ }
+ }
+ }
+ });
+ }
- if (LightBulbTileEntity.this.enableUpdateEntity())
- {
- world.loadedTileEntityList.add(LightBulbTileEntity.this);
- }
- }
- }
- });
- }
+ /**
+ * invalidates a tile entity
+ */
+ @Override
+ public void invalidate() {
+ super.invalidate();
+ if (this.loaded) {
+ this.onUnloaded();
+ }
+ }
- /**
- * invalidates a tile entity
- */
- @Override
- public void invalidate()
- {
- super.invalidate();
- if (this.loaded)
- {
- this.onUnloaded();
- }
- }
+ @Override
+ public void onChunkUnload() {
+ super.onChunkUnload();
+ if (this.loaded) {
+ this.onUnloaded();
+ }
+ }
- @Override
- public void onChunkUnload()
- {
- super.onChunkUnload();
- if (this.loaded)
- {
- this.onUnloaded();
- }
- }
+ public void onLoaded() {
+ if (IC2.platform.isSimulating() && !this.addedToEnergyNet) {
+ MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
+ this.addedToEnergyNet = true;
+ }
+ this.loaded = true;
+ }
- public void onLoaded()
- {
- if (IC2.platform.isSimulating() && !this.addedToEnergyNet)
- {
- MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
- this.addedToEnergyNet = true;
- }
- this.loaded = true;
- }
+ public void onUnloaded() {
+ if (IC2.platform.isSimulating()) {
+ if (this.addedToEnergyNet) {
+ MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
+ this.addedToEnergyNet = false;
+ }
+ this.active = false;
+ this.updateLightState(true);
+ }
+ }
- public void onUnloaded()
- {
- if (IC2.platform.isSimulating())
- {
- if(this.addedToEnergyNet)
- {
- MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
- this.addedToEnergyNet = false;
- }
- this.active=false;
- this.updateLightState();
- }
- }
+ @Override
+ public final boolean canUpdate() {
+ return false;
+ }
- @Override
- public final boolean canUpdate()
- {
- return false;
- }
-
- @Override
- public void updateEntity()
- {
- if(++this.ticker % 4 == 0)
- {
- if(this.prevFacing != facing)
- {
+ @Override
+ public void updateEntity() {
+ if (++this.ticker % 4 == 0) {
+ if (this.prevFacing != facing) {
this.setFacing(facing);
}
- if(this.energy>0)
- {
+ if (this.energy > 0) {
this.energy--;
- this.setActive(this.energy>0);
- }
- else
- {
+ this.setActive(true);
+ } else {
this.setActive(false);
}
}
- }
-
- protected void updateLightState()
- {
- int x,y,z;
- int xyz[] = {0,0,1,0,0,-1,0,0};
- Block block;
- for(int i=0;i<=5;i++)
- {
- x=xCoord+xyz[i];
- y=yCoord+xyz[i+1];
- z=zCoord+xyz[i+2];
- block = this.worldObj.getBlock(x,y,z);
- if(block.isAir(this.worldObj, x,y,z))
- {
- if(this.getActive())
- {
- worldObj.setBlock(x, y, z, LightBulbBlock.glowningAir);
- }
- if(!this.getActive())
- {
- worldObj.setBlockToAir(x, y, z);
- }
- }
+ }
+
+ protected void updateLightState(boolean spreadDarkness) {
+ if (IC2.platform.isSimulating()) {
+ worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
-
- public boolean enableUpdateEntity()
- {
- return IC2.platform.isSimulating();
- }
-
+
+ public boolean enableUpdateEntity() {
+ return IC2.platform.isSimulating();
+ }
+
@Override
- public boolean acceptsEnergyFrom(TileEntity emitter,
- ForgeDirection direction) {
- switch(direction)
- {
+ public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
+ switch (direction) {
case UP:
- return this.getFacing()==0;
+ return this.getFacing() == 0;
case DOWN:
- return this.getFacing()==1;
+ return this.getFacing() == 1;
case SOUTH:
- return this.getFacing()==2;
+ return this.getFacing() == 2;
case NORTH:
- return this.getFacing()==3;
+ return this.getFacing() == 3;
case EAST:
- return this.getFacing()==4;
+ return this.getFacing() == 4;
case WEST:
- return this.getFacing()==5;
+ return this.getFacing() == 5;
default:
return false;
}
}
@Override
- public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
- {
+ public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public short getFacing() {
- return this.facing;
+ return this.facing;
}
@Override
- public void setFacing(short facing1)
- {
- if (IC2.platform.isSimulating()&&this.addedToEnergyNet)
- {
- MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
- this.addedToEnergyNet = false;
- }
- this.facing=facing1;
- if(IC2.platform.isSimulating())
- {
- if (this.prevFacing != facing)
- {
- IC2.network.get().updateTileEntityField(this, "facing");
- }
+ public void setFacing(short facing1) {
+ if (IC2.platform.isSimulating() && this.addedToEnergyNet) {
+ MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
+ this.addedToEnergyNet = false;
+ }
+ this.facing = facing1;
+ if (IC2.platform.isSimulating()) {
+ if (this.prevFacing != facing) {
+ IC2.network.get().updateTileEntityField(this, "facing");
+ }
}
this.prevFacing = facing;
- if (IC2.platform.isSimulating()&&!this.addedToEnergyNet)
- {
- MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
- this.addedToEnergyNet = true;
- }
+ if (IC2.platform.isSimulating() && !this.addedToEnergyNet) {
+ MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
+ this.addedToEnergyNet = true;
+ }
+ }
+
+ @Override
+ public List<String> getNetworkedFields() {
+ Vector<String> ret = new Vector<String>(2);
+ ret.add("active");
+ ret.add("facing");
+ return ret;
}
-
- @Override
- public List<String> getNetworkedFields()
- {
- Vector<String> ret = new Vector<String>(2);
- ret.add("active");
- ret.add("facing");
- return ret;
- }
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
@@ -260,9 +206,11 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre }
@Override
- public double getDemandedEnergy()
- {
- return this.maxEnergy-this.energy;
+ public double getDemandedEnergy() {
+ if (energy > 10d) {
+ return 0d;
+ }
+ return Integer.MAX_VALUE;
}
@Override
@@ -271,38 +219,27 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre }
@Override
- public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
- {
- if (this.energy >= this.maxEnergy)
- {
- return amount;
- }
- else
- {
- this.energy += amount;
- return 0.0D;
- }
+ public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
+ this.energy += amount;
+ return 0.0D;
}
- public boolean getActive()
- {
- return this.active;
- }
+ public boolean getActive() {
+ return this.active;
+ }
- public void setActive(boolean active1)
- {
- this.active = active1;
+ public void setActive(boolean active1) {
+ this.active = active1;
- if (this.prevActive != active1)
- {
- IC2.network.get().updateTileEntityField(this, "active");
- updateLightState();
- }
- this.prevActive = active1;
- }
- public void setActiveWithoutNotify(boolean active1)
- {
- this.active = active1;
- this.prevActive = active1;
- }
+ if (this.prevActive != active1) {
+ IC2.network.get().updateTileEntityField(this, "active");
+ updateLightState(!active1);
+ }
+ this.prevActive = active1;
+ }
+
+ public void setActiveWithoutNotify(boolean active1) {
+ this.active = active1;
+ this.prevActive = active1;
+ }
}
diff --git a/ihl/enviroment/SpotlightTileEntity.java b/ihl/enviroment/SpotlightTileEntity.java index ab18ebe..287ef9f 100644 --- a/ihl/enviroment/SpotlightTileEntity.java +++ b/ihl/enviroment/SpotlightTileEntity.java @@ -111,7 +111,7 @@ public class SpotlightTileEntity extends LightBulbTileEntity implements INetwork if(needLightTargetUpdate)
{
this.generateGlowningAirList();
- this.updateLightState();
+ this.updateLightState(this.getActive());
needLightTargetUpdate=false;
}
if(this.prevRotationPitch!=this.rotationPitch)
@@ -214,7 +214,7 @@ public class SpotlightTileEntity extends LightBulbTileEntity implements INetwork }
@Override
- protected void updateLightState()
+ protected void updateLightState(boolean spreadDarkness)
{
if(this.getActive())
{
|
