summaryrefslogtreecommitdiff
path: root/ihl/enviroment
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
committerFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
commit05c78126859231a68e199dc34613689bd0978e2f (patch)
tree050bea104a18c72905095d29f31bec2935a27a24 /ihl/enviroment
Initial commit
Diffstat (limited to 'ihl/enviroment')
-rw-r--r--ihl/enviroment/GlowningAirBlock.java34
-rw-r--r--ihl/enviroment/LaserHitMirrorEventHandler.java48
-rw-r--r--ihl/enviroment/LightBulbBlock.java133
-rw-r--r--ihl/enviroment/LightBulbModel.java59
-rw-r--r--ihl/enviroment/LightBulbRender.java77
-rw-r--r--ihl/enviroment/LightBulbTileEntity.java308
-rw-r--r--ihl/enviroment/MirrorBlock.java222
-rw-r--r--ihl/enviroment/MirrorRender.java427
-rw-r--r--ihl/enviroment/MirrorTileEntity.java451
-rw-r--r--ihl/enviroment/SpotlightBlock.java108
-rw-r--r--ihl/enviroment/SpotlightModel.java71
-rw-r--r--ihl/enviroment/SpotlightRender.java109
-rw-r--r--ihl/enviroment/SpotlightTileEntity.java334
13 files changed, 2381 insertions, 0 deletions
diff --git a/ihl/enviroment/GlowningAirBlock.java b/ihl/enviroment/GlowningAirBlock.java
new file mode 100644
index 0000000..e6dfb8e
--- /dev/null
+++ b/ihl/enviroment/GlowningAirBlock.java
@@ -0,0 +1,34 @@
+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/LaserHitMirrorEventHandler.java b/ihl/enviroment/LaserHitMirrorEventHandler.java
new file mode 100644
index 0000000..9baee2d
--- /dev/null
+++ b/ihl/enviroment/LaserHitMirrorEventHandler.java
@@ -0,0 +1,48 @@
+package ihl.enviroment;
+
+import ic2.api.event.LaserEvent;
+import ic2.core.item.tool.EntityMiningLaser;
+import net.minecraft.entity.Entity;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.common.util.ForgeDirection;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+
+public class LaserHitMirrorEventHandler
+{
+ public LaserHitMirrorEventHandler(){}
+
+ @SubscribeEvent
+ public void onLaserHit(LaserEvent.LaserHitsBlockEvent event)
+ {
+ TileEntity te = event.world.getTileEntity(event.x, event.y, event.z);
+ if(te instanceof MirrorTileEntity)
+ {
+ ForgeDirection mirrorDirection = ForgeDirection.getOrientation(((MirrorTileEntity)te).getFacing());
+ Entity ls = event.lasershot;
+ if((ls.motionX*mirrorDirection.offsetX+ls.motionY*mirrorDirection.offsetY+ls.motionZ*mirrorDirection.offsetZ)<0)
+ {
+ if(mirrorDirection.offsetX!=0)
+ {
+ ls.motionX=-ls.motionX;
+ }
+ if(mirrorDirection.offsetY!=0)
+ {
+ ls.motionY=-ls.motionY;
+ }
+ if(mirrorDirection.offsetZ!=0)
+ {
+ ls.motionZ=-ls.motionZ;
+ }
+ if(!event.world.isRemote)
+ {
+ EntityMiningLaser tLaser = new EntityMiningLaser(event.world, event.owner, event.range, event.power, event.blockBreaks, event.explosive, 0, 0, ls.posY);
+ tLaser.setPosition(ls.posX, ls.posY, ls.posZ);
+ tLaser.setLaserHeading(ls.motionX, ls.motionY, ls.motionZ, 1d);
+ ls.setDead();
+ event.world.spawnEntityInWorld(tLaser);
+ }
+ event.setCanceled(true);
+ }
+ }
+ }
+}
diff --git a/ihl/enviroment/LightBulbBlock.java b/ihl/enviroment/LightBulbBlock.java
new file mode 100644
index 0000000..7175949
--- /dev/null
+++ b/ihl/enviroment/LightBulbBlock.java
@@ -0,0 +1,133 @@
+package ihl.enviroment;
+
+import java.util.Random;
+
+import cpw.mods.fml.common.registry.GameRegistry;
+
+import ihl.IHLCreativeTab;
+import ihl.items_blocks.IHLItemBlock;
+import net.minecraft.block.Block;
+import net.minecraft.block.ITileEntityProvider;
+import net.minecraft.block.material.Material;
+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);
+ 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");
+ }
+
+ @Override
+ public boolean hasTileEntity(int metadata)
+ {
+ return true;
+ }
+
+ public static void init()
+ {
+ glowningAir = new GlowningAirBlock();
+ GameRegistry.registerBlock(glowningAir, "glowningAir");
+ LightBulbBlock mblock = new LightBulbBlock("lightBulb");
+ GameRegistry.registerTileEntity(LightBulbTileEntity.class, "lightBulb");
+ SpotlightBlock sblock = new SpotlightBlock("spotlight");
+ GameRegistry.registerTileEntity(SpotlightTileEntity.class, "spotlight");
+ 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;
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World arg0, int arg1)
+ {
+ return new LightBulbTileEntity();
+ }
+}
diff --git a/ihl/enviroment/LightBulbModel.java b/ihl/enviroment/LightBulbModel.java
new file mode 100644
index 0000000..710d7fb
--- /dev/null
+++ b/ihl/enviroment/LightBulbModel.java
@@ -0,0 +1,59 @@
+package ihl.enviroment;
+
+import ihl.model.IHLModelRenderer;
+import net.minecraft.client.model.ModelBase;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class LightBulbModel extends ModelBase
+{
+ //fields
+ IHLModelRenderer Base;
+ IHLModelRenderer BaseON;
+
+ public LightBulbModel()
+ {
+ textureWidth = 32;
+ textureHeight = 32;
+ setTextureOffset("Base.Shape1", 0, 19);
+ setTextureOffset("Base.TubeNorth", 20, 0);
+ setTextureOffset("Base.CylinderNorth", 0, 0);
+ setTextureOffset("Base.CylinderNorth2", 0, 0);
+ setTextureOffset("Base.SpyralNorth", 16, 24);
+
+ setTextureOffset("BaseON.Shape1", 0, 19);
+ setTextureOffset("BaseON.TubeNorth", 20, 0);
+ setTextureOffset("BaseON.CylinderNorth", 0, 9);
+ setTextureOffset("BaseON.CylinderNorth2", 10, 10);
+ setTextureOffset("BaseON.SpyralNorth", 0, 24);
+
+ Base = new IHLModelRenderer(this, "Base");
+ Base.setRotationPoint(0F, 16F, 0F);
+ Base.mirror = true;
+ Base.addBox("Shape1", -2F, -2F, 7F, 4, 4, 1);
+ Base.addTube("TubeNorth", -2F, -2F, 5F, 4, 4, 2, 0.8f, 1f, ForgeDirection.NORTH);
+ Base.drawFromInside = true;
+ Base.addTube("CylinderNorth", -1.5F, -1.5F, 0F, 3, 3, 7, 0f, 1f, ForgeDirection.NORTH);
+ Base.addTube("CylinderNorth2", -1F, -1F, 0.5F, 2, 2, 5, 0f, 1f, ForgeDirection.NORTH);
+ Base.drawFromInside = false;
+ Base.addTube("SpyralNorth", -0.5F, -0.5F, 0.5F, 1, 1, 7, 0f, 1f, ForgeDirection.NORTH);
+
+ BaseON = new IHLModelRenderer(this, "BaseON");
+ BaseON.setRotationPoint(0F, 16F, 0F);
+ BaseON.mirror = true;
+ BaseON.addBox("Shape1", -2F, -2F, 7F, 4, 4, 1);
+ BaseON.addTube("TubeNorth", -2F, -2F, 5F, 4, 4, 2, 0.8f, 1f, ForgeDirection.NORTH);
+ BaseON.drawFromInside = true;
+ BaseON.addTube("CylinderNorth", -1.5F, -1.5F, 0F, 3, 3, 7, 0f, 1f, ForgeDirection.NORTH);
+ BaseON.addTube("CylinderNorth2", -1F, -1F, 0.5F, 2, 2, 5, 0f, 1f, ForgeDirection.NORTH);
+ BaseON.drawFromInside = false;
+ BaseON.addTube("SpyralNorth", -0.5F, -0.5F, 0.5F, 1, 1, 7, 0f, 1f, ForgeDirection.NORTH);
+ }
+
+ private void setRotation(IHLModelRenderer model, float x, float y, float z)
+ {
+ model.rotateAngleX = x;
+ model.rotateAngleY = y;
+ model.rotateAngleZ = z;
+ }
+
+}
diff --git a/ihl/enviroment/LightBulbRender.java b/ihl/enviroment/LightBulbRender.java
new file mode 100644
index 0000000..97104f7
--- /dev/null
+++ b/ihl/enviroment/LightBulbRender.java
@@ -0,0 +1,77 @@
+package ihl.enviroment;
+import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.opengl.GL11;
+
+import ihl.IHLModInfo;
+
+public class LightBulbRender extends TileEntitySpecialRenderer{
+private LightBulbModel model = new LightBulbModel();
+private ResourceLocation tex = new ResourceLocation(IHLModInfo.MODID+":textures/blocks/lightBulb.png");
+private final float scale=1F/16F;
+
+ public LightBulbRender() {}
+
+
+ @Override
+ public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float par8)
+ {
+ LightBulbTileEntity cte = (LightBulbTileEntity)tile;
+ int rotation = 0;
+ int rotationz = 0;
+ if(tile.getWorldObj() != null)
+ {
+ switch (cte.getFacing())
+ {
+ case 0:
+ rotationz = 1;
+ break;
+ case 1:
+ rotationz = 3;
+ break;
+ case 2:
+ rotation = 2;
+ break;
+ case 5:
+ rotation = 3;
+ break;
+ case 3:
+ rotation = 0;
+ break;
+ case 4:
+ rotation = 1;
+ break;
+ default:
+ rotation = 0;
+ }
+ }
+ else
+ {
+ return;
+ }
+ model.BaseON.rotateAngleY=(float) (rotation*Math.PI/2);
+ model.BaseON.rotateAngleX=(float) (rotationz*Math.PI/2);
+ model.Base.rotateAngleY=(float) (rotation*Math.PI/2);
+ model.Base.rotateAngleX=(float) (rotationz*Math.PI/2);
+ GL11.glPushMatrix();
+ GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
+ GL11.glScalef(1.0F, -1F, -1F);
+ 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);
+ if(cte.getActive())
+ {
+ GL11.glDisable(GL11.GL_LIGHTING);
+ model.BaseON.render(scale);
+ }
+ else
+ {
+ model.Base.render(scale);
+ }
+ GL11.glDisable(GL11.GL_BLEND);
+ GL11.glPopMatrix(); //end
+
+ }
+} \ No newline at end of file
diff --git a/ihl/enviroment/LightBulbTileEntity.java b/ihl/enviroment/LightBulbTileEntity.java
new file mode 100644
index 0000000..0d8f399
--- /dev/null
+++ b/ihl/enviroment/LightBulbTileEntity.java
@@ -0,0 +1,308 @@
+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;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.common.util.ForgeDirection;
+import ic2.api.energy.event.EnergyTileLoadEvent;
+import ic2.api.energy.event.EnergyTileUnloadEvent;
+import ic2.api.energy.tile.IEnergySink;
+import ic2.api.network.INetworkDataProvider;
+import ic2.api.tile.IWrenchable;
+import ic2.core.IC2;
+import ic2.core.ITickCallback;
+import ic2.core.network.NetworkManager;
+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;
+ private double energy;
+ 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 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()
+ {
+ @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);
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * 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();
+ }
+ }
+
+ 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();
+ }
+ }
+
+ @Override
+ public final boolean canUpdate()
+ {
+ return false;
+ }
+
+ @Override
+ public void updateEntity()
+ {
+ if(++this.ticker % 4 == 0)
+ {
+ if(this.prevFacing != facing)
+ {
+ this.setFacing(facing);
+ }
+ if(this.energy>0)
+ {
+ this.energy--;
+ this.setActive(this.energy>0);
+ }
+ 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);
+ }
+ }
+ }
+ }
+
+ public boolean enableUpdateEntity()
+ {
+ return IC2.platform.isSimulating();
+ }
+
+ @Override
+ public boolean acceptsEnergyFrom(TileEntity emitter,
+ ForgeDirection direction) {
+ switch(direction)
+ {
+ case UP:
+ return this.getFacing()==0;
+ case DOWN:
+ return this.getFacing()==1;
+ case SOUTH:
+ return this.getFacing()==2;
+ case NORTH:
+ return this.getFacing()==3;
+ case EAST:
+ return this.getFacing()==4;
+ case WEST:
+ return this.getFacing()==5;
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
+ {
+ return false;
+ }
+
+ @Override
+ public short getFacing() {
+ 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");
+ }
+ }
+ this.prevFacing = facing;
+ if (IC2.platform.isSimulating()&&!this.addedToEnergyNet)
+ {
+ MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
+ this.addedToEnergyNet = true;
+ }
+ }
+
+ @Override
+ public List<String> getNetworkedFields()
+ {
+ Vector ret = new Vector(2);
+ ret.add("active");
+ ret.add("facing");
+ return ret;
+ }
+
+ @Override
+ public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
+ return true;
+ }
+
+ @Override
+ public float getWrenchDropRate() {
+ return 1;
+ }
+
+ @Override
+ public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
+ return IHLUtils.getThisModItemStack("lightBulb");
+ }
+
+ @Override
+ public double getDemandedEnergy()
+ {
+ return this.maxEnergy-this.energy;
+ }
+
+ @Override
+ public int getSinkTier() {
+ return 1;
+ }
+
+ @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 boolean getActive()
+ {
+ return this.active;
+ }
+
+ 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;
+ }
+}
diff --git a/ihl/enviroment/MirrorBlock.java b/ihl/enviroment/MirrorBlock.java
new file mode 100644
index 0000000..fd1418e
--- /dev/null
+++ b/ihl/enviroment/MirrorBlock.java
@@ -0,0 +1,222 @@
+package ihl.enviroment;
+import ihl.IHLCreativeTab;
+import ihl.IHLModInfo;
+import ihl.utils.IHLUtils;
+import cpw.mods.fml.common.registry.GameRegistry;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.block.Block;
+import net.minecraft.block.ITileEntityProvider;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.util.IIcon;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+
+public class MirrorBlock extends Block implements ITileEntityProvider {
+
+ private String unlocalizedName;
+ private IIcon blockIconSide;
+
+ public MirrorBlock(String unlocalizedName1)
+ {
+ super(Material.glass);
+ this.setBlockName(unlocalizedName1);
+ GameRegistry.registerBlock(this, unlocalizedName1);
+ this.setCreativeTab(IHLCreativeTab.tab);
+ this.setHardness(0.3f);
+ this.setResistance(0.3f);
+ this.setBlockTextureName("clay");
+ }
+
+ public static void init()
+ {
+ MirrorBlock mblock = new MirrorBlock("mirror");
+ GameRegistry.registerTileEntity(MirrorTileEntity.class, "mirror");
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World arg0, int arg1) {
+ return new MirrorTileEntity();
+ }
+
+ @Override
+ public boolean isOpaqueCube()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean renderAsNormalBlock()
+ {
+ return false;
+ }
+
+ @Override
+ public void setBlockBoundsBasedOnState(IBlockAccess iBlockAccess, int x, int y, int z)
+ {
+ TileEntity te = iBlockAccess.getTileEntity(x, y, z);
+ if(te!=null && te instanceof MirrorTileEntity)
+ {
+ MirrorTileEntity ate = (MirrorTileEntity) te;
+ setBlockBoundsBasedOnFacing(ate.getFacing());
+ }
+ }
+
+ @Override
+ public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
+ {
+ TileEntity te = world.getTileEntity(x, y, z);
+ if(te!=null && te instanceof MirrorTileEntity)
+ {
+ MirrorTileEntity ate = (MirrorTileEntity) te;
+ int var2 = ate.getFacing() & 7;
+ float var4 = 0.375F;
+ float var5 = 0.625F;
+ float var6 = 0.5F;
+ float var7 = 0.09F;
+ if (var2 == 0)
+ {
+ return AxisAlignedBB.getBoundingBox(x+0.5F - var6,y+1.0F - var7,z+ 0.5F - var6, x+0.5F + var6, y+1.0F, z+0.5F + var6);
+ }
+ else if (var2 == 1)
+ {
+ return AxisAlignedBB.getBoundingBox(x+0.5F - var6,y+ 0.0F,z+ 0.5F - var6, x+0.5F + var6, y+var7, z+0.5F + var6);
+ }
+ else if (var2 == 2)
+ {
+ return AxisAlignedBB.getBoundingBox(x+0.5F - var6,y+ 0.5F - var6,z+ 1.0F - var7, x+0.5F + var6, y+0.5F + var6, z+1.0F);
+ }
+ else if (var2 == 3)
+ {
+ return AxisAlignedBB.getBoundingBox(x+0.5F - var6,y+ 0.5F - var6,z+ 0.0F, x+0.5F + var6, y+0.5F + var6, z+var7);
+ }
+ else if (var2 == 4)
+ {
+ return AxisAlignedBB.getBoundingBox(x+1.0F - var7,y+ 0.5F - var6,z+0.5F - var6, x+1.0F, y+0.5F + var6, z+0.5F + var6);
+ }
+ else if (var2 == 5)
+ {
+ return AxisAlignedBB.getBoundingBox(x+0.0F,y+ 0.5F - var6, z+0.5F - var6, x+var7, y+0.5F + var6, z+0.5F + var6);
+ }
+ }
+ return null;
+ }
+
+ private void setBlockBoundsBasedOnFacing(int facing)
+ {
+ int var2 = facing & 7;
+ float var4 = 0.375F;
+ float var5 = 0.625F;
+ float var6 = 0.5F;
+ float var7 = 0.09F;
+ 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);
+ }
+ }
+
+ /**
+ * Sets the block's bounds for rendering it as an item
+ */
+ @Override
+ public void setBlockBoundsForItemRender()
+ {
+ float var1 = 0.5F;
+ float var2 = 0.5F;
+ float var3 = 0.05F;
+ this.setBlockBounds(0.5F - var1, 0.5F - var2, 0.5F - var3, 0.5F + var1, 0.5F + var2, 0.5F + var3);
+ }
+
+ @Override
+ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack)
+ {
+ int var6 = MathHelper.floor_double(player.rotationPitch * 4.0F / 360.0F + 0.5D) & 3;
+ int var7 = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
+ TileEntity t = world.getTileEntity(x, y, z);
+ if(t!=null && t instanceof MirrorTileEntity)
+ {
+ MirrorTileEntity te = (MirrorTileEntity)t;
+ if(var6==1)
+ {
+ te.setFacing((short) 1);
+ }
+ else if(var6==3)
+ {
+ te.setFacing((short) 0);
+ }
+ else
+ {
+ switch(var7)
+ {
+ case 0:
+ te.setFacing((short) 2);
+ break;
+ case 1:
+ te.setFacing((short) 5);
+ break;
+ case 2:
+ te.setFacing((short) 3);
+ break;
+ case 3:
+ te.setFacing((short) 4);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void registerBlockIcons(IIconRegister par1IconRegister)
+ {
+ this.blockIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":mirror");
+ }
+
+ @Override
+ public void dropBlockAsItemWithChance(World world, int x, int y, int z, int meta, float chance, int flag)
+ {
+ this.dropBlockAsItem(world, x, y, z, IHLUtils.getThisModItemStack("dustGlass"));
+ }
+ /* @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);
+ if(IC2.platform.isRendering())
+ {
+ MirrorTileEntity rtu = (MirrorTileEntity)te;
+ if(player.getCurrentEquippedItem()==null)
+ {
+ IC2.platform.messagePlayer(player, "ic2.tooltip.mode", new Object[] {"Facing " + rtu.getFacing()});
+ }
+ }
+ return false;
+ }
+ */
+}
diff --git a/ihl/enviroment/MirrorRender.java b/ihl/enviroment/MirrorRender.java
new file mode 100644
index 0000000..9e06f90
--- /dev/null
+++ b/ihl/enviroment/MirrorRender.java
@@ -0,0 +1,427 @@
+package ihl.enviroment;
+
+import java.nio.IntBuffer;
+import java.util.Iterator;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.GLAllocation;
+import net.minecraft.client.renderer.RenderHelper;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.entity.Render;
+import net.minecraft.client.renderer.texture.TextureMap;
+import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
+import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
+import net.minecraft.entity.Entity;
+import net.minecraft.tileentity.TileEntity;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.opengl.ARBFramebufferObject;
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.EXTFramebufferObject;
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL14;
+import org.lwjgl.opengl.GL20;
+import org.lwjgl.opengl.GL30;
+import org.lwjgl.util.glu.GLU;
+import org.lwjgl.util.glu.Project;
+
+import ihl.IHLMod;
+import ihl.model.IHLBlockRenderer;
+import ihl.utils.IHLRenderUtils;
+
+public class MirrorRender extends TileEntitySpecialRenderer{
+private int texture=-1;
+private int fb=-1;
+private static final IntBuffer textureIDBuffer = BufferUtils.createIntBuffer(1);
+private static final float zNear = 1.5f;//1.5f
+private static final float zFar = 0.1f;//0.1f
+private final int textureWidth=512;
+private final int textureHeight=512;
+private final int[] xdepth;
+private final int[] ydepth;
+private final int[] textureU;
+private final int[] textureV;
+private final Minecraft mc;
+private static final boolean useARB = true;
+
+public MirrorRender()
+{
+ xdepth=new int[] {0,0,1,1};
+ ydepth=new int[] {0,1,1,0};
+ textureU=new int[] {0,0,1,1};
+ textureV=new int[]{0,1,1,0};
+ mc=Minecraft.getMinecraft();
+}
+
+public void renderAModelAt(MirrorTileEntity tile, double x, double y, double z, float f) {
+ Tessellator tessellator=Tessellator.instance;
+ float[] mAxis = tile.getMirrorAxis();
+ if(texture==-1)
+ {
+ GL11.glGenTextures(textureIDBuffer);
+ texture=textureIDBuffer.get(0);
+ fb=GL30.glGenFramebuffers();
+ GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fb);
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
+ GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB8, textureWidth, textureHeight, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer)null);
+ GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
+ GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
+ GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,GL11. GL_LINEAR);
+ GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
+ int depthBuffer = GL30.glGenRenderbuffers();
+ GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
+ GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, textureWidth, textureHeight);
+ GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthBuffer);
+ GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texture, 0);
+ IntBuffer drawBuffs = BufferUtils.createIntBuffer(1);
+ drawBuffs.put(0, GL30.GL_COLOR_ATTACHMENT0);
+ GL20.glDrawBuffers(drawBuffs);// SPme parts of code here mindlessly taken from TheArni/Advanced-Graphics-Processing-Units. https://github.com/TheArni/Advanced-Graphics-Processing-Units/
+
+ if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE)
+ {
+ IHLMod.log.error("Something went wrong while creating frame buffer!");
+ IHLMod.log.error(GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER));
+ }
+ else
+ {
+ IHLMod.log.info("FrameBuffer loaded correctly!");
+ }
+ }
+ //Show reflection when:
+ //x>-1 when offsetX==-1
+ //x<0 when offsetX==1
+ if(tile.shouldReflect &&
+ ((x>-0.8D && mAxis[3]==-1)||
+ (x<-0.2 && mAxis[3]==1)||
+ (y>-0.8D && mAxis[4]==-1)||
+ (y<-0.2D && mAxis[4]==1)||
+ (z>-0.8D && mAxis[5]==-1)||
+ (z<-0.2D && mAxis[5]==1)))
+ {
+ GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fb);
+ drawReflection(tile, x, y, z, f);
+ mc.entityRenderer.setupCameraTransform(f, 0);
+ Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false);
+ GL11.glPushMatrix();
+ GL11.glTranslatef((float) x, (float) y , (float) z);
+ defineMeshAndTextureCoordinates(tile);
+ IHLRenderUtils.instance.enableAmbientLighting();
+ drawMirrorFrame(tile);
+ IHLRenderUtils.instance.disableAmbientLighting();
+ RenderHelper.enableStandardItemLighting();
+ GL11.glPopMatrix();
+ }
+}
+
+ @Override
+ public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8)
+ {
+ this.renderAModelAt((MirrorTileEntity)par1TileEntity, par2, par4, par6, par8);
+ }
+
+ private void drawReflection(MirrorTileEntity tile, double x, double y, double z, float f)
+ {
+ GL11.glViewport(0, 0, textureWidth, textureHeight);
+ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
+ GL11.glColor4f(1f, 1f, 1f, 1f);
+ setMirrorView(tile, x, y, z);
+ IHLRenderUtils.instance.enableAmbientLighting();
+ mc.renderGlobal.renderSky(f);
+ mc.renderGlobal.renderClouds(f);
+ IHLRenderUtils.instance.disableAmbientLighting();
+ setMirrorView(tile, x, y, z);
+ GL11.glColor4f(1f, 1f, 1f, 1f);
+ bindTexture(TextureMap.locationBlocksTexture);
+ GL11.glTranslatef((-tile.xCoord), (-tile.yCoord), (-tile.zCoord));
+ if (tile.displayListCache != -1)
+ {
+ GL11.glCallList(tile.displayListCache);
+ if(tile.needRenderUpdate)
+ {
+ IHLBlockRenderer.instance.refreshDisplayLists(tile.displayListCache, tile.bwc, tile.chunkCache);
+ tile.needRenderUpdate=false;
+ }
+ }
+ else if(tile.chunkCache!=null)
+ {
+ tile.displayListCache=GLAllocation.generateDisplayLists(1);
+ IHLBlockRenderer.instance.refreshDisplayLists(tile.displayListCache, tile.bwc, tile.chunkCache);
+ }
+ Iterator<Entity> ientity = tile.reflectedEntity.iterator();
+ while(ientity.hasNext())
+ {
+ Entity centity = ientity.next();
+ Render render = (Render) IHLMod.proxy.getRenderForEntityClass(centity.getClass());
+ if(render!=null)
+ {
+ render.doRender(centity, centity.prevPosX, centity.prevPosY, centity.prevPosZ, 1f, f);
+ GL11.glEnable(GL11.GL_COLOR_MATERIAL);
+ GL11.glColor4f(1f, 1f, 1f, 1f);
+ }
+ }
+ Iterator<TileEntity> itentity = tile.reflectedTileEntity.iterator();
+ while(itentity.hasNext())
+ {
+ TileEntity te = itentity.next();
+ if(TileEntityRendererDispatcher.instance.hasSpecialRenderer(te))
+ {
+ TileEntitySpecialRenderer specialRenderer = TileEntityRendererDispatcher.instance.getSpecialRenderer(te);
+ specialRenderer.renderTileEntityAt(te, te.xCoord, te.yCoord, te.zCoord, f);
+ GL11.glEnable(GL11.GL_COLOR_MATERIAL);
+ }
+ }
+ GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
+ }
+
+ private void defineMeshAndTextureCoordinates(MirrorTileEntity tile)
+ {
+ switch (tile.getFacing())
+ {
+ case 0://up
+ xdepth[0]=1+tile.reflectExtensionRight;
+ xdepth[1]=1+tile.reflectExtensionRight;
+ xdepth[2]=0;
+ xdepth[3]=0;
+ ydepth[0]=0;
+ ydepth[1]=1+tile.reflectExtensionTop;
+ ydepth[2]=1+tile.reflectExtensionTop;
+ ydepth[3]=0;
+ textureU[0]=0;
+ textureU[1]=0;
+ textureU[2]=1;
+ textureU[3]=1;
+ textureV[0]=0;
+ textureV[1]=1;
+ textureV[2]=1;
+ textureV[3]=0;
+ break;
+ case 1://down
+ xdepth[0]=-tile.reflectExtensionRight;
+ xdepth[1]=-tile.reflectExtensionRight;
+ xdepth[2]=1;
+ xdepth[3]=1;
+ ydepth[0]=-tile.reflectExtensionTop;
+ ydepth[1]=1;
+ ydepth[2]=1;
+ ydepth[3]=-tile.reflectExtensionTop;
+ textureU[0]=0;
+ textureU[1]=0;
+ textureU[2]=1;
+ textureU[3]=1;
+ textureV[0]=0;
+ textureV[1]=1;
+ textureV[2]=1;
+ textureV[3]=0;
+ break;
+ case 2:
+ xdepth[0]=0;
+ xdepth[1]=0;
+ xdepth[2]=1+tile.reflectExtensionRight;
+ xdepth[3]=1+tile.reflectExtensionRight;
+ ydepth[0]=0;
+ ydepth[1]=1+tile.reflectExtensionTop;
+ ydepth[2]=1+tile.reflectExtensionTop;
+ ydepth[3]=0;
+ textureU[0]=0;
+ textureU[1]=0;
+ textureU[2]=1;
+ textureU[3]=1;
+ textureV[0]=0;
+ textureV[1]=1;
+ textureV[2]=1;
+ textureV[3]=0;
+ break;
+ case 3:
+ xdepth[0]=-tile.reflectExtensionRight;
+ xdepth[1]=1;
+ xdepth[2]=1;
+ xdepth[3]=-tile.reflectExtensionRight;
+ ydepth[0]=0;
+ ydepth[1]=0;
+ ydepth[2]=1+tile.reflectExtensionTop;
+ ydepth[3]=1+tile.reflectExtensionTop;
+ textureU[0]=1;
+ textureU[1]=0;
+ textureU[2]=0;
+ textureU[3]=1;
+ textureV[0]=0;
+ textureV[1]=0;
+ textureV[2]=1;
+ textureV[3]=1;
+ break;
+ case 4:
+ xdepth[0]=-tile.reflectExtensionRight;
+ xdepth[1]=1;
+ xdepth[2]=1;
+ xdepth[3]=-tile.reflectExtensionRight;
+ ydepth[0]=0;
+ ydepth[1]=0;
+ ydepth[2]=1+tile.reflectExtensionTop;
+ ydepth[3]=1+tile.reflectExtensionTop;
+ textureU[0]=1;
+ textureU[1]=0;
+ textureU[2]=0;
+ textureU[3]=1;
+ textureV[0]=0;
+ textureV[1]=0;
+ textureV[2]=1;
+ textureV[3]=1;
+ break;
+ case 5:
+ xdepth[0]=0;
+ xdepth[1]=0;
+ xdepth[2]=1+tile.reflectExtensionRight;
+ xdepth[3]=1+tile.reflectExtensionRight;
+ ydepth[0]=0;
+ ydepth[1]=1+tile.reflectExtensionTop;
+ ydepth[2]=1+tile.reflectExtensionTop;
+ ydepth[3]=0;
+ textureU[0]=0;
+ textureU[1]=0;
+ textureU[2]=1;
+ textureU[3]=1;
+ textureV[0]=0;
+ textureV[1]=1;
+ textureV[2]=1;
+ textureV[3]=0;
+ break;
+ default:
+ }
+
+ }
+
+ private void drawMirrorFrame(MirrorTileEntity tile)
+ {
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
+ GL11.glColor4f(1f, 1f, 1f, 1f);
+ GL11.glDisable(GL11.GL_BLEND);
+ Tessellator tessellator=Tessellator.instance;
+ tessellator.startDrawingQuads();
+ for(int i=0;i<xdepth.length;i++)
+ {
+ switch (tile.getFacing())
+ {
+ case 0:
+ tessellator.addVertexWithUV(xdepth[i], 0.9d, ydepth[i],textureU[i],textureV[i]);
+ break;
+ case 1:
+ tessellator.addVertexWithUV(xdepth[i], 0.1d, ydepth[i],textureU[i],textureV[i]);
+ break;
+ case 2:
+ tessellator.addVertexWithUV(xdepth[i], ydepth[i], 0.9d,textureU[i],textureV[i]);
+ break;
+ case 3:
+ tessellator.addVertexWithUV(xdepth[i], ydepth[i], 0.1d,textureU[i],textureV[i]);
+ break;
+ case 4:
+ tessellator.addVertexWithUV(0.9d, ydepth[i], xdepth[i],textureU[i],textureV[i]);
+ break;
+ case 5:
+ tessellator.addVertexWithUV(0.1d, ydepth[i], xdepth[i],textureU[i],textureV[i]);
+ break;
+ default:
+ }
+ }
+ tessellator.draw();
+ }
+
+ private void setMirrorView(MirrorTileEntity tile, double x, double y, double z)
+ {
+ float mirrorHeightCoorrection, mirrorWidthCoorrection, xShift, yShift, shiftCorrection,yCorrection,xCorrection,zCorrection;
+ GL11.glMatrixMode(GL11.GL_PROJECTION);
+ GL11.glLoadIdentity();
+ Project.gluPerspective(65f, (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.mc.gameSettings.renderDistanceChunks * 32F);
+ GL11.glMatrixMode(GL11.GL_MODELVIEW);
+ GL11.glLoadIdentity();
+ double aspectRatioMirror = Math.sqrt((tile.reflectExtensionTop+1)/(double)(tile.reflectExtensionRight+1));
+ double aspectRatio = Display.getHeight()/(double)Display.getWidth()/aspectRatioMirror;
+ shiftCorrection = tile.reflectExtensionTop*0.45f+tile.reflectExtensionRight*0.45f-0.5f;
+ float kYS = 0.5f;//0.5f;
+ float kZS = 0.0f;//0.5f;
+ switch(tile.getFacing())
+ {
+ //swap y and z
+ case 0://down facing mirror
+ mirrorHeightCoorrection = (tile.reflectExtensionTop+1)*0.5f;
+ yShift = (float)(z+mirrorHeightCoorrection)*kYS;
+ yCorrection = mirrorHeightCoorrection-yShift*(tile.reflectExtensionTop*0.5f+1f);
+ zCorrection = 2f+shiftCorrection-kZS;
+ mirrorWidthCoorrection = (-tile.reflectExtensionRight+1)*0.5f;
+ xShift = (float)(-x+mirrorWidthCoorrection)*0.5f-0.5f;
+ GL11.glFrustum(-aspectRatio+xShift, aspectRatio+xShift, -aspectRatioMirror+yShift, aspectRatioMirror+yShift, zNear, zFar);
+ xCorrection = mirrorWidthCoorrection+xShift*(tile.reflectExtensionRight*0.5f-0.375f/(tile.reflectExtensionRight+1)+1.125f);
+ GLU.gluLookAt(xCorrection+tile.reflectExtensionRight, zCorrection, yCorrection, xCorrection+tile.reflectExtensionRight/*x reference*/, -32f+zCorrection/*y reference*/, yCorrection/*z reference*/, 0.0f, 0.0f, 1.0f);
+ break;
+ case 1://up facing mirror
+ mirrorHeightCoorrection = (-tile.reflectExtensionTop+1)*0.5f;
+ yShift = (float)(z+mirrorHeightCoorrection)*kYS;
+ yCorrection = mirrorHeightCoorrection-yShift*(tile.reflectExtensionTop*0.5f+1f);
+ zCorrection = -1f-shiftCorrection-kZS;
+ mirrorWidthCoorrection = (-tile.reflectExtensionRight+1)*0.5f;
+ xShift = (float)(x+mirrorWidthCoorrection)*0.5f;
+ GL11.glFrustum(-aspectRatio+xShift, aspectRatio+xShift, -aspectRatioMirror+yShift, aspectRatioMirror+yShift, zNear, zFar);
+ xCorrection = mirrorWidthCoorrection-xShift*(tile.reflectExtensionRight*0.5f+1f);
+ GLU.gluLookAt(xCorrection, zCorrection, yCorrection, xCorrection/*x reference*/, 32f+zCorrection/*y reference*/, yCorrection/*z reference*/, 0.0f, 0.0f, 1.0f);
+ break;
+ case 2:
+ mirrorHeightCoorrection = (tile.reflectExtensionTop+1)*0.5f;
+ yShift = (float)(y+mirrorHeightCoorrection)*kYS;
+ yCorrection = mirrorHeightCoorrection-yShift*(tile.reflectExtensionTop*0.5f+1f);
+ zCorrection = 2f+shiftCorrection-kZS;
+ mirrorWidthCoorrection = (tile.reflectExtensionRight+1)*0.5f;
+ xShift = (float)(x+mirrorWidthCoorrection)*0.5f;
+ GL11.glFrustum(-aspectRatio+xShift, aspectRatio+xShift, -aspectRatioMirror+yShift, aspectRatioMirror+yShift, zNear, zFar);
+ xCorrection = mirrorWidthCoorrection-xShift*(tile.reflectExtensionRight*0.5f+1f);
+ GLU.gluLookAt(xCorrection, yCorrection, zCorrection, xCorrection/*x reference*/, yCorrection/*y reference*/, -32f+zCorrection/*z reference*/, 0.0f, 1.0f, 0.0f);
+ break;
+ case 3:
+ mirrorHeightCoorrection = (tile.reflectExtensionTop+1)*0.5f;
+ yShift = (float)(y+mirrorHeightCoorrection)*kYS;
+ yCorrection = mirrorHeightCoorrection-yShift*(tile.reflectExtensionRight*0.5f+1f);
+ zCorrection = -1f-shiftCorrection-kZS;
+ mirrorWidthCoorrection = 0.5f-tile.reflectExtensionRight*0.5f;
+ xShift = (float)(-x-mirrorWidthCoorrection)*0.5f;
+ GL11.glFrustum(-aspectRatio+xShift, aspectRatio+xShift, -aspectRatioMirror+yShift, aspectRatioMirror+yShift, zNear, zFar);
+ xCorrection = mirrorWidthCoorrection+xShift*(tile.reflectExtensionTop*0.5f-0.375f/(tile.reflectExtensionTop+1)+1.125f);
+ GLU.gluLookAt(xCorrection, yCorrection, zCorrection, xCorrection/*x reference*/, yCorrection/*y reference*/, 32f+zCorrection/*z reference*/, 0.0f, 1.0f, 0.0f);
+ break;
+ case 4:
+ mirrorHeightCoorrection = (tile.reflectExtensionTop+1)*0.5f;
+ yShift = (float)(y+mirrorHeightCoorrection)*kYS;
+ yCorrection = mirrorHeightCoorrection-yShift*(tile.reflectExtensionTop*0.5f+1f);
+ zCorrection = 2f+shiftCorrection-kZS;
+ mirrorWidthCoorrection = 0.5f-tile.reflectExtensionRight*0.5f;
+ xShift = (float)(-z-mirrorWidthCoorrection)*0.5f;
+ GL11.glFrustum(-aspectRatio+xShift, aspectRatio+xShift, -aspectRatioMirror+yShift, aspectRatioMirror+yShift, zNear, zFar);
+ xCorrection = mirrorWidthCoorrection+xShift*(tile.reflectExtensionRight*0.5f-0.375f/(tile.reflectExtensionRight+1)+1.125f);
+ GLU.gluLookAt(zCorrection, yCorrection, xCorrection, zCorrection-32f/*x reference*/, yCorrection/*y reference*/, xCorrection/*z reference*/, 0.0f, 1.0f, 0.0f);
+ break;
+ case 5:
+ mirrorHeightCoorrection = (tile.reflectExtensionTop+1)*0.5f;
+ yShift = (float)(y+mirrorHeightCoorrection)*kYS;
+ yCorrection = mirrorHeightCoorrection-yShift*(tile.reflectExtensionTop*0.5f+1f);
+ zCorrection = -1f-shiftCorrection-kZS;
+ mirrorWidthCoorrection = (tile.reflectExtensionRight+1)*0.5f;
+ xShift = (float)(z+mirrorWidthCoorrection)*0.5f;
+ GL11.glFrustum(-aspectRatio+xShift, aspectRatio+xShift, -aspectRatioMirror+yShift, aspectRatioMirror+yShift, zNear, zFar);
+ xCorrection = mirrorWidthCoorrection-xShift*(tile.reflectExtensionRight*0.5f+1f);
+ GLU.gluLookAt(zCorrection, yCorrection, xCorrection, zCorrection+32f/*x reference*/, yCorrection/*y reference*/, xCorrection/*z reference*/, 0.0f, 1.0f, 0.0f);
+ break;
+ default:
+ mirrorHeightCoorrection = (tile.reflectExtensionTop+1)*0.5f;
+ yShift = (float)(y+mirrorHeightCoorrection)*kYS;
+ yCorrection = mirrorHeightCoorrection-yShift*(tile.reflectExtensionTop*0.5f+1f);
+ zCorrection = 2f+shiftCorrection-kZS;
+ mirrorWidthCoorrection = (tile.reflectExtensionRight+1)*0.5f;
+ xShift = (float)(x+mirrorWidthCoorrection)*0.5f;
+ GL11.glFrustum(-aspectRatio+xShift, aspectRatio+xShift, -aspectRatioMirror+yShift, aspectRatioMirror+yShift, zNear, zFar);
+ xCorrection = mirrorWidthCoorrection-xShift*(tile.reflectExtensionRight*0.5f+1f);
+ GLU.gluLookAt(xCorrection, yCorrection, zCorrection, xCorrection/*x reference*/, yCorrection/*y reference*/, -32f+zCorrection/*z reference*/, 0.0f, 1.0f, 0.0f);
+ }
+ }
+
+ public static void deleteTextures()
+ {
+ GL11.glDeleteTextures(textureIDBuffer);
+ }
+} \ No newline at end of file
diff --git a/ihl/enviroment/MirrorTileEntity.java b/ihl/enviroment/MirrorTileEntity.java
new file mode 100644
index 0000000..083f61d
--- /dev/null
+++ b/ihl/enviroment/MirrorTileEntity.java
@@ -0,0 +1,451 @@
+package ihl.enviroment;
+
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.block.Block;
+import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityBoat;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.entity.item.EntityMinecart;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.world.ChunkCache;
+import net.minecraftforge.common.util.ForgeDirection;
+import ic2.core.block.TileEntityBlock;
+import ihl.IHLMod;
+import ihl.handpump.BlockWithCoordinates;
+import ihl.utils.IHLUtils;
+
+public class MirrorTileEntity extends TileEntityBlock
+{
+ public final List<BlockWithCoordinates> bwc = new ArrayList();
+ public final List<Entity> reflectedEntity = new ArrayList();
+ public final List<TileEntity> reflectedTileEntity = new ArrayList();
+ private int bwcListPos=0;
+ private int reflectedEntityListPos=0;
+ private int reflectedTileEntityListPos=0;
+ private int reflectionVolumePos=0;
+ boolean firstTick=true;
+ public int dnx,dpx,dny,dpy,dnz,dpz;
+ boolean shouldReflect=true;
+ int reflectExtensionRight=0;
+ int reflectExtensionTop=0;
+ int timer=0;
+ int blockReflectionUpdateTimer=0;
+ int reflectionVolumeSize=-1;
+ AxisAlignedBB reflectionArea;
+ int displayListCache=-1;
+ public ChunkCache chunkCache;
+ public boolean needRenderUpdate=false;
+ private int minX;
+ private int maxX;
+ private int minY;
+ private int maxY;
+ private int minZ;
+ private int maxZ;
+ private int lastBWCSize;
+
+ public MirrorTileEntity()
+ {}
+
+ @Override
+ public void updateEntityClient()
+ {
+ super.updateEntityClient();
+ if(this.shouldReflect)
+ {
+ int i=0;
+ for(i=0;i<Math.min(this.reflectionVolumeSize, IHLMod.config.mirrorReflectionUpdateSpeed);i++)
+ {
+ this.checkReflectionVolume();
+ }
+ for(i=0;i<Math.min(this.bwc.size(), IHLMod.config.mirrorReflectionUpdateSpeed);i++)
+ {
+ this.checkBWCList();
+ }
+ for(i=0;i<Math.min(this.reflectedTileEntity.size(), IHLMod.config.mirrorReflectionUpdateSpeed);i++)
+ {
+ this.checkTileEntityList();
+ }
+ }
+ if(timer++>20)
+ {
+ boolean isFirst=true;
+ TileEntity t = worldObj.getTileEntity(xCoord-mXT(),yCoord-mYT(), zCoord-mZT());
+ if(t instanceof MirrorTileEntity)
+ {
+ if(((MirrorTileEntity)t).getFacing()==this.getFacing())
+ {
+ isFirst=false;
+ }
+ }
+ t = worldObj.getTileEntity(xCoord-mXR(),yCoord-mYR(), zCoord-mZR());
+ if(t instanceof MirrorTileEntity)
+ {
+ if(((MirrorTileEntity)t).getFacing()==this.getFacing())
+ {
+ isFirst=false;
+ }
+ }
+ if(isFirst)
+ {
+ this.shouldReflect=true;
+ this.reflectExtensionTop=0;
+ this.reflectExtensionRight=0;
+ for(int i=1;i<=IHLMod.config.mirrorReflectionRange+2;i++)
+ {
+ t = worldObj.getTileEntity(xCoord+mXT()*i,yCoord+mYT()*i, zCoord+mZT()*i);
+ if(t instanceof MirrorTileEntity && ((MirrorTileEntity)t).getFacing()==this.getFacing())
+ {
+ MirrorTileEntity te = (MirrorTileEntity) t;
+ te.shouldReflect=false;
+ this.reflectExtensionTop=i;
+ }
+ else
+ {
+ break;
+ }
+ }
+ a:for(int i0=1;i0<=IHLMod.config.mirrorReflectionRange+2;i0++)
+ {
+ for(int i=0;i<=this.reflectExtensionTop;i++)
+ {
+ t = worldObj.getTileEntity(xCoord+mXT()*i+mXR()*i0,yCoord+mYT()*i+mYR()*i0, zCoord+mZT()*i+mZR()*i0);
+ if(t instanceof MirrorTileEntity && ((MirrorTileEntity)t).getFacing()==this.getFacing())
+ {
+ MirrorTileEntity te = (MirrorTileEntity) t;
+ te.shouldReflect=false;
+ }
+ else
+ {
+ break a;
+ }
+ }
+ this.reflectExtensionRight=i0;
+ }
+ }
+ if(this.reflectionArea!=null)
+ {
+ this.reflectedEntity.clear();
+ this.reflectedEntity.addAll(worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.reflectionArea));
+ this.reflectedEntity.addAll(worldObj.getEntitiesWithinAABB(EntityBoat.class, this.reflectionArea));
+ this.reflectedEntity.addAll(worldObj.getEntitiesWithinAABB(EntityItem.class, this.reflectionArea));
+ this.reflectedEntity.addAll(worldObj.getEntitiesWithinAABB(EntityMinecart.class, this.reflectionArea));
+ }
+ timer=0;
+ }
+ if(firstTick && this.shouldReflect)
+ {
+ int ix,iy,iz;
+ int range=IHLMod.config.mirrorReflectionRange;
+ ForgeDirection direction = ForgeDirection.getOrientation(this.getFacing());
+ bwc.clear();
+ {
+ dpx = direction.offsetX==-1?0:1;
+ dnx = direction.offsetX==1?0:1;
+ dpy = direction.offsetY==-1?0:1;
+ dny = direction.offsetY==1?0:1;
+ dpz = direction.offsetZ==-1?0:1;
+ dnz = direction.offsetZ==1?0:1;
+ reflectionVolumeSize=(range*dnx+range*dpx+dnx)*(range*dny+range*dpy+dny)*(range*dnz+range*dpz+dnz);
+ reflectionArea = AxisAlignedBB.getBoundingBox(xCoord-range*dnx-1d, yCoord-range*dny-1d, zCoord-range*dnz-1d, xCoord+range*dpx+dnx+1d, yCoord+range*dpy+dny+1d, zCoord+range*dpz+dnz+1d);
+ minX = xCoord-range*dnx;
+ maxX = xCoord+range*dpx+dnx;
+ minY = Math.max(yCoord-range*dny,0);
+ maxY = Math.min(yCoord+range*dpy+dny,this.worldObj.getActualHeight());
+ minZ = zCoord-range*dnz;
+ maxZ = zCoord+range*dpz+dnz;
+ chunkCache = new ChunkCache(worldObj, minX, minY, minZ, maxX, maxY, maxZ, 16);
+ for(ix=minX;ix<maxX;ix++)
+ {
+ for(iy=minY;iy<maxY;iy++)
+ {
+ for(iz=minZ;iz<maxZ;iz++)
+ {
+ Block block = worldObj.getBlock(ix, iy, iz);
+ if(block!=null && !block.isAir(worldObj, ix, iy, iz) && isBlockVisible(block,ix,iy,iz))
+ {
+ TileEntity te = worldObj.getTileEntity(ix, iy, iz);
+ if(te!=null && !te.isInvalid() && !reflectedTileEntity.contains(te) && TileEntityRendererDispatcher.instance.hasSpecialRenderer(te) && !(te instanceof MirrorTileEntity))
+ {
+ reflectedTileEntity.add(te);
+ }
+ if(block.getRenderType()>=0)
+ {
+ bwc.add(new BlockWithCoordinates(block, ix, iy, iz, worldObj.getBlockMetadata(ix, iy, iz)));
+ }
+ }
+
+ }
+ }
+ }
+ }
+ lastBWCSize=bwc.size();
+ firstTick=false;
+ }
+ }
+
+ private void dropMirrorStatusByDirection(ForgeDirection direction)
+ {
+ for(int i=1;i<=IHLMod.config.mirrorReflectionRange+2;i++)
+ {
+ TileEntity t = worldObj.getTileEntity(xCoord+direction.offsetX*i,yCoord+direction.offsetY*i, zCoord+direction.offsetZ*i);
+ if(t instanceof MirrorTileEntity)
+ {
+ MirrorTileEntity te = (MirrorTileEntity) t;
+ te.firstTick=false;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ }
+
+ private boolean isBlockVisible(Block block, int x, int y, int z)
+ {
+ if(block instanceof MirrorBlock)
+ {
+ ForgeDirection direction = ForgeDirection.getOrientation(this.getFacing());
+ int x1=x*direction.offsetX;
+ int y1=y*direction.offsetY;
+ int z1=z*direction.offsetZ;
+ int x2=xCoord*direction.offsetX;
+ int y2=yCoord*direction.offsetY;
+ int z2=zCoord*direction.offsetZ;
+ return !(x1==x2 && y1==y2 && z1==z2);
+ }
+ if(block.shouldSideBeRendered(worldObj, x, y-1, z, 0))
+ {
+ return true;
+ }
+ if(block.shouldSideBeRendered(worldObj, x, y+1, z, 1))
+ {
+ return true;
+ }
+ if(block.shouldSideBeRendered(worldObj, x, y, z-1, 2))
+ {
+ return true;
+ }
+ if(block.shouldSideBeRendered(worldObj, x, y, z+1, 3))
+ {
+ return true;
+ }
+ if(block.shouldSideBeRendered(worldObj, x-1, y, z, 4))
+ {
+ return true;
+ }
+ if(block.shouldSideBeRendered(worldObj, x+1, y, z, 5))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
+ return false;
+ }
+
+ @Override
+ public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
+ return true;
+ }
+
+ @Override
+ public void setFacing(short side)
+ {
+ super.setFacing(side);
+ this.bwc.clear();
+ this.firstTick=true;
+ }
+
+ @Override
+ public float getWrenchDropRate() {
+ return 1F;
+ }
+
+ @Override
+ public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
+ return IHLUtils.getThisModItemStack("mirror");
+ }
+
+ public float[] getMirrorAxis()
+ {
+ ForgeDirection direction = ForgeDirection.getOrientation(this.getFacing());
+ int mx = direction.offsetX!=0?-1:1;
+ int my = direction.offsetY!=0?-1:1;
+ int mz = direction.offsetZ!=0?-1:1;
+ return new float[] {mx,my,mz,direction.offsetX,direction.offsetY,direction.offsetZ};
+ }
+
+ private void checkBWCList()
+ {
+ if(++this.bwcListPos>=bwc.size())
+ {
+ this.bwcListPos=0;
+ }
+ if(!bwc.isEmpty())
+ {
+ BlockWithCoordinates bwcEntry = bwc.get(bwcListPos);
+ if(bwcEntry.block!=worldObj.getBlock(bwcEntry.x, bwcEntry.y, bwcEntry.z))
+ {
+ bwc.remove(bwcListPos);
+ }
+ }
+ }
+
+ private void checkTileEntityList()
+ {
+ if(++this.reflectedTileEntityListPos>=reflectedTileEntity.size())
+ {
+ this.reflectedTileEntityListPos=0;
+ }
+ if(!reflectedTileEntity.isEmpty())
+ {
+ TileEntity entry = reflectedTileEntity.get(reflectedTileEntityListPos);
+ if(entry==null || entry.isInvalid() || entry!=worldObj.getTileEntity(entry.xCoord, entry.yCoord, entry.zCoord))
+ {
+ reflectedTileEntity.remove(reflectedTileEntityListPos);
+ }
+ }
+ }
+
+ private void checkReflectionVolume()
+ {
+ if(++this.reflectionVolumePos>=reflectionVolumeSize)
+ {
+ this.reflectionVolumePos=0;
+ if(lastBWCSize!=bwc.size())
+ {
+ this.needRenderUpdate=true;
+ lastBWCSize=bwc.size();
+ }
+ }
+ if(reflectionVolumeSize>0)
+ {
+ int range=IHLMod.config.mirrorReflectionRange;
+ //reflectionVolumePos = x+y*maxX+z*maxX*maxY;
+ int z = reflectionVolumePos / (maxX-minX) / (maxY-minY);
+ int y = (reflectionVolumePos % ((maxX-minX) * (maxY-minY)))/ (maxX-minX);
+ int x = reflectionVolumePos - y * (maxX-minX) - z * (maxX-minX) * (maxY-minY);
+ //for example position is 69 volume is 4*5*5=100, therefore z will be 69 / (4*5)=3
+ //y will be (69 % (4*5))/4=9/4=2
+ //x will be 69 - 2*4 - 3*4*5 = 69-8-60=1
+ //for check 1+2*4+3*4*5=1+8+60
+ int ix = minX+x;
+ int iy = minY+y;
+ int iz = minZ+z;
+ Block block = worldObj.getBlock(ix, iy, iz);
+ if(block!=null && !block.isAir(worldObj, ix, iy, iz) && isBlockVisible(block,ix,iy,iz))
+ {
+ TileEntity te = worldObj.getTileEntity(ix, iy, iz);
+ if(te!=null && !te.isInvalid() && !reflectedTileEntity.contains(te) && TileEntityRendererDispatcher.instance.hasSpecialRenderer(te) && !(te instanceof MirrorTileEntity))
+ {
+ reflectedTileEntity.add(te);
+ }
+ if(block.getRenderType()>=0)
+ {
+ BlockWithCoordinates bwc1 = new BlockWithCoordinates(block, ix, iy, iz, worldObj.getBlockMetadata(ix, iy, iz));
+ if(!bwc.contains(bwc1))
+ {
+ bwc.add(bwc1);
+ }
+ }
+ }
+ }
+ }
+
+ private int mXR()
+ {
+ switch(this.getFacing())
+ {
+ case 0:
+ return 1;
+ case 1:
+ return -1;
+ case 2:
+ return 1;
+ case 3:
+ return -1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mYR()
+ {
+ return 0;
+ }
+
+ private int mZR()
+ {
+ switch(this.getFacing())
+ {
+ case 4:
+ return -1;
+ case 5:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mXT()
+ {
+ return 0;
+ }
+
+ private int mYT()
+ {
+ switch(this.getFacing())
+ {
+ case 2:
+ return 1;
+ case 3:
+ return 1;
+ case 4:
+ return 1;
+ case 5:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mZT()
+ {
+ switch(this.getFacing())
+ {
+ case 0:
+ return 1;
+ case 1:
+ return -1;
+ default:
+ return 0;
+ }
+ }
+
+ @Override
+ public AxisAlignedBB getRenderBoundingBox()
+ {
+ double xMinD=(double)this.xCoord-this.reflectExtensionRight*Math.abs(this.mXR())-this.reflectExtensionTop*Math.abs(this.mXT());
+ double xMaxD=(double)this.xCoord+this.reflectExtensionRight*Math.abs(this.mXR())+this.reflectExtensionTop*Math.abs(this.mXT())+1d;
+ double yMinD=(double)this.yCoord-this.reflectExtensionRight*Math.abs(this.mYR())-this.reflectExtensionTop*Math.abs(this.mYT());
+ double yMaxD=(double)this.yCoord+this.reflectExtensionRight*Math.abs(this.mYR())+this.reflectExtensionTop*Math.abs(this.mYT())+1d;
+ double zMinD=(double)this.zCoord-this.reflectExtensionRight*Math.abs(this.mZR())-this.reflectExtensionTop*Math.abs(this.mZT());
+ double zMaxD=(double)this.zCoord+this.reflectExtensionRight*Math.abs(this.mZR())+this.reflectExtensionTop*Math.abs(this.mZT())+1d;
+ return AxisAlignedBB.getBoundingBox(xMinD, yMinD, zMinD, xMaxD, yMaxD, zMaxD);
+ }
+
+ @Override
+ public boolean shouldRenderInPass(int pass)
+ {
+ return pass==0;
+ }
+} \ No newline at end of file
diff --git a/ihl/enviroment/SpotlightBlock.java b/ihl/enviroment/SpotlightBlock.java
new file mode 100644
index 0000000..2cabecf
--- /dev/null
+++ b/ihl/enviroment/SpotlightBlock.java
@@ -0,0 +1,108 @@
+package ihl.enviroment;
+
+import ic2.core.IC2;
+import ihl.IHLCreativeTab;
+import ihl.items_blocks.IHLItemBlock;
+
+import java.util.Random;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.ITileEntityProvider;
+import net.minecraft.block.material.Material;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+import cpw.mods.fml.common.registry.GameRegistry;
+
+public class SpotlightBlock extends Block implements ITileEntityProvider
+{
+
+ public SpotlightBlock(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");
+ }
+
+ @Override
+ public boolean hasTileEntity(int metadata)
+ {
+ return true;
+ }
+
+ /**
+ * 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 boolean isOpaqueCube()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isNormalCube()
+ {
+ return false;
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World arg0, int arg1)
+ {
+ return new SpotlightTileEntity();
+ }
+
+ @Override
+ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack)
+ {
+ TileEntity t = world.getTileEntity(x, y, z);
+ if(IC2.platform.isSimulating() && t instanceof SpotlightTileEntity)
+ {
+ SpotlightTileEntity te = (SpotlightTileEntity)t;
+ te.setDirectionVector(player);
+ }
+ }
+
+ @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);
+ if(IC2.platform.isSimulating() && te instanceof SpotlightTileEntity)
+ {
+ ((SpotlightTileEntity)te).setDirectionVector(player);
+ return true;
+ }
+ return false;
+ }
+
+
+
+
+} \ No newline at end of file
diff --git a/ihl/enviroment/SpotlightModel.java b/ihl/enviroment/SpotlightModel.java
new file mode 100644
index 0000000..057bf94
--- /dev/null
+++ b/ihl/enviroment/SpotlightModel.java
@@ -0,0 +1,71 @@
+package ihl.enviroment;
+
+import ihl.model.IHLModelRenderer;
+import net.minecraft.client.model.ModelBase;
+
+
+public class SpotlightModel extends ModelBase
+{
+ //fields
+ IHLModelRenderer Base;
+ IHLModelRenderer RotatingPart1;
+ IHLModelRenderer RotatingPart2;
+ IHLModelRenderer RotatingPart3Halo;
+
+ public SpotlightModel()
+ {
+ textureWidth = 64;
+ textureHeight = 32;
+ setTextureOffset("Base.Shape1", 0, 0);
+ setTextureOffset("RotatingPart1.Shape3", 0, 0);
+ setTextureOffset("RotatingPart1.Shape2", 0, 0);
+ setTextureOffset("RotatingPart1.Shape4", 0, 0);
+ setTextureOffset("RotatingPart2.Shape5", 0, 15);
+ setTextureOffset("RotatingPart2.Shape6", 13, 14);
+ setTextureOffset("RotatingPart2.Shape7", 7, 15);
+ setTextureOffset("RotatingPart2.Shape8", 14, 8);
+ setTextureOffset("RotatingPart2.Shape9", 6, 8);
+ setTextureOffset("RotatingPart2.Shape10", 0, 23);
+ setTextureOffset("RotatingPart2.Shape11", 0, 0);
+ setTextureOffset("RotatingPart2.Shape12", 0, 0);
+ setTextureOffset("RotatingPart3Halo.Shape13", 32, 0);
+
+ Base = new IHLModelRenderer(this, "Base");
+ Base.setRotationPoint(0F, 16F, 0F);
+ setRotation(Base, 0F, 0F, 0F);
+ Base.mirror = false;
+ Base.addBox("Shape1", -7F, -7F, 7F, 14, 14, 1);
+ RotatingPart1 = new IHLModelRenderer(this, "RotatingPart1");
+ RotatingPart1.setRotationPoint(0F, 16F, 0F);
+ setRotation(RotatingPart1, 0F, 0F, 0F);
+ RotatingPart1.mirror = false;
+ RotatingPart1.addBox("Shape3", 5F, -1F, -1F, 1, 2, 8);
+ RotatingPart1.addBox("Shape2", -6F, -1F, -1F, 1, 2, 8);
+ RotatingPart1.addBox("Shape4", -5F, -1F, 6F, 10, 2, 1);
+ RotatingPart2 = new IHLModelRenderer(this, "RotatingPart2");
+ RotatingPart2.setRotationPoint(0F, 16F, 0F);
+ setRotation(RotatingPart2, 0F, 0F, 0F);
+ RotatingPart2.mirror = false;
+ RotatingPart2.addBox("Shape5", -4F, -4F, -6F, 7, 1, 7);
+ RotatingPart2.addBox("Shape6", -4F, -4F, 1F, 8, 8, 1);
+ RotatingPart2.addBox("Shape7", -3F, 3F, -6F, 7, 1, 7);
+ RotatingPart2.addBox("Shape8", 3F, -4F, -6F, 1, 7, 7);
+ RotatingPart2.addBox("Shape9", -4F, -3F, -6F, 1, 7, 7);
+ RotatingPart2.addBox("Shape10", -3F, -3F, -5F, 6, 6, 1);
+ RotatingPart2.addBox("Shape11", 4F, -1F, -1F, 1, 2, 2);
+ RotatingPart2.addBox("Shape12", -5F, -1F, -1F, 1, 2, 2);
+ RotatingPart3Halo = new IHLModelRenderer(this, "RotatingPart3Halo");
+ RotatingPart3Halo.setRotationPoint(0F, 16F, 0F);
+ setRotation(RotatingPart3Halo, 0F, 0F, 0F);
+ RotatingPart3Halo.mirror = false;
+ RotatingPart3Halo.addBox("Shape13", -8F, -8F, -6.1F, 16, 16, 0);
+ }
+
+ private void setRotation(IHLModelRenderer model, float x, float y, float z)
+ {
+ model.rotateAngleX = x;
+ model.rotateAngleY = y;
+ model.rotateAngleZ = z;
+ }
+
+}
diff --git a/ihl/enviroment/SpotlightRender.java b/ihl/enviroment/SpotlightRender.java
new file mode 100644
index 0000000..e38e251
--- /dev/null
+++ b/ihl/enviroment/SpotlightRender.java
@@ -0,0 +1,109 @@
+package ihl.enviroment;
+import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.opengl.GL11;
+
+import ihl.IHLModInfo;
+import ihl.utils.IHLRenderUtils;
+
+public class SpotlightRender extends TileEntitySpecialRenderer{
+private SpotlightModel model = new SpotlightModel();
+private ResourceLocation tex = new ResourceLocation(IHLModInfo.MODID+":textures/blocks/spotlight.png");
+private final float scale=1F/16F;
+
+ public SpotlightRender() {}
+
+
+ @Override
+ public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float par8)
+ {
+ SpotlightTileEntity cte = (SpotlightTileEntity)tile;
+ int rotation = 0;
+ int rotationz = 0;
+ if(tile.getWorldObj() != null)
+ {
+ switch (cte.getFacing())
+ {
+ case 0:
+ rotationz = 1;
+ break;
+ case 1:
+ rotationz = 3;
+ break;
+ case 2:
+ rotation = 2;
+ break;
+ case 5:
+ rotation = 3;
+ break;
+ case 3:
+ rotation = 0;
+ break;
+ case 4:
+ rotation = 1;
+ break;
+ default:
+ rotation = 0;
+ }
+ }
+ else
+ {
+ return;
+ }
+ model.Base.rotateAngleY=(float) (rotation*Math.PI/2);
+ model.Base.rotateAngleX=(float) (rotationz*Math.PI/2);
+ model.RotatingPart1.rotateAngleY=(float) (rotation*Math.PI/2);
+ model.RotatingPart1.rotateAngleX=(float) (rotationz*Math.PI/2);
+ model.RotatingPart2.rotateAngleY=(float) (rotation*Math.PI/2);
+ model.RotatingPart2.rotateAngleX=(float) (rotationz*Math.PI/2);
+ model.RotatingPart3Halo.rotateAngleY=(float) (rotation*Math.PI/2);
+ model.RotatingPart3Halo.rotateAngleX=(float) (rotationz*Math.PI/2);
+ model.RotatingPart2.rotateAngleX+=cte.rotationPitch;
+ model.RotatingPart3Halo.rotateAngleX+=cte.rotationPitch;
+ GL11.glPushMatrix();
+ GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
+ GL11.glScalef(1.0F, -1F, -1F);
+ 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);
+ model.Base.render(scale);
+ GL11.glTranslatef(model.RotatingPart1.rotationPointX*scale, model.RotatingPart1.rotationPointY*scale, model.RotatingPart1.rotationPointZ*scale);
+ switch(cte.getFacing())
+ {
+ case 0:
+ GL11.glRotatef(cte.rotationYaw * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
+ break;
+ case 1:
+ GL11.glRotatef(cte.rotationYaw * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
+ break;
+ case 2:
+ GL11.glRotatef(cte.rotationYaw * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
+ break;
+ case 3:
+ GL11.glRotatef(cte.rotationYaw * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
+ break;
+ case 4:
+ GL11.glRotatef(cte.rotationYaw * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
+ break;
+ case 5:
+ GL11.glRotatef(cte.rotationYaw * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
+ break;
+ }
+ GL11.glTranslatef(-model.RotatingPart1.rotationPointX*scale, -model.RotatingPart1.rotationPointY*scale, -model.RotatingPart1.rotationPointZ*scale);
+ model.RotatingPart1.render(scale);
+ model.RotatingPart2.render(scale);
+ if(cte.getActive())
+ {
+ IHLRenderUtils.instance.enableAmbientLighting();
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
+ model.RotatingPart3Halo.render(scale);
+ IHLRenderUtils.instance.disableAmbientLighting();
+ }
+
+ GL11.glDisable(GL11.GL_BLEND);
+ GL11.glPopMatrix(); //end
+
+ }
+} \ No newline at end of file
diff --git a/ihl/enviroment/SpotlightTileEntity.java b/ihl/enviroment/SpotlightTileEntity.java
new file mode 100644
index 0000000..04b340b
--- /dev/null
+++ b/ihl/enviroment/SpotlightTileEntity.java
@@ -0,0 +1,334 @@
+package ihl.enviroment;
+import ic2.api.network.INetworkTileEntityEventListener;
+import ic2.core.IC2;
+import ic2.core.network.NetworkManager;
+import ihl.IHLModInfo;
+import ihl.i_hate_liquids.XYZ;
+import ihl.utils.IHLUtils;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.ItemStack;
+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();
+ private static final Set<Vec3> lightSphereVectors = new HashSet();
+ 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));
+ }
+ }
+ }
+
+ @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);
+ }
+ }
+ }
+
+ 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 void updateEntity()
+ {
+ super.updateEntity();
+ if(needLightTargetUpdate)
+ {
+ this.generateGlowningAirList();
+ this.updateLightState();
+ needLightTargetUpdate=false;
+ }
+ 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());
+ }
+ }
+
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ @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));
+ }
+ }
+
+ 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;
+ }
+ }
+
+ @Override
+ 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};*/