diff options
Diffstat (limited to 'ihl/enviroment')
| -rw-r--r-- | ihl/enviroment/GlowningAirBlock.java | 34 | ||||
| -rw-r--r-- | ihl/enviroment/LightBulbBlock.java | 60 | ||||
| -rw-r--r-- | ihl/enviroment/LightBulbRender.java | 2 | ||||
| -rw-r--r-- | ihl/enviroment/LightBulbTileEntity.java | 88 | ||||
| -rw-r--r-- | ihl/enviroment/LightHandler.java | 76 | ||||
| -rw-r--r-- | ihl/enviroment/LightSource.java | 167 | ||||
| -rw-r--r-- | ihl/enviroment/SpotlightBlock.java | 49 | ||||
| -rw-r--r-- | ihl/enviroment/SpotlightRender.java | 1 | ||||
| -rw-r--r-- | ihl/enviroment/SpotlightTileEntity.java | 451 |
9 files changed, 493 insertions, 435 deletions
diff --git a/ihl/enviroment/GlowningAirBlock.java b/ihl/enviroment/GlowningAirBlock.java deleted file mode 100644 index e6dfb8e..0000000 --- a/ihl/enviroment/GlowningAirBlock.java +++ /dev/null @@ -1,34 +0,0 @@ -package ihl.enviroment;
-
-import net.minecraft.block.BlockAir;
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityLivingBase;
-import net.minecraft.entity.EnumCreatureAttribute;
-import net.minecraft.world.IBlockAccess;
-import net.minecraft.world.World;
-
-public class GlowningAirBlock extends BlockAir
-{
- public GlowningAirBlock()
- {
- super();
- this.setBlockName("glowningAir");
- this.setLightLevel(1.0f);
- this.setBlockTextureName("glass");
- }
-
- @Override
- public boolean isAir(IBlockAccess world, int x, int y, int z)
- {
- return true;
- }
-
- @Override
- public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity)
- {
- if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).getCreatureAttribute() == EnumCreatureAttribute.UNDEAD)
- {
- entity.setFire(20);
- }
- }
-}
diff --git a/ihl/enviroment/LightBulbBlock.java b/ihl/enviroment/LightBulbBlock.java index 720ca4e..7c95001 100644 --- a/ihl/enviroment/LightBulbBlock.java +++ b/ihl/enviroment/LightBulbBlock.java @@ -1,20 +1,29 @@ package ihl.enviroment;
+import java.util.List;
import java.util.Random;
import cpw.mods.fml.common.registry.GameRegistry;
-
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
import ihl.IHLCreativeTab;
+import ihl.flexible_cable.AnchorTileEntity;
import ihl.items_blocks.IHLItemBlock;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemDye;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class LightBulbBlock extends Block implements ITileEntityProvider {
- public static GlowningAirBlock glowningAir;
public LightBulbBlock(String unlocalizedName1) {
super(Material.glass);
@@ -25,7 +34,7 @@ public class LightBulbBlock extends Block implements ITileEntityProvider { this.setResistance(0.5F);
this.setCreativeTab(IHLCreativeTab.tab);
this.setBlockTextureName("glass");
- this.setLightOpacity(16);
+ this.setLightOpacity(0);
}
@Override
@@ -34,13 +43,22 @@ public class LightBulbBlock extends Block implements ITileEntityProvider { }
public static void init() {
- glowningAir = new GlowningAirBlock();
new LightBulbBlock("lightBulb");
new SpotlightBlock("spotlight");
- GameRegistry.registerBlock(glowningAir, "glowningAir");
GameRegistry.registerTileEntity(LightBulbTileEntity.class, "lightBulb");
GameRegistry.registerTileEntity(SpotlightTileEntity.class, "spotlight");
- SpotlightTileEntity.createLightSphereVectors();
+ }
+
+ @Override
+ public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
+ if (world.isRemote) {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (te != null && te instanceof LightBulbTileEntity) {
+ LightBulbTileEntity ate = (LightBulbTileEntity) te;
+ ate.invalidate();
+ }
+ }
+ super.onBlockPreDestroy(world, x, y, z, meta);
}
/**
@@ -73,6 +91,27 @@ public class LightBulbBlock extends Block implements ITileEntityProvider { }
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @SideOnly(Side.CLIENT)
+ public void getSubBlocks(Item item, CreativeTabs tab, List itemlist) {
+ for (int colour : ItemDye.field_150922_c) {
+ ItemStack stack = new ItemStack(item);
+ stack.stackTagCompound = new NBTTagCompound();
+ stack.stackTagCompound.setInteger("colour", colour);
+ itemlist.add(stack);
+ }
+ }
+
+ @Override
+ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
+ super.onBlockPlacedBy(world, x, y, z, player, stack);
+ if (!world.isRemote) {
+ TileEntity tile = world.getTileEntity(x, y, z);
+ if (tile instanceof LightBulbTileEntity && stack.stackTagCompound != null)
+ ((LightBulbTileEntity)tile).colour=stack.stackTagCompound.getInteger("colour");
+ }
+ }
+
private void setBlockBoundsBasedOnFacing(int facing) {
int var2 = facing & 7;
float var6 = 0.1875F;
@@ -109,11 +148,10 @@ public class LightBulbBlock extends Block implements ITileEntityProvider { }
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;
- }*/
+ TileEntity te = world.getTileEntity(x, y, z);
+ if(te instanceof LightBulbTileEntity && ((LightBulbTileEntity)te).getActive()){
+ return 15;
+ }
return 0;
}
}
diff --git a/ihl/enviroment/LightBulbRender.java b/ihl/enviroment/LightBulbRender.java index 97104f7..caa5f65 100644 --- a/ihl/enviroment/LightBulbRender.java +++ b/ihl/enviroment/LightBulbRender.java @@ -60,7 +60,7 @@ private final float scale=1F/16F; bindTexture(tex);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- GL11.glColor4f(1f, 1f, 1f, 1f);
+ GL11.glColor4f((cte.colour>>>16)/255f,((cte.colour>>>8)&255)/255f, (cte.colour&255)/255f,1f);
if(cte.getActive())
{
GL11.glDisable(GL11.GL_LIGHTING);
diff --git a/ihl/enviroment/LightBulbTileEntity.java b/ihl/enviroment/LightBulbTileEntity.java index f2c229b..8695bd7 100644 --- a/ihl/enviroment/LightBulbTileEntity.java +++ b/ihl/enviroment/LightBulbTileEntity.java @@ -26,7 +26,8 @@ import ihl.IHLModInfo; import ihl.model.RenderBlocksExt;
import ihl.utils.IHLUtils;
-public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWrenchable, INetworkDataProvider, INetworkTileEntityEventListener {
+public class LightBulbTileEntity extends TileEntity
+ implements IEnergySink, IWrenchable, INetworkDataProvider {
private boolean active = false;
private short facing = 0;
public boolean prevActive = false;
@@ -35,6 +36,8 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre public boolean addedToEnergyNet = false;
private boolean loaded = false;
private int ticker;
+ public int colour = 0xffffff;
+
@SideOnly(value = Side.CLIENT)
LightSource lightSource;
@@ -43,6 +46,7 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre super.readFromNBT(nbttagcompound);
this.energy = nbttagcompound.getDouble("energy");
this.facing = nbttagcompound.getShort("facing");
+ this.colour = nbttagcompound.getInteger("colour");
}
@Override
@@ -50,28 +54,7 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre 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")
- @Override
- 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);
- }
- }
- }
- });
+ nbttagcompound.setInteger("colour", this.colour);
}
/**
@@ -94,6 +77,9 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre }
public void onLoaded() {
+ if (!this.worldObj.isRemote) {
+ IC2.network.get().updateTileEntityField(this, "colour");
+ }
if (IC2.platform.isSimulating() && !this.addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true;
@@ -107,19 +93,28 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
this.addedToEnergyNet = false;
}
- this.active = false;
- this.updateLightState();
}
+ this.active = false;
+ this.updateLightState();
}
@Override
public final boolean canUpdate() {
- return false;
+ return true;
}
@Override
public void updateEntity() {
- if (++this.ticker % 4 == 0) {
+ if (this.worldObj.isRemote) {
+ if(this.prevActive != active){
+ updateLightState();
+ this.prevActive = active;
+ }
+ }
+ if(!this.loaded){
+ this.onLoaded();
+ }
+ if (!this.worldObj.isRemote && ++this.ticker % 4 == 0) {
if (this.prevFacing != facing) {
this.setFacing(facing);
}
@@ -136,9 +131,22 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre if (IC2.platform.isSimulating()) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
} else if (IC2.platform.isRendering()) {
- if (lightSource == null && this.getActive()) {
- lightSource = ((ClientProxy) IHLMod.proxy).getLightHandler().calculateOmniLightSource(worldObj, xCoord,
- yCoord, zCoord, 8096, 255, 255, 0);
+ if (this.getActive()) {
+ if(lightSource != null)
+ ((ClientProxy) IHLMod.proxy).getLightHandler().removeLightSource(lightSource);
+ int red = colour >>> 16;
+ int green = (colour >>> 8) & 255;
+ int blue = colour & 255;
+ int max = red;
+ if (max < green)
+ max = green;
+ if (max < blue)
+ max = blue;
+ max -= 255;
+ red -= max;// Normalize colours
+ blue -= max;
+ green -= max;
+ lightSource = this.createLightSource(red, green, blue);
((ClientProxy) IHLMod.proxy).getLightHandler().addLightSource(lightSource);
} else if (lightSource != null) {
((ClientProxy) IHLMod.proxy).getLightHandler().removeLightSource(lightSource);
@@ -147,8 +155,10 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre }
}
- public boolean enableUpdateEntity() {
- return IC2.platform.isSimulating();
+ @SideOnly(value = Side.CLIENT)
+ protected LightSource createLightSource(int red, int green, int blue) {
+ return ((ClientProxy) IHLMod.proxy).getLightHandler().calculateLightSource(worldObj, xCoord, yCoord, zCoord,
+ 64, red, green, blue, null);
}
@Override
@@ -205,6 +215,7 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre Vector<String> ret = new Vector<String>(2);
ret.add("active");
ret.add("facing");
+ ret.add("colour");
return ret;
}
@@ -250,7 +261,6 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre this.active = active1;
if (this.prevActive != active1) {
IC2.network.get().updateTileEntityField(this, "active");
- IC2.network.get().initiateTileEntityEvent(this, active1?1:0, true);
updateLightState();
}
this.prevActive = active1;
@@ -260,16 +270,4 @@ public class LightBulbTileEntity extends TileEntity implements IEnergySink, IWre this.active = active1;
this.prevActive = active1;
}
-
- @Override
- public void onNetworkEvent(int event)
- {
- boolean active1 = event==1;
- this.active = active1;
- if (this.prevActive != active1) {
- updateLightState();
- }
- this.prevActive = active1;
- }
-
}
diff --git a/ihl/enviroment/LightHandler.java b/ihl/enviroment/LightHandler.java index c89ffb7..31a921e 100644 --- a/ihl/enviroment/LightHandler.java +++ b/ihl/enviroment/LightHandler.java @@ -7,7 +7,9 @@ import java.util.Set; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ihl.IHLMod; +import ihl.utils.IHLMathUtils; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.world.World; @@ -41,27 +43,28 @@ public class LightHandler { ((l >>> lightBitsPerDimension) & bitmask) - maxLightRadius, (l & bitmask) - maxLightRadius }; } - public LightSource calculateOmniLightSource(World world, int sourceX, int sourceY, int sourceZ, int power, int red, - int green, int blue) { + public LightSource calculateLightSource(World world, int sourceX, int sourceY, int sourceZ, int power, int red, + int green, int blue, double[] ds) { LightSource lightSource = new LightSource(sourceX, sourceY, sourceZ, red, green, blue, power); int[] borders = { sourceX, sourceY, sourceZ, sourceX, sourceY, sourceZ }; int[] evSource = { sourceX, sourceY, sourceZ }; int[] lightSourceXYZ = { sourceX, sourceY, sourceZ }; for (int i = 0; i < directionMasks.length; i++) { int[] directionMask = directionMasks[i]; - this.litBlocksAndGetDescendants(world, evSource, lightSourceXYZ, lightSource.illuminatedBlocks, 0, power, - directionMask, borders); + this.litBlocksAndGetDescendants(world, evSource, lightSourceXYZ, lightSource.illuminatedBlocks, 0, power>>1, + directionMask, borders, ds); } lightSource.setBorders(borders[0], borders[1], borders[2], borders[3], borders[4], borders[5]); return lightSource; } private void litBlocksAndGetDescendants(World world, int[] evSource, int[] lightSource, BitSet illuminatedBlocksSet, - int ev, int power, int[] directionMask, int[] borders) { - power = this.getNewPower(world, ev, evSource, lightSource, power, directionMask, illuminatedBlocksSet, borders); - power = (power<<4)/17 - 1; + int ev, int power, int[] directionMask, int[] borders, double[] ds) { + power = this.getNewPower(world, ev, evSource, lightSource, power, directionMask, illuminatedBlocksSet, borders, + ds); + power--; if (power > 1) { - if (vectors[ev][0] == 0) { + if (vectors[ev].length == 0) { int[] xyz = IHLMod.explosionHandler.decodeXYZ(ev); int xb = xyz[0] >> bits - 1; int yb = xyz[1] >> bits - 1; @@ -78,13 +81,11 @@ public class LightHandler { evSource[1] + yb * halfValue * directionMask[1], evSource[2] + zb * halfValue * directionMask[2] }; litBlocksAndGetDescendants(world, nextEVSource, lightSource, illuminatedBlocksSet, ev2, power, - directionMask, borders); + directionMask, borders, ds); } else { for (int d1 : this.vectors[ev]) { - if (d1 != 0) { litBlocksAndGetDescendants(world, evSource, lightSource, illuminatedBlocksSet, d1, power, - directionMask, borders); - } + directionMask, borders, ds); } } } @@ -92,7 +93,7 @@ public class LightHandler { } private int getNewPower(World world, int ev, int[] evSource, int[] lightSource, int power, int[] directionMask, - BitSet illuminatedBlocksSet, int[] borders) { + BitSet illuminatedBlocksSet, int[] borders, double[] ds) { int power1 = power; int[] xyz = IHLMod.explosionHandler.decodeXYZ(ev); int absX = xyz[0] * directionMask[0] + evSource[0]; @@ -111,24 +112,55 @@ public class LightHandler { } else if (absZ > borders[5]) { borders[5] = absZ; } - Block block = world.getBlock(absX, absY, absZ); - if (block.equals(Blocks.air) || block.isAir(world, absX, absY, absZ)) { - return power; - } - power1 *= world.getBlockLightOpacity(absX, absY, absZ) / 16; + power1 = power1 * (255 - world.getBlockLightOpacity(absX, absY, absZ)) / 255; int lightBitAddress = this.encodeXYZ(absX - lightSource[0], absY - lightSource[1], absZ - lightSource[2]); illuminatedBlocksSet.set(lightBitAddress); + if (ds != null) { + float dx = (float) (absX - ds[0]); + float dy = (float) (absY - ds[1]); + float dz = (float) (absZ - ds[2]); + float sqd = dx * dx + dy * dy + dz * dz; + float d = IHLMathUtils.sqrt(sqd); + float dx1 = (float) (ds[3] * d); + float dy1 = (float) (ds[4] * d); + float dz1 = (float) (ds[5] * d); + float ddx = dx - dx1; + float ddy = dy - dy1; + float ddz = dz - dz1; + float sqr = ddx * ddx + ddy * ddy + ddz * ddz; + float sqrmax = (float) ds[6] * sqd + 4f; + if (sqr > sqrmax) { + return 0; + } + } return power1; } public void addLightSource(LightSource lightSource) { - System.out.println("Adding light source. Borders:"); - System.out.println("from " + lightSource.fromX + ";" + lightSource.fromY + ";" + lightSource.fromZ); - System.out.println("to " + lightSource.toX + ";" + lightSource.toY + ";" + lightSource.toZ); +/* IHLMod.log.info("Added light source at area from "+lightSource.fromX+";"+lightSource.fromY+";"+lightSource.fromZ+ + " to "+lightSource.toX+";"+lightSource.toY+";"+lightSource.toZ);*/ this.lightSources.add(lightSource); + Minecraft.getMinecraft().theWorld.markBlockRangeForRenderUpdate( + lightSource.fromX, + lightSource.fromY, + lightSource.fromZ, + lightSource.toX, + lightSource.toY, + lightSource.toZ); } public void removeLightSource(LightSource lightSource) { - this.lightSources.remove(lightSource); + if(!this.lightSources.remove(lightSource)){ + throw new IllegalArgumentException("Requested light source is not presented."); + } +/* IHLMod.log.info("Removing light source at area from "+lightSource.fromX+";"+lightSource.fromY+";"+lightSource.fromZ+ + " to "+lightSource.toX+";"+lightSource.toY+";"+lightSource.toZ);*/ + Minecraft.getMinecraft().theWorld.markBlockRangeForRenderUpdate( + lightSource.fromX, + lightSource.fromY, + lightSource.fromZ, + lightSource.toX, + lightSource.toY, + lightSource.toZ); } } diff --git a/ihl/enviroment/LightSource.java b/ihl/enviroment/LightSource.java index ff4a91f..55f7c6c 100644 --- a/ihl/enviroment/LightSource.java +++ b/ihl/enviroment/LightSource.java @@ -6,8 +6,10 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ihl.ClientProxy; import ihl.IHLMod; +import ihl.utils.IHLMathUtils; +import net.minecraft.world.World; -@SideOnly(value=Side.CLIENT) +@SideOnly(value = Side.CLIENT) public class LightSource { private final int centerX; private final int centerY; @@ -24,8 +26,7 @@ public class LightSource { private final int power; public final BitSet illuminatedBlocks = new BitSet(); - public LightSource(int centerX1, int centerY1, int centerZ1, - int red1, int green1, int blue1, int power1) { + public LightSource(int centerX1, int centerY1, int centerZ1, int red1, int green1, int blue1, int power1) { centerX = centerX1; centerY = centerY1; centerZ = centerZ1; @@ -34,45 +35,149 @@ public class LightSource { blue = blue1; power = power1; } - - public void setBorders(int fromX1, int fromY1, int fromZ1, - int toX1, int toY1, int toZ1) - { - fromX=fromX1; - fromY=fromY1; - fromZ=fromZ1; - toX=toX1; - toY=toY1; - toZ=toZ1; + + public void setBorders(int fromX1, int fromY1, int fromZ1, int toX1, int toY1, int toZ1) { + fromX = fromX1; + fromY = fromY1; + fromZ = fromZ1; + toX = toX1; + toY = toY1; + toZ = toZ1; } public boolean isBlockIlluminated(int x, int y, int z) { - if(x<fromX || x>toX || y<fromY || y>toY || z<fromZ || z>toZ) - { + if (x < fromX || x > toX || y < fromY || y > toY || z < fromZ || z > toZ) { return false; - } - else - { + } else { int rx = x - centerX; int ry = y - centerY; int rz = z - centerZ; - int l = ((ClientProxy)IHLMod.proxy).getLightHandler().encodeXYZ(rx, ry, rz); + int l = ((ClientProxy) IHLMod.proxy).getLightHandler().encodeXYZ(rx, ry, rz); return illuminatedBlocks.get(l); } } public int[] getLightValue(int x, int y, int z, int[] normal) { - int dx = centerX-x; - int dy = centerY-y; - int dz = centerZ-z; - int d = dx*dx+dy*dy+dz*dz; - dx=normal[0]*dx; - dy=normal[1]*dy; - dz=normal[2]*dz; - dx=dx>0?(dx<<16)/d:0; - dy=dy>0?(dy<<16)/d:0; - dz=dz>0?(dz<<16)/d:0; - int brightness = Math.min(power*(dx+dy+dz)>>16,16); - return new int[]{brightness, this.red, this.blue, this.green}; + int dx = centerX - x; + int dy = centerY - y; + int dz = centerZ - z; + int d = dx * dx + dy * dy + dz * dz; + if (d == 0) { + return new int[] { 0xf0, this.red, this.blue, this.green }; + } + if (normal[0] + normal[1] + normal[2] == 0) { + dx = dx < 0 ? -dx : dx; + dy = dy < 0 ? -dy : dy; + dz = dz < 0 ? -dz : dz; + } else { + dx = normal[0] * dx; + dy = normal[1] * dy; + dz = normal[2] * dz; + dx = dx > 0 ? dx : 0; + dy = dy > 0 ? dy : 0; + dz = dz > 0 ? dz : 0; + } + int r = power * (dx + dy + dz) / d; + r = r<0?0:r; + int brightness = r > 15 ? 15 : r; + return new int[] { brightness << 4, this.red*r, this.green*r, this.blue*r}; + } + + @Override + public boolean equals(Object o) { + if (o instanceof LightSource) { + LightSource otherLS = (LightSource) o; + return this.centerX == otherLS.centerX && this.centerY == otherLS.centerY && this.centerZ == otherLS.centerZ + && this.fromX == otherLS.fromX && this.fromY == otherLS.fromY && this.fromZ == otherLS.fromZ + && this.toX == otherLS.toX && this.toY == otherLS.toY && this.toZ == otherLS.toZ; + } + return false; + } + + public void provideLight(World world, int x, int y, int z) { + int dx = x-centerX;//100 10 20 + int dy = y-centerY; + int dz = z-centerZ; + int sqd = dx*dx+dy*dy+dz*dz; + float d = IHLMathUtils.sqrt(sqd); + float dx1 = dx/d; + float dy1 = dy/d; + float dz1 = dz/d; + float x1 = x+0.5f; + float y1 = y+0.5f; + float z1 = z+0.5f; + for(int i=0;i<64;i++){ + x1+=dx1; + y1+=dy1; + z1+=dz1; + int absX = (int)x1; + int absY = (int)y1; + int absZ = (int)z1; + int ddx = absX-centerX; + int ddy = absY-centerY; + int ddz = absZ-centerZ; + this.illuminatedBlocks.set(((ClientProxy) IHLMod.proxy).getLightHandler().encodeXYZ(ddx, ddy, ddz)); + if (absX < fromX) { + fromX = absX; + } else if (absY < fromY) { + fromY = absY; + } else if (absZ < fromZ) { + fromZ = absZ; + } else if (absX > toX) { + toX = absX; + } else if (absY > toY) { + toY = absY; + } else if (absZ > toZ) { + toZ = absZ; + } + if(world.getBlockLightOpacity(absX, absY, absZ)>192) { + break; + } + } + } + + public void castShadow(World world, int x, int y, int z) { + int dx = x-centerX; + int dy = y-centerY; + int dz = z-centerZ; + int sqd = dx*dx+dy*dy+dz*dz; + float d = IHLMathUtils.sqrt(sqd); + float dx1 = dx/d; + float dy1 = dy/d; + float dz1 = dz/d; + float x1 = x+0.5f; + float y1 = y+0.5f; + float z1 = z+0.5f; + x1+=dx1; + y1+=dy1; + z1+=dz1; + for(int i=0;i<64;i++){ + x1+=dx1; + y1+=dy1; + z1+=dz1; + int absX = (int)x1; + int absY = (int)y1; + int absZ = (int)z1; + int ddx = absX-centerX; + int ddy = absY-centerY; + int ddz = absZ-centerZ; + this.illuminatedBlocks.clear(((ClientProxy) IHLMod.proxy).getLightHandler().encodeXYZ(ddx, ddy, ddz)); + if (absX < fromX) { + fromX = absX; + } else if (absY < fromY) { + fromY = absY; + } else if (absZ < fromZ) { + fromZ = absZ; + } else if (absX > toX) { + toX = absX; + } else if (absY > toY) { + toY = absY; + } else if (absZ > toZ) { + toZ = absZ; + } + if(world.getBlockLightOpacity(absX, absY, absZ)>192) { + break; + } + } } } diff --git a/ihl/enviroment/SpotlightBlock.java b/ihl/enviroment/SpotlightBlock.java index 2cabecf..02cafd1 100644 --- a/ihl/enviroment/SpotlightBlock.java +++ b/ihl/enviroment/SpotlightBlock.java @@ -4,17 +4,25 @@ import ic2.core.IC2; import ihl.IHLCreativeTab;
import ihl.items_blocks.IHLItemBlock;
+import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
+import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.GameRegistry;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
public class SpotlightBlock extends Block implements ITileEntityProvider
{
@@ -36,7 +44,20 @@ public class SpotlightBlock extends Block implements ITileEntityProvider {
return true;
}
-
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @SideOnly(Side.CLIENT)
+ public void getSubBlocks(Item item, CreativeTabs tab, List itemlist) {
+ for (int colour : ItemDye.field_150922_c) {
+ ItemStack stack = new ItemStack(item);
+ stack.stackTagCompound = new NBTTagCompound();
+ stack.stackTagCompound.setInteger("colour", colour);
+ itemlist.add(stack);
+ }
+ }
+
+
+
/**
* Returns the quantity of items to drop on block destruction.
*/
@@ -80,17 +101,31 @@ public class SpotlightBlock extends Block implements ITileEntityProvider }
@Override
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack)
+ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack)
{
TileEntity t = world.getTileEntity(x, y, z);
if(IC2.platform.isSimulating() && t instanceof SpotlightTileEntity)
{
SpotlightTileEntity te = (SpotlightTileEntity)t;
te.setDirectionVector(player);
+ if(stack.stackTagCompound!=null)
+ te.colour=stack.stackTagCompound.getInteger("colour");
}
}
@Override
+ public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
+ if (world.isRemote) {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if (te != null && te instanceof LightBulbTileEntity) {
+ LightBulbTileEntity ate = (LightBulbTileEntity) te;
+ ate.invalidate();
+ }
+ }
+ super.onBlockPreDestroy(world, x, y, z, meta);
+ }
+
+ @Override
public boolean onBlockActivated(World world,int x,int y,int z,EntityPlayer player,int i,float pos_x,float pos_y,float pos_z)
{
TileEntity te = world.getTileEntity(x,y,z);
@@ -102,7 +137,11 @@ public class SpotlightBlock extends Block implements ITileEntityProvider return false;
}
-
-
-
+ public int getLightValue(IBlockAccess world, int x, int y, int z) {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if(te instanceof LightBulbTileEntity && ((LightBulbTileEntity)te).getActive()){
+ return 15;
+ }
+ return 0;
+ }
}
\ No newline at end of file diff --git a/ihl/enviroment/SpotlightRender.java b/ihl/enviroment/SpotlightRender.java index e38e251..8f48e1a 100644 --- a/ihl/enviroment/SpotlightRender.java +++ b/ihl/enviroment/SpotlightRender.java @@ -70,6 +70,7 @@ private final float scale=1F/16F; GL11.glColor4f(1f, 1f, 1f, 1f);
model.Base.render(scale);
GL11.glTranslatef(model.RotatingPart1.rotationPointX*scale, model.RotatingPart1.rotationPointY*scale, model.RotatingPart1.rotationPointZ*scale);
+ GL11.glColor4f((cte.colour>>>16)/255f,((cte.colour>>>8)&255)/255f, (cte.colour&255)/255f,1f);
switch(cte.getFacing())
{
case 0:
diff --git a/ihl/enviroment/SpotlightTileEntity.java b/ihl/enviroment/SpotlightTileEntity.java index ab18ebe..d8e55df 100644 --- a/ihl/enviroment/SpotlightTileEntity.java +++ b/ihl/enviroment/SpotlightTileEntity.java @@ -1,6 +1,9 @@ package ihl.enviroment;
+
import ic2.api.network.INetworkTileEntityEventListener;
import ic2.core.IC2;
+import ihl.ClientProxy;
+import ihl.IHLMod;
import ihl.IHLModInfo;
import ihl.handpump.XYZ;
import ihl.utils.IHLUtils;
@@ -9,6 +12,9 @@ import java.util.HashSet; import java.util.Iterator;
import java.util.List;
import java.util.Set;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
@@ -19,315 +25,188 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
-public class SpotlightTileEntity extends LightBulbTileEntity implements INetworkTileEntityEventListener
-{
- Vec3 directionVector=Vec3.createVectorHelper(1, 0, 0);
- private static final int maxLightRange=128;
- private final Set<XYZ> xyzGlowningAir = new HashSet<XYZ>();
- private static final Set<Vec3> lightSphereVectors = new HashSet<Vec3>();
- public float rotationPitch=0f;
- public float rotationYaw=0f;
- public float prevRotationPitch=0f;
- public float prevRotationYaw=0f;
- boolean needLightTargetUpdate=false;
-
- public static void createLightSphereVectors()
- {
- for(double y=-1d;y<=1d;y+=0.2d)
- {
- double sqr = 1-y*y;
- double x,z;
- for(double alpha=0;alpha<Math.PI*2;alpha+=Math.PI*2d/(sqr*16d+0.1d))
- {
- x=Math.cos(alpha)*sqr;
- z=Math.sin(alpha)*sqr;
- lightSphereVectors.add(Vec3.createVectorHelper(x*0.5d, y*0.5d, z*0.5d));
- }
- }
+public class SpotlightTileEntity extends LightBulbTileEntity implements INetworkTileEntityEventListener {
+ public float directionX = 0f;
+ public float directionY = -1f;
+ public float directionZ = 0f;
+ public float prevDirectionX = 0f;
+ public float prevDirectionY = -1f;
+ public float prevDirectionZ = 0f;
+ public float rotationPitch = 0f;
+ public float rotationYaw = 0f;
+ public float prevRotationPitch = 0f;
+ public float prevRotationYaw = 0f;
+ boolean needLightTargetUpdate = false;
+
+ @Override
+ public void readFromNBT(NBTTagCompound nbttagcompound) {
+ super.readFromNBT(nbttagcompound);
+ directionX = nbttagcompound.getFloat("directionX");
+ directionY = nbttagcompound.getFloat("directionY");
+ directionZ = nbttagcompound.getFloat("directionZ");
+ this.rotationPitch = this.getVectorPitchAngle(directionX,directionY,directionZ);
+ this.rotationYaw = this.getVectorYawAngle(directionX,directionY,directionZ);
+ needLightTargetUpdate = true;
}
-
- @Override
- public void readFromNBT(NBTTagCompound nbttagcompound)
- {
- super.readFromNBT(nbttagcompound);
- directionVector.xCoord = nbttagcompound.getDouble("directionVector.xCoord");
- directionVector.yCoord = nbttagcompound.getDouble("directionVector.yCoord");
- directionVector.zCoord = nbttagcompound.getDouble("directionVector.zCoord");
- this.rotationPitch=this.getVectorPitchAngle(directionVector);
- this.rotationYaw=this.getVectorYawAngle(directionVector);
- needLightTargetUpdate=true;
- }
- @Override
- public void writeToNBT(NBTTagCompound nbttagcompound)
- {
- super.writeToNBT(nbttagcompound);
- nbttagcompound.setDouble("directionVector.xCoord", directionVector.xCoord);
- nbttagcompound.setDouble("directionVector.yCoord", directionVector.yCoord);
- nbttagcompound.setDouble("directionVector.zCoord", directionVector.zCoord);
- }
-
- @Override
- public List<String> getNetworkedFields()
- {
- List<String> list = super.getNetworkedFields();
- list.add("rotationPitch");
- list.add("rotationYaw");
- return list;
- }
-
- public void setLightOn()
- {
- Iterator<XYZ> gai = xyzGlowningAir.iterator();
- while(gai.hasNext())
- {
- XYZ xyz = gai.next();
- Block block = worldObj.getBlock(xyz.x,xyz.y,xyz.z);
- if(block==Blocks.air || block.isAir(this.worldObj, xyz.x,xyz.y,xyz.z))
- {
- worldObj.setBlock(xyz.x, xyz.y, xyz.z, LightBulbBlock.glowningAir);
- }
- }
+ @Override
+ public void writeToNBT(NBTTagCompound nbttagcompound) {
+ super.writeToNBT(nbttagcompound);
+ nbttagcompound.setDouble("directionX", directionX);
+ nbttagcompound.setDouble("directionY", directionY);
+ nbttagcompound.setDouble("directionZ", directionZ);
}
-
- public void setLightOff()
- {
- Iterator<XYZ> gai = xyzGlowningAir.iterator();
- while(gai.hasNext())
- {
- XYZ xyz = gai.next();
- Block block = worldObj.getBlock(xyz.x,xyz.y,xyz.z);
- if(block == LightBulbBlock.glowningAir)
- {
- worldObj.setBlockToAir(xyz.x, xyz.y, xyz.z);
- }
- }
+
+ @Override
+ public List<String> getNetworkedFields() {
+ List<String> list = super.getNetworkedFields();
+ list.add("needLightTargetUpdate");
+ list.add("rotationPitch");
+ list.add("rotationYaw");
+ list.add("directionX");
+ list.add("directionY");
+ list.add("directionZ");
+ return list;
}
-
+
@Override
- public void updateEntity()
- {
+ public void updateEntity() {
super.updateEntity();
- if(needLightTargetUpdate)
- {
- this.generateGlowningAirList();
+ if (this.worldObj.isRemote) {
+ if(this.directionX!=this.prevDirectionX ||
+ this.directionY!=this.prevDirectionY ||
+ this.directionZ!=this.prevDirectionZ){
+ updateLightState();
+ this.prevDirectionX=this.directionX;
+ this.prevDirectionY=this.directionY;
+ this.prevDirectionZ=this.directionZ;
+ }
+ } else if (needLightTargetUpdate) {
this.updateLightState();
- needLightTargetUpdate=false;
- }
- if(this.prevRotationPitch!=this.rotationPitch)
- {
- IC2.network.get().updateTileEntityField(this, "rotationPitch");
- this.prevRotationPitch=this.rotationPitch;
+ needLightTargetUpdate = false;
}
- if(this.prevRotationYaw!=this.rotationYaw)
- {
- IC2.network.get().updateTileEntityField(this, "rotationYaw");
- this.prevRotationYaw=this.rotationYaw;
+ if (!this.worldObj.isRemote) {
+ if (this.prevRotationPitch != this.rotationPitch) {
+ IC2.network.get().updateTileEntityField(this, "rotationPitch");
+ this.prevRotationPitch = this.rotationPitch;
+ }
+ if (this.prevRotationYaw != this.rotationYaw) {
+ IC2.network.get().updateTileEntityField(this, "rotationYaw");
+ this.prevRotationYaw = this.rotationYaw;
+ }
}
- }
-
+ }
+
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return IHLUtils.getThisModItemStack("spotlight");
}
-
- public void setDirectionVector(EntityLivingBase player)
- {
- ForgeDirection dir = ForgeDirection.getOrientation(this.getFacing());
- Vec3 lookVec = player.getLookVec();
- if(lookVec.xCoord*dir.offsetX+lookVec.yCoord*dir.offsetY+lookVec.zCoord*dir.offsetZ<0)
- {
- double x=player.posX-this.xCoord-0.5D;
- double y=player.posY+player.getEyeHeight()-this.yCoord-0.5D;
- double z=player.posZ-this.zCoord-0.5D;
- double d=Math.sqrt(x*x+y*y+z*z);
- directionVector=Vec3.createVectorHelper(x/d, y/d, z/d);
- }
- else
- {
- directionVector=player.getLookVec();
- }
- this.rotationPitch=this.getVectorPitchAngle(directionVector);
- this.rotationYaw=this.getVectorYawAngle(directionVector);
- this.needLightTargetUpdate=true;
- IC2.network.get().initiateTileEntityEvent(this, 0, true);
- }
-
- private void generateGlowningAirList()
- {
- this.setLightOff();
- xyzGlowningAir.clear();
- Iterator<Vec3> lvi = lightSphereVectors.iterator();
- while(lvi.hasNext())
- {
- traceVectorToLastAirBlock(lvi.next());
+
+ public void setDirectionVector(EntityLivingBase player) {
+ ForgeDirection dir = ForgeDirection.getOrientation(this.getFacing());
+ Vec3 lookVec = player.getLookVec();
+ if (lookVec.xCoord * dir.offsetX + lookVec.yCoord * dir.offsetY + lookVec.zCoord * dir.offsetZ < 0) {
+ double x = player.posX - this.xCoord - 0.5D;
+ double y = player.posY + player.getEyeHeight() - this.yCoord - 0.5D;
+ double z = player.posZ - this.zCoord - 0.5D;
+ double d = Math.sqrt(x * x + y * y + z * z);
+ directionX = (float) (x / d);
+ directionY = (float) (y / d);
+ directionZ = (float) (z / d);
+ } else {
+ Vec3 plook = player.getLookVec();
+ directionX = (float) (plook.xCoord);
+ directionY = (float) (plook.yCoord);
+ directionZ = (float) (plook.zCoord);
}
+ IC2.network.get().updateTileEntityField(this, "directionX");
+ IC2.network.get().updateTileEntityField(this, "directionY");
+ IC2.network.get().updateTileEntityField(this, "directionZ");
+ this.rotationPitch = this.getVectorPitchAngle(directionX,directionY,directionZ);
+ this.rotationYaw = this.getVectorYawAngle(directionX,directionY,directionZ);
+ this.needLightTargetUpdate = true;
+ IC2.network.get().initiateTileEntityEvent(this, 0, true);
}
-
- private void traceVectorToLastAirBlock(Vec3 vector)
- {
- double dx=directionVector.xCoord;
- double dy=directionVector.yCoord;
- double dz=directionVector.zCoord;
- double dx1=vector.xCoord;
- double dy1=vector.yCoord;
- double dz1=vector.zCoord;
- if(2*dx*dx1+dx1*dx1+2*dy*dy1+dy1*dy1+2*dz*dz1+dz1*dz1>0d)
- {
- double x1=xCoord+0.5d;
- double y1=yCoord+0.5d;
- double z1=zCoord+0.5d;
- int xi1=xCoord;
- int yi1=yCoord;
- int zi1=zCoord;
- int airx=xCoord;
- int airy=yCoord;
- int airz=zCoord;
- for(int i=0;i<maxLightRange;i++)
- {
- int xi = (int)Math.floor(x1+(dx+dx1)*i*0.79);
- int yi = (int)Math.floor(y1+(dy+dy1)*i*0.79);
- int zi = (int)Math.floor(z1+(dz+dz1)*i*0.79);
- if(xi!=xi1||yi!=yi1||zi!=zi1)
- {
- Block block = worldObj.getBlock(xi,yi,zi);
- if(block!=Blocks.air && !block.isAir(worldObj, xi, yi, zi) && block.getMaterial()!=Material.glass && block.getMaterial()!=Material.air)
- {
- xyzGlowningAir.add(new XYZ(airx,airy,airz));
- break;
- }
- else
- {
- if(block.isAir(worldObj, xi, yi, zi) || block==Blocks.air)
- {
- airx=xi;
- airy=yi;
- airz=zi;
- }
- xi1=xi;
- yi1=yi;
- zi1=zi;
- }
- }
- }
+
+ private float getVectorPitchAngle(float x, float y, float z) {
+ switch (this.getFacing()) {
+ case 0:
+ return (float) -(Math.abs(Math.asin(z)) + Math.abs(Math.asin(x)));
+ case 1:
+ return (float) (Math.abs(Math.asin(z)) + Math.abs(Math.asin(x)));
+ case 2:
+ return (float) (Math.abs(Math.asin(y)) + Math.abs(Math.asin(x)));
+ case 3:
+ return (float) (Math.abs(Math.asin(y)) + Math.abs(Math.asin(x)));
+ case 4:
+ return (float) (Math.abs(Math.asin(y)) + Math.abs(Math.asin(z)));
+ case 5:
+ return (float) (Math.abs(Math.asin(y)) + Math.abs(Math.asin(z)));
+ default:
+ return (float) (-Math.asin(y));
}
}
-
+
+ @SideOnly(value = Side.CLIENT)
@Override
- protected void updateLightState()
- {
- if(this.getActive())
- {
- setLightOn();
- }
- else
- {
- setLightOff();
- }
- }
-
- private float getVectorPitchAngle(Vec3 vector)
- {
- double x=vector.xCoord;
- double y=vector.yCoord;
- double z=vector.zCoord;
- switch(this.getFacing())
- {
- case 0:
- return (float)-(Math.abs(Math.asin(z))+Math.abs(Math.asin(x)));
- case 1:
- return (float)(Math.abs(Math.asin(z))+Math.abs(Math.asin(x)));
- case 2:
- return (float)(Math.abs(Math.asin(y))+Math.abs(Math.asin(x)));
- case 3:
- return (float)(Math.abs(Math.asin(y))+Math.abs(Math.asin(x)));
- case 4:
- return (float)(Math.abs(Math.asin(y))+Math.abs(Math.asin(z)));
- case 5:
- return (float)(Math.abs(Math.asin(y))+Math.abs(Math.asin(z)));
- default:
- return (float)(-Math.asin(y));
- }
+ protected LightSource createLightSource(int red, int green, int blue) {
+ return ((ClientProxy) IHLMod.proxy).getLightHandler().calculateLightSource(worldObj, xCoord, yCoord, zCoord,
+ 256, red, green, blue, new double[] { this.xCoord + 0.5f, this.yCoord + 0.5f, this.zCoord + 0.5f,
+ this.directionX, this.directionY, this.directionZ, 0.8d });
}
-
- private float getVectorYawAngle(Vec3 vector)
- {
- double x=vector.xCoord;
- double y=vector.yCoord;
- double z=vector.zCoord;
- switch(this.getFacing())
- {
- case 0:
- if(z>=0)
- {
- return (float)(Math.acos(x/Math.sqrt(x*x+z*z))-Math.PI/2);
- }
- else
- {
- return (float)(-Math.acos(x/Math.sqrt(x*x+z*z))-Math.PI/2);
- }
- case 1:
- if(z>=0)
- {
- return (float)(Math.acos(x/Math.sqrt(x*x+z*z))-Math.PI/2);
- }
- else
- {
- return (float)(-Math.acos(x/Math.sqrt(x*x+z*z))-Math.PI/2);
- }
- case 2:
- if(y>=0)
- {
- return (float)(-Math.acos(x/Math.sqrt(x*x+y*y))-Math.PI/2);
- }
- else
- {
- return (float)(Math.acos(x/Math.sqrt(x*x+y*y))-Math.PI/2);
- }
- case 3:
- if(y>=0)
- {
- return (float)(-Math.acos(x/Math.sqrt(x*x+y*y))-Math.PI/2);
- }
- else
- {
- return (float)(Math.acos(x/Math.sqrt(x*x+y*y))-Math.PI/2);
- }
- case 4:
- if(y>=0)
- {
- return (float)(-Math.acos(z/Math.sqrt(z*z+y*y))-Math.PI/2);
- }
- else
- {
- return (float)(Math.acos(z/Math.sqrt(z*z+y*y))-Math.PI/2);
- }
- case 5:
- if(y>=0)
- {
- return (float)(-Math.acos(z/Math.sqrt(z*z+y*y))-Math.PI/2);
- }
- else
- {
- return (float)(Math.acos(z/Math.sqrt(z*z+y*y))-Math.PI/2);
- }
- default:
- return 0f;
+
+ private float getVectorYawAngle(float x, float y, float z) {
+ switch (this.getFacing()) {
+ case 0:
+ if (z >= 0) {
+ return (float) (Math.acos(x / Math.sqrt(x * x + z * z)) - Math.PI / 2);
+ } else {
+ return (float) (-Math.acos(x / Math.sqrt(x * x + z * z)) - Math.PI / 2);
+ }
+ case 1:
+ if (z >= 0) {
+ return (float) (Math.acos(x / Math.sqrt(x * x + z * z)) - Math.PI / 2);
+ } else {
+ return (float) (-Math.acos(x / Math.sqrt(x * x + z * z)) - Math.PI / 2);
+ }
+ case 2:
+ if (y >= 0) {
+ return (float) (-Math.acos(x / Math.sqrt(x * x + y * y)) - Math.PI / 2);
+ } else {
+ return (float) (Math.acos(x / Math.sqrt(x * x + y * y)) - Math.PI / 2);
+ }
+ case 3:
+ if (y >= 0) {
+ return (float) (-Math.acos(x / Math.sqrt(x * x + y * y)) - Math.PI / 2);
+ } else {
+ return (float) (Math.acos(x / Math.sqrt(x * x + y * y)) - Math.PI / 2);
+ }
+ case 4:
+ if (y >= 0) {
+ return (float) (-Math.acos(z / Math.sqrt(z * z + y * y)) - Math.PI / 2);
+ } else {
+ return (float) (Math.acos(z / Math.sqrt(z * z + y * y)) - Math.PI / 2);
+ }
+ case 5:
+ if (y >= 0) {
+ return (float) (-Math.acos(z / Math.sqrt(z * z + y * y)) - Math.PI / 2);
+ } else {
+ return (float) (Math.acos(z / Math.sqrt(z * z + y * y)) - Math.PI / 2);
+ }
+ default:
+ return 0f;
}
}
@Override
- public void onNetworkEvent(int event)
- {
- this.worldObj.playSound(xCoord+0.5d, yCoord+0.5d, zCoord+0.5d, IHLModInfo.MODID+":spotlightRotating", 10F, 1f, true);
+ public void onNetworkEvent(int event) {
+ this.worldObj.playSound(xCoord + 0.5d, yCoord + 0.5d, zCoord + 0.5d, IHLModInfo.MODID + ":spotlightRotating",
+ 10F, 1f, true);
}
}
-
-/* -Y DOWN(0, -1, 0) 0
-/* +Y UP(0, 1, 0) 1
-/* -Z NORTH(0, 0, -1) 2
-/* +Z SOUTH(0, 0, 1) 3
-/* -X WEST(-1, 0, 0), 4
-/* +X EAST(1, 0, 0), 5
-//VALID_DIRECTIONS = {DOWN, UP, NORTH, SOUTH, WEST, EAST};*/
+/*
+ * -Y DOWN(0, -1, 0) 0 /* +Y UP(0, 1, 0) 1 /* -Z NORTH(0, 0, -1) 2 /* +Z
+ * SOUTH(0, 0, 1) 3 /* -X WEST(-1, 0, 0), 4 /* +X EAST(1, 0, 0), 5
+ * //VALID_DIRECTIONS = {DOWN, UP, NORTH, SOUTH, WEST, EAST};
+ */
|
