diff --git a/build.gradle b/build.gradle index e498b01d..71be6dec 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-v0.9.3-Beta-Pre1" +version = "1.7.10-v0.9.3-Beta-Pre3" group= "com.brandon3055.draconicevolution" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "Draconic-Evolution" diff --git a/src/main/java/com/brandon3055/draconicevolution/client/render/EnergyPylonRenderer.java b/src/main/java/com/brandon3055/draconicevolution/client/render/EnergyPylonRenderer.java new file mode 100644 index 00000000..d9ccc71c --- /dev/null +++ b/src/main/java/com/brandon3055/draconicevolution/client/render/EnergyPylonRenderer.java @@ -0,0 +1,85 @@ +package com.brandon3055.draconicevolution.client.render; + +import com.brandon3055.draconicevolution.common.blocks.multiblock.EnergyPylon; +import com.brandon3055.draconicevolution.common.lib.References; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyPylon; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; +import cpw.mods.fml.client.FMLClientHandler; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.AdvancedModelLoader; +import net.minecraftforge.client.model.IModelCustom; +import org.lwjgl.opengl.GL11; + +/** + * Created by Brandon on 27/07/2014. + */ +public class EnergyPylonRenderer extends TileEntitySpecialRenderer { + + private static final ResourceLocation model_texture = new ResourceLocation(References.MODID.toLowerCase(), "textures/models/pylon_sphere_texture.png"); + private IModelCustom model; + + public EnergyPylonRenderer() + { + model = AdvancedModelLoader.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/pylon_sphere.obj")); + } + @Override + public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) { + if (tile == null || !(tile instanceof TileEnergyPylon)) return; + TileEnergyPylon pylon = (TileEnergyPylon) tile; + if (!pylon.active) return; + float scale = pylon.modelScale + (timeSinceLastTick *= pylon.input ? -0.01F : 0.01F); + float rotation = pylon.modelRotation + (timeSinceLastTick / 2F); + GL11.glPushMatrix(); + GL11.glTranslated(x+0.5, y+0.5, z+0.5); + if (pylon.getWorldObj().getBlockMetadata(pylon.xCoord, pylon.yCoord, pylon.zCoord) == 1) { + GL11.glTranslated(0, 1, 0); + }else { + GL11.glTranslated(0, -1, 0); + } + //GL11.glScalef(0.5F, 0.5F, 0.5F); + GL11.glDepthMask(false); + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(model_texture); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200F, 200F); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_BLEND); + + GL11.glPushMatrix(); + float scale1 = scale % 1F; + GL11.glScalef(scale1, scale1, scale1); + GL11.glRotatef(rotation*0.5F, 0F, -1F, -0.5F); + GL11.glColor4f(1F, 1F, 1F, 1F-(scale1)); + model.renderAll(); + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + float scale2 = (scale+0.25F) % 1F; + GL11.glScalef(scale2, scale2, scale2); + GL11.glRotatef(rotation*0.5F, 0F, -1F, -0.5F); + GL11.glColor4f(1F, 1F, 1F, 1F-(scale2)); + model.renderAll(); + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + float scale3 = (scale+0.5F) % 1F; + GL11.glScalef(scale3, scale3, scale3); + GL11.glRotatef(rotation*0.5F, 0F, -1F, -0.5F); + GL11.glColor4f(1F, 1F, 1F, 1F-(scale3)); + model.renderAll(); + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + float scale4 = (scale+0.75F) % 1F; + GL11.glScalef(scale4, scale4, scale4); + GL11.glRotatef(rotation*0.5F, 0F, -1F, -0.5F); + GL11.glColor4f(1F, 1F, 1F, 1F-(scale4)); + model.renderAll(); + GL11.glPopMatrix(); + + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/com/brandon3055/draconicevolution/client/render/EnergyStorageCoreRenderer.java b/src/main/java/com/brandon3055/draconicevolution/client/render/EnergyStorageCoreRenderer.java new file mode 100644 index 00000000..610916d5 --- /dev/null +++ b/src/main/java/com/brandon3055/draconicevolution/client/render/EnergyStorageCoreRenderer.java @@ -0,0 +1,106 @@ +package com.brandon3055.draconicevolution.client.render; + +import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import com.brandon3055.draconicevolution.common.lib.References; +import com.brandon3055.draconicevolution.common.tileentities.TileTestBlock; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; +import cpw.mods.fml.client.FMLClientHandler; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.AdvancedModelLoader; +import net.minecraftforge.client.model.IModelCustom; +import org.lwjgl.opengl.GL11; + +/** + * Created by Brandon on 27/07/2014. + */ +public class EnergyStorageCoreRenderer extends TileEntitySpecialRenderer { + + private static final ResourceLocation iner_model_texture = new ResourceLocation(References.MODID.toLowerCase(), "textures/models/power_sphere_layer_1.png"); + private static final ResourceLocation outer_model_texture = new ResourceLocation(References.MODID.toLowerCase(), "textures/models/power_sphere_layer_2.png"); + private IModelCustom iner_model; + private IModelCustom outer_model; + + public EnergyStorageCoreRenderer() + { + iner_model = AdvancedModelLoader.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/power_sphere_layer_1.obj")); + //outer_model = AdvancedModelLoader.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/power_sphere_layer_2.obj")); + } + @Override + public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) { + if (tile == null || !(tile instanceof TileEnergyStorageCore)) return; + TileEnergyStorageCore core = (TileEnergyStorageCore) tile; + if (!core.isOnline()) return; + float scale = 0; + float rotation = core.modelRotation + (timeSinceLastTick / 2F); + + switch (core.getTier()){ + case 0: + scale = 0.7F; + break; + case 1: + scale = 1.2F; + break; + case 2: + scale = 1.7F; + break; + case 3: + scale = 2.5F; + break; + case 4: + scale = 3.5F; + break; + case 5: + scale = 4.5F; + break; + case 6: + scale = 5.5F; + break; + } + + GL11.glPushMatrix(); + GL11.glColor4f(1F, 1F, 1F, 1F); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) 100, (float) 100); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glTranslated(x+0.5, y+0.5, z+0.5); + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(iner_model_texture); + + GL11.glScalef(scale, scale, scale); + GL11.glPushMatrix(); + GL11.glRotatef(rotation, 0F, 1F, 0.5F); + iner_model.renderAll(); + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + GL11.glScalef(0.8F, 0.8F, 0.8F); + GL11.glColor4f(0.5F, 1F, 1F, 1F); + GL11.glRotatef(rotation, 0F, 1F, 0.5F); + iner_model.renderAll(); + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + GL11.glScalef(0.9F, 0.9F, 0.9F); + GL11.glColor4f(0F, 1F, 1F, 1F); + GL11.glRotatef(rotation, 0F, 1F, 0.5F); + iner_model.renderAll(); + GL11.glPopMatrix(); + + GL11.glScalef(1.1F, 1.1F, 1.1F); + GL11.glDepthMask(false); + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(outer_model_texture); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200F, 200F); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_BLEND); + GL11.glRotatef(rotation*0.5F, 0F, -1F, -0.5F); + GL11.glColor4f(0.5F, 2F, 2F, 0.7F); + iner_model.renderAll(); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); + + + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/com/brandon3055/draconicevolution/client/render/ParticleGenRenderer.java b/src/main/java/com/brandon3055/draconicevolution/client/render/ParticleGenRenderer.java index 29a52fd2..dbacb376 100644 --- a/src/main/java/com/brandon3055/draconicevolution/client/render/ParticleGenRenderer.java +++ b/src/main/java/com/brandon3055/draconicevolution/client/render/ParticleGenRenderer.java @@ -1,45 +1,63 @@ package com.brandon3055.draconicevolution.client.render; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.client.model.AdvancedModelLoader; +import net.minecraftforge.client.model.IModelCustom; import org.lwjgl.opengl.GL11; import com.brandon3055.draconicevolution.common.lib.References; import com.brandon3055.draconicevolution.common.tileentities.TileParticleGenerator; + +@SideOnly(Side.CLIENT) public class ParticleGenRenderer extends TileEntitySpecialRenderer { private final ResourceLocation texture = new ResourceLocation(References.MODID.toLowerCase(), "textures/models/ParticleGenTextureSheet.png"); + private final ResourceLocation beamTexture = new ResourceLocation(References.MODID.toLowerCase(), "textures/models/stabilizer_beam.png"); + private static final ResourceLocation modelTexture = new ResourceLocation(References.MODID.toLowerCase(), "textures/models/stabilizer_sphere.png"); + private IModelCustom stabilizerSphereModel; private float pxl = 1F / 64; - @Override - public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) + public ParticleGenRenderer() { + stabilizerSphereModel = AdvancedModelLoader.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/stabilizer_sphere.obj")); + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { GL11.glPushMatrix(); GL11.glTranslatef((float) x, (float) y, (float) z); TileParticleGenerator tileEntityGen = (TileParticleGenerator) tileEntity; - renderBlock(tileEntityGen, tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, tileEntity.getWorldObj().getBlock(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); + renderBlock(tileEntityGen, tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, tileEntity.getWorldObj().getBlock(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord), f); GL11.glPopMatrix(); } - //And this method actually renders your tile entity - public void renderBlock(TileParticleGenerator tl, World world, int x, int y, int z, Block block) - { + public void renderBlock(TileParticleGenerator tl, World world, int x, int y, int z, Block block, float f3) { Tessellator tessellator = Tessellator.instance; - - bindTexture(texture); + boolean inverted = tl.inverted; - + boolean stabilizerMode = tl.stabalizerMode; + + GL11.glPushMatrix(); + + GL11.glDisable(GL11.GL_LIGHTING); + bindTexture(texture); tessellator.startDrawingQuads(); tessellator.setNormal(0.0F, 0.0F, 1.0F); @@ -53,19 +71,18 @@ public class ParticleGenRenderer extends TileEntitySpecialRenderer OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)l1, (float)l2); //tessellator.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1F); - - + {//Draw Corners float f = 0.4F; - drawCornerCube(tessellator, f, f, f, 1F - f, inverted); - drawCornerCube(tessellator, f, -f, f, 1F - f, inverted); - drawCornerCube(tessellator, -f, f, -f, 1F - f, inverted); - drawCornerCube(tessellator, -f, -f, -f, 1F - f, inverted); - drawCornerCube(tessellator, -f, f, f, 1F - f, inverted); - drawCornerCube(tessellator, f, f, -f, 1F - f, inverted); - drawCornerCube(tessellator, f, -f, -f, 1F - f, inverted); - drawCornerCube(tessellator, -f, -f, f, 1F - f, inverted); + drawCornerCube(tessellator, f, f, f, 1F - f, inverted, stabilizerMode); + drawCornerCube(tessellator, f, -f, f, 1F - f, inverted, stabilizerMode); + drawCornerCube(tessellator, -f, f, -f, 1F - f, inverted, stabilizerMode); + drawCornerCube(tessellator, -f, -f, -f, 1F - f, inverted, stabilizerMode); + drawCornerCube(tessellator, -f, f, f, 1F - f, inverted, stabilizerMode); + drawCornerCube(tessellator, f, f, -f, 1F - f, inverted, stabilizerMode); + drawCornerCube(tessellator, f, -f, -f, 1F - f, inverted, stabilizerMode); + drawCornerCube(tessellator, -f, -f, f, 1F - f, inverted, stabilizerMode); } {//Draw Beams float f = 0.45F; @@ -87,12 +104,230 @@ public class ParticleGenRenderer extends TileEntitySpecialRenderer } tessellator.draw(); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + if (stabilizerMode) + { + drawEnergyBeam(tessellator, tl, f3); + } } - private void drawCornerCube(Tessellator tess, float x, float y, float z, float FP, boolean inverted) - { + private void drawEnergyBeam(Tessellator tess, TileParticleGenerator gen, float f){ + TileEnergyStorageCore master = gen.getMaster(); + if (master == null) return; + float length = 0; + + GL11.glPushMatrix(); + + if (master.xCoord > gen.xCoord){ + GL11.glRotatef(-90F, 0F, 0F, 1F); + GL11.glTranslated(-1, 0.5, 0); + length = master.xCoord - gen.xCoord - 0.2F; + } + else if (master.xCoord < gen.xCoord){ + GL11.glRotatef(90F, 0F, 0F, 1F); + GL11.glTranslated(0, -0.5, 0); + length = gen.xCoord - master.xCoord - 0.2F; + } + else if (master.zCoord > gen.zCoord){ + GL11.glRotatef(90F, 1F, 0F, 0F); + GL11.glTranslated(0, 0.5, -1); + length = master.zCoord - gen.zCoord - 0.2F; + } + else if (master.zCoord < gen.zCoord){ + GL11.glRotatef(-90F, 1F, 0F, 0F); + GL11.glTranslated(0, -0.5, 0); + length = gen.zCoord - master.zCoord - 0.2F; + } + + renderStabilizerSphere(gen); + renderEnergyBeam(tess, gen, length, f); + + GL11.glPopMatrix(); + } + + public void renderStabilizerSphere(TileParticleGenerator tile){ + GL11.glPushMatrix(); + //GL11.glColor4f(0.5F, 0.0F, 0.0F, 1F); + GL11.glColor4f(0.0F, 2.0F, 0.0F, 1F); + GL11.glTranslated(0.5, 0, 0.5); + GL11.glScalef(0.4F, 0.4F, 0.4F); + + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200, 200); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_CULL_FACE); + + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(modelTexture); + + GL11.glRotatef(tile.rotation, 0F, 1F, 0F); + stabilizerSphereModel.renderAll(); + + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200, 200); + GL11.glRotatef(tile.rotation*2, 0F, -1F, 0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDepthMask(false); + GL11.glColor4f(0.0F, 1.0F, 1.0F, 0.5F); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glScalef(1.3F, 1.3F, 1.3F); + stabilizerSphereModel.renderAll(); + GL11.glDepthMask(true); + + GL11.glPopMatrix(); + } + + private void renderEnergyBeam(Tessellator tess, TileParticleGenerator tile, float length, float f){ + int x = 0; + int y = 0; + int z = 0; + + GL11.glPushMatrix(); + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); + + bindTexture(beamTexture); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0F); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); + OpenGlHelper.glBlendFunc(770, 1, 1, 0); + + float time = (float)tile.getWorldObj().getTotalWorldTime() + f; + float upMot = -time * 0.2F - (float) MathHelper.floor_float(-time * 0.1F); + byte scaleMult = 1; + double rotation = (double)time * 0.025D * (1.0D - (double)(scaleMult & 1) * 2.5D); + + + tess.startDrawingQuads(); + tess.setColorRGBA(255, 255, 255, 32); + + double scale = (double)scaleMult * 0.2D; + double d7 = 0.5D + Math.cos(rotation + 2.356194490192345D) * scale; //x point 1 + double d9 = 0.5D + Math.sin(rotation + 2.356194490192345D) * scale; //z point 1 + double d11 = 0.5D + Math.cos(rotation + (Math.PI / 4D)) * scale; //x point 2 + double d13 = 0.5D + Math.sin(rotation + (Math.PI / 4D)) * scale; //z point 2 + double d15 = 0.5D + Math.cos(rotation + 3.9269908169872414D) * scale;//Dist from x-3 + double d17 = 0.5D + Math.sin(rotation + 3.9269908169872414D) * scale; + double d19 = 0.5D + Math.cos(rotation + 5.497787143782138D) * scale; + double d21 = 0.5D + Math.sin(rotation + 5.497787143782138D) * scale; + double height = (double)(length); + double texXMin = 0.0D; + double texXMax = 1.0D; + double d28 = (double)(-1.0F + upMot); + double texHeight = (double)(length) * (0.5D / scale) + d28; + + tess.addVertexWithUV(x + d7, y + height, z + d9, texXMax, texHeight); + tess.addVertexWithUV(x + d7, y, z + d9, texXMax, d28); + tess.addVertexWithUV(x + d11, y, z + d13, texXMin, d28); + tess.addVertexWithUV(x + d11, y + height, z + d13, texXMin, texHeight); + + tess.addVertexWithUV(x + d19, y + height, z + d21, texXMax, texHeight); + tess.addVertexWithUV(x + d19, y, z + d21, texXMax, d28); + tess.addVertexWithUV(x + d15, y, z + d17, texXMin, d28); + tess.addVertexWithUV(x + d15, y + height, z + d17, texXMin, texHeight); + + tess.addVertexWithUV(x + d11, y + height, z + d13, texXMax, texHeight); + tess.addVertexWithUV(x + d11, y, z + d13, texXMax, d28); + tess.addVertexWithUV(x + d19, y, z + d21, texXMin, d28); + tess.addVertexWithUV(x + d19, y + height, z + d21, texXMin, texHeight); + + tess.addVertexWithUV(x + d15, y + height, z + d17, texXMax, texHeight); + tess.addVertexWithUV(x + d15, y, z + d17, texXMax, d28); + tess.addVertexWithUV(x + d7, y, z + d9, texXMin, d28); + tess.addVertexWithUV(x + d7, y + height, z + d9, texXMin, texHeight); + + rotation += 0.77f; + d7 = 0.5D + Math.cos(rotation + 2.356194490192345D) * scale; + d9 = 0.5D + Math.sin(rotation + 2.356194490192345D) * scale; + d11 = 0.5D + Math.cos(rotation + (Math.PI / 4D)) * scale; + d13 = 0.5D + Math.sin(rotation + (Math.PI / 4D)) * scale; + d15 = 0.5D + Math.cos(rotation + 3.9269908169872414D) * scale; + d17 = 0.5D + Math.sin(rotation + 3.9269908169872414D) * scale; + d19 = 0.5D + Math.cos(rotation + 5.497787143782138D) * scale; + d21 = 0.5D + Math.sin(rotation + 5.497787143782138D) * scale; + + d28 = (-1F + (upMot*1)); + texHeight = (double)(length) * (0.5D / scale) + d28; + + tess.setColorRGBA_F(1.0F, 1.0f, 1.0f, 1f); + + tess.addVertexWithUV(x + d7, y + height, z + d9, texXMax, texHeight); + tess.addVertexWithUV(x + d7, y, z + d9, texXMax, d28); + tess.addVertexWithUV(x + d11, y, z + d13, texXMin, d28); + tess.addVertexWithUV(x + d11, y + height, z + d13, texXMin, texHeight); + + tess.addVertexWithUV(x + d19, y + height, z + d21, texXMax, texHeight); + tess.addVertexWithUV(x + d19, y, z + d21, texXMax, d28); + tess.addVertexWithUV(x + d15, y, z + d17, texXMin, d28); + tess.addVertexWithUV(x + d15, y + height, z + d17, texXMin, texHeight); + + tess.addVertexWithUV(x + d11, y + height, z + d13, texXMax, texHeight); + tess.addVertexWithUV(x + d11, y, z + d13, texXMax, d28); + tess.addVertexWithUV(x + d19, y, z + d21, texXMin, d28); + tess.addVertexWithUV(x + d19, y + height, z + d21, texXMin, texHeight); + + tess.addVertexWithUV(x + d15, y + height, z + d17, texXMax, texHeight); + tess.addVertexWithUV(x + d15, y, z + d17, texXMax, d28); + tess.addVertexWithUV(x + d7, y, z + d9, texXMin, d28); + tess.addVertexWithUV(x + d7, y + height, z + d9, texXMin, texHeight); + + tess.draw(); + GL11.glPushMatrix(); + + GL11.glTranslated(0, 0.4, 0); + length -= 0.5F; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glDepthMask(false); + tess.startDrawingQuads(); + tess.setColorRGBA(255, 255, 255, 32); + double d30 = 0.2D; + double d4 = 0.2D; + double d6 = 0.8D; + double d8 = 0.2D; + double d10 = 0.2D; + double d12 = 0.8D; + double d14 = 0.8D; + double d16 = 0.8D; + double d18 = (double)(length); + double d20 = 0.0D; + double d22 = 1.0D; + double d24 = (double)(-1.0F + upMot); + double d26 = (double)(length) + d24; + tess.addVertexWithUV(x + d30, y + d18, z + d4, d22, d26); + tess.addVertexWithUV(x + d30, y, z + d4, d22, d24); + tess.addVertexWithUV(x + d6, y, z + d8, d20, d24); + tess.addVertexWithUV(x + d6, y + d18, z + d8, d20, d26); + tess.addVertexWithUV(x + d14, y + d18, z + d16, d22, d26); + tess.addVertexWithUV(x + d14, y, z + d16, d22, d24); + tess.addVertexWithUV(x + d10, y, z + d12, d20, d24); + tess.addVertexWithUV(x + d10, y + d18, z + d12, d20, d26); + tess.addVertexWithUV(x + d6, y + d18, z + d8, d22, d26); + tess.addVertexWithUV(x + d6, y, z + d8, d22, d24); + tess.addVertexWithUV(x + d14, y, z + d16, d20, d24); + tess.addVertexWithUV(x + d14, y + d18, z + d16, d20, d26); + tess.addVertexWithUV(x + d10, y + d18, z + d12, d22, d26); + tess.addVertexWithUV(x + d10, y, z + d12, d22, d24); + tess.addVertexWithUV(x + d30, y, z + d4, d20, d24); + tess.addVertexWithUV(x + d30, y + d18, z + d4, d20, d26); + tess.draw(); + GL11.glPopMatrix(); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDepthMask(true); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glPopMatrix(); + + } + + private void drawCornerCube(Tessellator tess, float x, float y, float z, float FP, boolean inverted, boolean stabalizerMode) { float srcXMin = inverted ? 38F * pxl: 32F * pxl; float srcYMin = 0F; float srcXMax = inverted ? 44F * pxl : 38F * pxl; @@ -100,6 +335,11 @@ public class ParticleGenRenderer extends TileEntitySpecialRenderer //float FP = 0.6F; //Scale float FN = 1F - FP; + if (stabalizerMode){ + srcXMin = 44F * pxl; + srcXMax = 50F * pxl; + } + //X+ tess.addVertexWithUV(FP + x, FN + y, FN + z, srcXMin, srcYMin); tess.addVertexWithUV(FP + x, FP + y, FN + z, srcXMax, srcYMin); @@ -137,8 +377,7 @@ public class ParticleGenRenderer extends TileEntitySpecialRenderer tess.addVertexWithUV(FP + x, FN + y, FN + z, srcXMin, srcYMax); } - private void drawBeamX(Tessellator tess, float x, float y, float z, float FP) - { + private void drawBeamX(Tessellator tess, float x, float y, float z, float FP) { float srcXMin = 0; float srcYMin = 0F; float srcXMax = 32F * pxl; @@ -173,8 +412,7 @@ public class ParticleGenRenderer extends TileEntitySpecialRenderer tess.addVertexWithUV(XX, FN + y, FN + z, srcXMax, srcYMax); } - private void drawBeamY(Tessellator tess, float x, float y, float z, float FP) - { + private void drawBeamY(Tessellator tess, float x, float y, float z, float FP) { float srcXMin = 0; float srcYMin = 0F; float srcXMax = 32F * pxl; @@ -210,8 +448,7 @@ public class ParticleGenRenderer extends TileEntitySpecialRenderer } - private void drawBeamZ(Tessellator tess, float x, float y, float z, float FP) - { + private void drawBeamZ(Tessellator tess, float x, float y, float z, float FP) { float srcXMin = 0; float srcYMin = 0F; float srcXMax = 32F * pxl; diff --git a/src/main/java/com/brandon3055/draconicevolution/client/render/Particles.java b/src/main/java/com/brandon3055/draconicevolution/client/render/Particles.java new file mode 100644 index 00000000..c7e465ae --- /dev/null +++ b/src/main/java/com/brandon3055/draconicevolution/client/render/Particles.java @@ -0,0 +1,273 @@ +package com.brandon3055.draconicevolution.client.render; + +import com.brandon3055.draconicevolution.common.core.handler.ParticleHandler; +import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import com.brandon3055.draconicevolution.common.lib.References; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; + +/** + * Created by Brandon on 27/07/2014. + */ +@SideOnly(Side.CLIENT) +public final class Particles { + + public static class EnergyBeamParticle extends EntityFX { + + private int direction = 0; + private double masterX = 0; + private double masterZ = 0; + private float rotation = 0; + private boolean mirror = false; + private double[] trailX = new double[15]; + private double[] trailY = new double[15]; + private double[] trailZ = new double[15]; + + public EnergyBeamParticle(World world, double x, double y, double z, double x1, double z1, int direction, boolean mirror) { + super(world, x, y, z, 0.0D, 0.0D, 0.0D); + float speed = 0.04F; + this.motionX = 0; + this.motionY = 0; + this.motionZ = 0; + this.masterX = x1; + this.masterZ = z1; + this.direction = direction; + this.mirror = mirror; + + switch (direction){ + case 0: + this.motionX = speed; + break; + case 1: + this.motionX = -speed; + break; + case 2: + this.motionZ = speed; + break; + case 3: + this.motionZ = -speed; + break; + } + + this.particleTextureIndexX = 0; + this.particleTextureIndexY = 0; + this.particleScale = 1F; + this.noClip = true; + this.particleMaxAge = 300; + } + + @Override + public void onUpdate() { + if (particleAge > particleMaxAge || this.getDistanceSq(masterX, posY, masterZ) < 0.02) setDead(); + if (this.getDistanceSq(masterX, posY, masterZ) < 0.1) { + motionX = (masterX - posX) * 0.1F; + motionY = (Math.floor(posY) + 0.5 - posY) * 0.1F; + motionZ = (masterZ - posZ) * 0.1F; + prevPosX = posX; + prevPosY = posY; + prevPosZ = posZ; + moveEntity(motionX, motionY, motionZ); + return; + }else { + trailX[0] = posX; + trailY[0] = posY; + trailZ[0] = posZ; + for (int i = 14; i >= 0; i--){ + if (i > 0) { + trailX[i] = trailX[i-1]; + trailY[i] = trailY[i-1]; + trailZ[i] = trailZ[i-1]; + } + } + + float multiplier = 0.27F; + double masterY = Math.floor(posY) + 0.5; + if (direction == 0 || direction == 1) { + posZ = masterZ + Math.sin(rotation) * multiplier; + posY = masterY + Math.cos(rotation) * multiplier; + }else{ + posX = masterX + Math.sin(rotation) * multiplier; + posY = masterY + Math.cos(rotation) * multiplier; + } + if (mirror){ + float modifier = 3F; + if (direction == 0 || direction == 1) { + posZ = masterZ + Math.sin(rotation + modifier) * multiplier; + posY = masterY + Math.cos(rotation + modifier) * multiplier; + }else{ + posX = masterX + Math.sin(rotation + modifier) * multiplier; + posY = masterY + Math.cos(rotation + modifier) * multiplier; + } + } + setPosition(posX, posY, posZ); + } + prevPosX = posX; + prevPosY = posY; + prevPosZ = posZ; + if (direction == 0 || direction == 1) + moveEntity(motionX, 0, 0); + else + moveEntity(0, 0, motionZ); + particleAge ++; + if (direction == 0 || direction == 3) + rotation -= 0.15; + else + rotation += 0.15; + } + @Override + @SideOnly(Side.CLIENT) + public void renderParticle(Tessellator tesselator, float par2, float par3, float par4, float par5, float par6, float par7) {//Note U=X V=Y + + tesselator.draw(); + Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(References.RESOURCESPREFIX + "textures/particle/particles.png")); + tesselator.startDrawingQuads(); + tesselator.setBrightness(200);//make sure you have this!! + + + float minU = 0.0F + 0F;//(float)this.particleTextureIndexX / 32.0F; + float maxU = 0.0F + 0.1245F;//minU + 0.124F; + float minV = 0F;//(float)this.particleTextureIndexY / 32.0F; + float maxV = 0.1245F;//minV + 0.124F; + float drawScale = 0.1F * particleScale; + + if (this.particleIcon != null) { + minU = particleIcon.getMinU(); + maxU = particleIcon.getMaxU(); + minV = particleIcon.getMinV(); + maxV = particleIcon.getMaxV(); + } + + float drawX = (float) (prevPosX + (posX - prevPosX) * (double) par2 - interpPosX); + float drawY = (float) (prevPosY + (posY - prevPosY) * (double) par2 - interpPosY); + float drawZ = (float) (prevPosZ + (posZ - prevPosZ) * (double) par2 - interpPosZ); + + tesselator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha); + + tesselator.addVertexWithUV((double) (drawX - par3 * drawScale - par6 * drawScale), (double) (drawY - par4 * drawScale), (double) (drawZ - par5 * drawScale - par7 * drawScale), (double) maxU, (double) maxV); + tesselator.addVertexWithUV((double) (drawX - par3 * drawScale + par6 * drawScale), (double) (drawY + par4 * drawScale), (double) (drawZ - par5 * drawScale + par7 * drawScale), (double) maxU, (double) minV); + tesselator.addVertexWithUV((double) (drawX + par3 * drawScale + par6 * drawScale), (double) (drawY + par4 * drawScale), (double) (drawZ + par5 * drawScale + par7 * drawScale), (double) minU, (double) minV); + tesselator.addVertexWithUV((double) (drawX + par3 * drawScale - par6 * drawScale), (double) (drawY - par4 * drawScale), (double) (drawZ + par5 * drawScale - par7 * drawScale), (double) minU, (double) maxV); + + for (int i = 0; i <= 14; i++){ + GL11.glPushMatrix(); + drawX = (float) (trailX[i] + (trailX[i] - trailX[i]) * (double) par2 - interpPosX); + drawY = (float) (trailY[i] + (trailY[i] - trailY[i]) * (double) par2 - interpPosY); + drawZ = (float) (trailZ[i] + (trailZ[i] - trailZ[i]) * (double) par2 - interpPosZ); + float scale = 0.1F * (1F - ((float)i / 14F)); + float scale2 = (1F - ((float)i / 14F)); + + if (!mirror) { + tesselator.setColorRGBA_F(1F, scale2, scale2, scale2); + }else{ + tesselator.setColorRGBA_F(scale2, 1F, scale2, scale2); + } + + tesselator.addVertexWithUV((double) (drawX - par3 * scale - par6 * scale), (double) (drawY - par4 * scale), (double) (drawZ - par5 * scale - par7 * scale), (double) maxU, (double) maxV); + tesselator.addVertexWithUV((double) (drawX - par3 * scale + par6 * scale), (double) (drawY + par4 * scale), (double) (drawZ - par5 * scale + par7 * scale), (double) maxU, (double) minV); + tesselator.addVertexWithUV((double) (drawX + par3 * scale + par6 * scale), (double) (drawY + par4 * scale), (double) (drawZ + par5 * scale + par7 * scale), (double) minU, (double) minV); + tesselator.addVertexWithUV((double) (drawX + par3 * scale - par6 * scale), (double) (drawY - par4 * scale), (double) (drawZ + par5 * scale - par7 * scale), (double) minU, (double) maxV); + GL11.glPopMatrix(); + } + + tesselator.draw(); + Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/particle/particles.png")); + tesselator.startDrawingQuads(); + + } + } + + public static class EnergyTransferParticle extends EntityFX { + + private double targetX; + private double targetY; + private double targetZ; + private boolean passive; + + public EnergyTransferParticle(World world, double x, double y, double z, double tX, double tY, double tZ, boolean passive) { + super(world, x, y, z, 0.0D, 0.0D, 0.0D); + this.passive = passive; + this.targetX = tX; + this.targetY = tY; + this.targetZ = tZ; + this.motionX = 0; + this.motionY = 0; + this.motionZ = 0; + this.particleTextureIndexX = 0; + this.particleTextureIndexY = 0; + this.particleScale = world.rand.nextFloat() + 0.5F; + this.particleMaxAge = 100; + this.noClip = true; + if (!passive){ + this.particleRed = 0F; + this.particleGreen = 94F/255F; + this.particleBlue = 250F/255F; + } + } + + @Override + public void onUpdate() { + if (particleAge > particleMaxAge) setDead(); + if (particleAge > particleMaxAge || this.getDistanceSq(targetX, targetY, targetZ) < 0.05) setDead(); + particleAge ++; + motionX += (targetX - posX) * 0.001F; + motionY += (targetY - posY) * 0.001F; + motionZ += (targetZ - posZ) * 0.001F; + prevPosX = posX; + prevPosY = posY; + prevPosZ = posZ; + moveEntity(motionX, motionY, motionZ); + return; + } + @Override + @SideOnly(Side.CLIENT) + public void renderParticle(Tessellator tesselator, float par2, float par3, float par4, float par5, float par6, float par7) {//Note U=X V=Y + + tesselator.draw(); + Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(References.RESOURCESPREFIX + "textures/particle/particles.png")); + tesselator.startDrawingQuads(); + tesselator.setBrightness(200);//make sure you have this!! + + + float minU = 0.0F + 0F;//(float)this.particleTextureIndexX / 32.0F; + float maxU = 0.0F + 0.1245F;//minU + 0.124F; + float minV = 0F;//(float)this.particleTextureIndexY / 32.0F; + float maxV = 0.1245F;//minV + 0.124F; + float drawScale = 0.1F * this.particleScale; + + if (this.particleIcon != null) { + minU = this.particleIcon.getMinU(); + maxU = this.particleIcon.getMaxU(); + minV = this.particleIcon.getMinV(); + maxV = this.particleIcon.getMaxV(); + } + + float drawX = (float) (this.prevPosX + (this.posX - this.prevPosX) * (double) par2 - interpPosX); + float drawY = (float) (this.prevPosY + (this.posY - this.prevPosY) * (double) par2 - interpPosY); + float drawZ = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * (double) par2 - interpPosZ); + + if (passive) + tesselator.setColorRGBA_F((float)this.getDistanceSq(targetX, targetY, targetZ)*5F*this.particleRed, (float)this.getDistanceSq(targetX, targetY, targetZ)*5F*this.particleGreen, this.particleBlue, this.particleAlpha); + else + tesselator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, (float)this.getDistanceSq(targetX, targetY, targetZ)*5F); + + //tesselator.setColorRGBA(0, 255, 255, (int) (this.particleAlpha * 255F)); + + tesselator.addVertexWithUV((double) (drawX - par3 * drawScale - par6 * drawScale), (double) (drawY - par4 * drawScale), (double) (drawZ - par5 * drawScale - par7 * drawScale), (double) maxU, (double) maxV); + tesselator.addVertexWithUV((double) (drawX - par3 * drawScale + par6 * drawScale), (double) (drawY + par4 * drawScale), (double) (drawZ - par5 * drawScale + par7 * drawScale), (double) maxU, (double) minV); + tesselator.addVertexWithUV((double) (drawX + par3 * drawScale + par6 * drawScale), (double) (drawY + par4 * drawScale), (double) (drawZ + par5 * drawScale + par7 * drawScale), (double) minU, (double) minV); + tesselator.addVertexWithUV((double) (drawX + par3 * drawScale - par6 * drawScale), (double) (drawY - par4 * drawScale), (double) (drawZ + par5 * drawScale - par7 * drawScale), (double) minU, (double) maxV); + + tesselator.draw(); + Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/particle/particles.png")); + tesselator.startDrawingQuads(); + + } + } + +} diff --git a/src/main/java/com/brandon3055/draconicevolution/client/render/TestBlockRenderer.java b/src/main/java/com/brandon3055/draconicevolution/client/render/TestBlockRenderer.java index 59f294da..1717a075 100644 --- a/src/main/java/com/brandon3055/draconicevolution/client/render/TestBlockRenderer.java +++ b/src/main/java/com/brandon3055/draconicevolution/client/render/TestBlockRenderer.java @@ -26,28 +26,32 @@ public class TestBlockRenderer extends TileEntitySpecialRenderer { public TestBlockRenderer() { iner_model = AdvancedModelLoader.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/power_sphere_layer_1.obj")); - outer_model = AdvancedModelLoader.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/power_sphere_layer_2.obj")); + //outer_model = AdvancedModelLoader.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/power_sphere_layer_2.obj")); } @Override public void renderTileEntityAt(TileEntity var1, double x, double y, double z, float var8) { GL11.glPushMatrix(); - + GL11.glColor4f(1F, 1F, 1F, 1F); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) 100, (float) 100); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_CULL_FACE); + //GL11.glDepthMask(false); + GL11.glTranslated(x+0.5, y+0.5, z+0.5); FMLClientHandler.instance().getClient().getTextureManager().bindTexture(iner_model_texture); GL11.glPushMatrix(); GL11.glRotatef(((TileTestBlock)var1).modelRotation, 0F, 1F, 0.5F); - GL11.glColor4f(2F, 2F, 2F, 1F); + //GL11.glColor4f(2F, 2F, 2F, 1F); iner_model.renderAll(); GL11.glPopMatrix(); GL11.glScalef(1.1F, 1.1F, 1.1F); - + GL11.glDepthMask(false); FMLClientHandler.instance().getClient().getTextureManager().bindTexture(outer_model_texture); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200F, 200F); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); @@ -56,6 +60,7 @@ public class TestBlockRenderer extends TileEntitySpecialRenderer { GL11.glColor4f(0.5F, 2F, 2F, 0.7F); outer_model.renderAll(); GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); GL11.glPopMatrix(); diff --git a/src/main/java/com/brandon3055/draconicevolution/common/blocks/ModBlocks.java b/src/main/java/com/brandon3055/draconicevolution/common/blocks/ModBlocks.java index 6e8e7f71..2beae7ef 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/blocks/ModBlocks.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/blocks/ModBlocks.java @@ -1,5 +1,6 @@ package com.brandon3055.draconicevolution.common.blocks; +import com.brandon3055.draconicevolution.common.blocks.multiblock.EnergyPylon; import com.brandon3055.draconicevolution.common.blocks.multiblock.EnergyStorageCore; import com.brandon3055.draconicevolution.common.blocks.multiblock.InvisibleMultiblock; import net.minecraft.block.Block; @@ -26,6 +27,7 @@ public class ModBlocks { public static Block energyStorageCore; public static Block draconium; public static Block invisibleMultiblock; + public static Block energyPylon; public static void init() { @@ -45,6 +47,7 @@ public class ModBlocks { energyStorageCore = new EnergyStorageCore(); draconium = new Draconium(); invisibleMultiblock = new InvisibleMultiblock(); + energyPylon = new EnergyPylon(); if(ConfigHandler.disable_LRD < 2) longRangeDislocator = new LongRangeDislocator(); if(DraconicEvolution.debug) testBlock = new TestBlock(); diff --git a/src/main/java/com/brandon3055/draconicevolution/common/blocks/ParticleGenerator.java b/src/main/java/com/brandon3055/draconicevolution/common/blocks/ParticleGenerator.java index 87afdfb1..42fed8be 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/blocks/ParticleGenerator.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/blocks/ParticleGenerator.java @@ -47,9 +47,9 @@ public class ParticleGenerator extends Block } @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float p_149727_7_, float p_149727_8_, float p_149727_9_) + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float p_149727_7_, float p_149727_8_, float p_149727_9_) { - if (meta == 1) return false; + if (world.getBlockMetadata(x, y, z) == 1) return false; if (player.isSneaking()) { if (activateEnergyStorageCore(world, x, y, z, player)) return true; @@ -160,9 +160,16 @@ public class ParticleGenerator extends Block TileEnergyStorageCore tile = (world.getTileEntity(x1, y, z) != null && world.getTileEntity(x1, y, z) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) world.getTileEntity(x1, y, z) : null; if (tile != null && !tile.isOnline()) { - if (!tile.tryActivate() && world.isRemote) { - player.addChatComponentMessage(new ChatComponentTranslation("msg.energyStorageCoreUTA.txt")); - return false; + if (player.capabilities.isCreativeMode) { + if (!tile.creativeActivate()) { + if (world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("msg.energyStorageCoreUTA.txt")); + return false; + } + }else { + if (!tile.tryActivate()) { + if (world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("msg.energyStorageCoreUTA.txt")); + return false; + } } return true; } @@ -174,9 +181,16 @@ public class ParticleGenerator extends Block TileEnergyStorageCore tile = (world.getTileEntity(x, y, z1) != null && world.getTileEntity(x, y, z1) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) world.getTileEntity(x, y, z1) : null; if (tile != null && !tile.isOnline()) { - if (!tile.tryActivate() && world.isRemote) { - player.addChatComponentMessage(new ChatComponentTranslation("msg.energyStorageCoreUTA.txt")); - return false; + if (player.capabilities.isCreativeMode) { + if (!tile.creativeActivate()) { + if (world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("msg.energyStorageCoreUTA.txt")); + return false; + } + }else { + if (!tile.tryActivate()) { + if (world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("msg.energyStorageCoreUTA.txt")); + return false; + } } return true; } @@ -184,4 +198,20 @@ public class ParticleGenerator extends Block } return false; } + + @Override + public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int meta) { + if (meta == 1) + { + TileEntity tile = world.getTileEntity(x, y, z); + TileParticleGenerator gen = (tile != null && tile instanceof TileParticleGenerator) ? (TileParticleGenerator) tile : null; + if (gen != null && gen.getMaster() != null) + { + world.setBlockMetadataWithNotify(x, y, z, 0, 2); + //LogHelper.info("deActivate"); + gen.getMaster().isStructureStillValid(true); + } + } + super.breakBlock(world, x, y, z, p_149749_5_, meta); + } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/EnergyPylon.java b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/EnergyPylon.java new file mode 100644 index 00000000..92176596 --- /dev/null +++ b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/EnergyPylon.java @@ -0,0 +1,119 @@ +package com.brandon3055.draconicevolution.common.blocks.multiblock; + +import com.brandon3055.draconicevolution.DraconicEvolution; +import com.brandon3055.draconicevolution.common.blocks.DraconicEvolutionBlock; +import com.brandon3055.draconicevolution.common.blocks.ModBlocks; +import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import com.brandon3055.draconicevolution.common.lib.References; +import com.brandon3055.draconicevolution.common.lib.Strings; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyPylon; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileInvisibleMultiblock; +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.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +/** + * Created by Brandon on 28/07/2014. + */ +public class EnergyPylon extends DraconicEvolutionBlock { + @SideOnly(Side.CLIENT) + public IIcon icon_active_face; + public IIcon icon_input; + public IIcon icon_output; + + public EnergyPylon() { + super(Material.iron); + this.setHardness(5F); + this.setResistance(20F); + this.setCreativeTab(DraconicEvolution.getCreativeTab(2)); + this.setBlockName(Strings.energyPylonName); + ModBlocks.register(this); + } + + @Override + public boolean hasTileEntity(int metadata) { + return metadata == 1 || metadata == 2; + } + + @Override + public TileEntity createTileEntity(World world, int metadata) { + if (metadata == 1 || metadata == 2) + return new TileEnergyPylon(); + else + return null; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iconRegister) { + icon_input = iconRegister.registerIcon(References.RESOURCESPREFIX + "energy_pylon_input"); + icon_output = iconRegister.registerIcon(References.RESOURCESPREFIX + "energy_pylon_output"); + icon_active_face = iconRegister.registerIcon(References.RESOURCESPREFIX + "energy_pylon_active_face"); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) { + if (meta == 1 && side == 1) + return icon_active_face; + if (meta == 2 && side == 0) + return icon_active_face; + return icon_input; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEnergyPylon) ? (TileEnergyPylon) world.getTileEntity(x, y, z) : null; + if (thisTile == null) return icon_input; + return thisTile.input ? icon_output : icon_input; + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) { + int meta = world.getBlockMetadata(x, y, z); + if (meta == 0) { + if (world.getBlock(x, y + 1, z) == Blocks.glass) { + world.setBlockMetadataWithNotify(x, y, z, 1, 2); + world.setBlock(x, y + 1, z, ModBlocks.invisibleMultiblock, 2, 2); + } + else if (world.getBlock(x, y - 1, z) == Blocks.glass) { + world.setBlockMetadataWithNotify(x, y, z, 2, 2); + world.setBlock(x, y - 1, z, ModBlocks.invisibleMultiblock, 2, 2); + } + }else { + TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEnergyPylon) ? (TileEnergyPylon) world.getTileEntity(x, y, z) : null; + if (thisTile == null || (meta == 1 && !isGlass(world, x, y+1, z)) || (meta == 2 && !isGlass(world, x, y-1, z))) { + world.setBlockMetadataWithNotify(x, y, z, 0, 2); + } + } + TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEnergyPylon) ? (TileEnergyPylon) world.getTileEntity(x, y, z) : null; + if (thisTile != null) { + thisTile.onActivated(); + } + } + + private boolean isGlass(World world, int x, int y, int z){ + return world.getBlock(x, y, z) == ModBlocks.invisibleMultiblock && world.getBlockMetadata(x, y, z) == 2; + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { + int meta = world.getBlockMetadata(x, y, z); + if (meta == 0) return false; + TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEnergyPylon) ? (TileEnergyPylon) world.getTileEntity(x, y, z) : null; + if (thisTile != null) { + thisTile.onActivated(); + return true; + } + return false; + } +} diff --git a/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/EnergyStorageCore.java b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/EnergyStorageCore.java index fe52f9f1..2d276bce 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/EnergyStorageCore.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/EnergyStorageCore.java @@ -4,18 +4,21 @@ import com.brandon3055.draconicevolution.DraconicEvolution; import com.brandon3055.draconicevolution.common.blocks.DraconicEvolutionBlock; import com.brandon3055.draconicevolution.common.blocks.ModBlocks; import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import com.brandon3055.draconicevolution.common.core.utills.Utills; import com.brandon3055.draconicevolution.common.lib.References; import com.brandon3055.draconicevolution.common.lib.Strings; -import com.brandon3055.draconicevolution.common.tileentities.TileGenerator; import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileInvisibleMultiblock; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentText; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -58,10 +61,56 @@ public class EnergyStorageCore extends DraconicEvolutionBlock { LogHelper.error("Missing Tile Entity (EnergyStorageCore)"); return false; } - if (!world.isRemote) - tile.tryActivate(); - //if (world.isRemote) - //player.addChatComponentMessage(new ChatComponentText(""+tile.getEnergyStored(ForgeDirection.UP))); + + if (!world.isRemote) { + player.addChatComponentMessage(new ChatComponentText("Tier:" + tile.getTier())); + player.addChatComponentMessage(new ChatComponentText("" + Utills.formatNumber(tile.getEnergyStored()) + " / " + Utills.formatNumber(tile.getMaxEnergyStored()))); + } return true; } + + @Override + @SideOnly(Side.CLIENT) + public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) { + TileEnergyStorageCore tile = (world.getTileEntity(x - ForgeDirection.getOrientation(side).offsetX, y - ForgeDirection.getOrientation(side).offsetY, z - ForgeDirection.getOrientation(side).offsetZ) != null && world.getTileEntity(x - ForgeDirection.getOrientation(side).offsetX, y - ForgeDirection.getOrientation(side).offsetY, z - ForgeDirection.getOrientation(side).offsetZ) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) world.getTileEntity(x - ForgeDirection.getOrientation(side).offsetX, y - ForgeDirection.getOrientation(side).offsetY, z - ForgeDirection.getOrientation(side).offsetZ) : null; + //LogHelper.error(world.getTileEntity(x - ForgeDirection.getOrientation(side).offsetX, y - ForgeDirection.getOrientation(side).offsetY, z - ForgeDirection.getOrientation(side).offsetZ)); + if (tile == null) + { + LogHelper.error("Missing Tile Entity (EnergyStorageCore)(shouldSideBeRendered)"); + return true; + } + if (tile.isOnline()) + return false; + else + return super.shouldSideBeRendered(world, x, y, z, side); + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) { + TileEnergyStorageCore thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) world.getTileEntity(x, y, z) : null; + if (thisTile != null && thisTile.isOnline() && thisTile.getTier() == 0) + { + thisTile.isStructureStillValid(false); + } + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int p_149749_6_) { + TileEnergyStorageCore thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) world.getTileEntity(x, y, z) : null; + if (thisTile != null && thisTile.isOnline() && thisTile.getTier() == 0) + { + thisTile.deactivateStabilizers(); + } + super.breakBlock(world, x, y, z, p_149749_5_, p_149749_6_); + } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { + TileEnergyStorageCore thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) world.getTileEntity(x, y, z) : null; + if (thisTile != null && thisTile.isOnline()) + { + return AxisAlignedBB.getBoundingBox(thisTile.xCoord + 0.5, thisTile.yCoord + 0.5, thisTile.zCoord + 0.5, thisTile.xCoord + 0.5, thisTile.yCoord + 0.5, thisTile.zCoord + 0.5); + } + return super.getSelectedBoundingBoxFromPool(world, x, y, z); + } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/InvisibleMultiblock.java b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/InvisibleMultiblock.java index 89b8d345..66b94c75 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/InvisibleMultiblock.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/InvisibleMultiblock.java @@ -5,8 +5,11 @@ import com.brandon3055.draconicevolution.common.blocks.DraconicEvolutionBlock; import com.brandon3055.draconicevolution.common.blocks.Draconium; import com.brandon3055.draconicevolution.common.blocks.ModBlocks; import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import com.brandon3055.draconicevolution.common.core.utills.Utills; import com.brandon3055.draconicevolution.common.lib.References; import com.brandon3055.draconicevolution.common.lib.Strings; +import com.brandon3055.draconicevolution.common.tileentities.TileParticleGenerator; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyPylon; import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileInvisibleMultiblock; import cpw.mods.fml.relauncher.Side; @@ -18,6 +21,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentText; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -63,12 +67,14 @@ public class InvisibleMultiblock extends DraconicEvolutionBlock { @Override public boolean hasTileEntity(int metadata) { - return true; + return metadata == 0 || metadata == 1; } @Override public TileEntity createTileEntity(World world, int metadata) { - return new TileInvisibleMultiblock(); + if (metadata == 0 || metadata == 1) + return new TileInvisibleMultiblock(); + else return null; } @Override @@ -83,38 +89,55 @@ public class InvisibleMultiblock extends DraconicEvolutionBlock { @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { - TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock) ? (TileInvisibleMultiblock) world.getTileEntity(x, y, z) : null; - if (thisTile == null) - { - LogHelper.error("Missing Tile Entity (TileInvisibleMultiblock)"); - return false; + int meta = world.getBlockMetadata(x, y, z); + if (meta == 0 || meta == 1) { + TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock) ? (TileInvisibleMultiblock) world.getTileEntity(x, y, z) : null; + if (thisTile == null) { + LogHelper.error("Missing Tile Entity (TileInvisibleMultiblock)"); + return false; + } + TileEnergyStorageCore master = thisTile.getMaster(); + if (master == null) { + onNeighborBlockChange(world, x, y, z, this); + return false; + } + if (!world.isRemote) { + player.addChatComponentMessage(new ChatComponentText("Tier:" + master.getTier())); + player.addChatComponentMessage(new ChatComponentText("" + Utills.formatNumber(master.getEnergyStored()) + " / " + Utills.formatNumber(master.getMaxEnergyStored()))); + } + return true; + } else if (meta == 2) { + TileEnergyPylon pylon = (world.getTileEntity(x, y+1, z) != null && world.getTileEntity(x, y+1, z) instanceof TileEnergyPylon) ? (TileEnergyPylon) world.getTileEntity(x, y+1, z) : (world.getTileEntity(x, y-1, z) != null && world.getTileEntity(x, y-1, z) instanceof TileEnergyPylon) ? (TileEnergyPylon) world.getTileEntity(x, y-1, z) : null; + if (pylon == null) return false; + pylon.input = !pylon.input; + world.markBlockForUpdate(pylon.xCoord, pylon.yCoord, pylon.zCoord); + pylon.onActivated(); + return true; } - TileEnergyStorageCore master= thisTile.getMaster(); - if (master == null) { - onNeighborBlockChange(world, x, y, z, this); - return false; - } - if (world.isRemote) - player.addChatComponentMessage(new ChatComponentText(""+master.getEnergyStored(ForgeDirection.UP))); - return true; + return false; } @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) { - TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock) ? (TileInvisibleMultiblock) world.getTileEntity(x, y, z) : null; - if (thisTile == null) - { - LogHelper.error("Missing Tile Entity (TileInvisibleMultiblock)"); - revert(world, x, y, z); - return; + int meta = world.getBlockMetadata(x, y, z); + if (meta == 0 || meta == 1) { + TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock) ? (TileInvisibleMultiblock) world.getTileEntity(x, y, z) : null; + if (thisTile == null) { + LogHelper.error("Missing Tile Entity (TileInvisibleMultiblock)"); + revert(world, x, y, z); + return; + } + TileEnergyStorageCore master = thisTile.getMaster(); + if (master == null) { + LogHelper.error("Master = null reverting!"); + revert(world, x, y, z); + return; + } + if (master.isOnline()) master.isStructureStillValid(false); + if (!master.isOnline()) revert(world, x, y, z); + }else if (meta == 2) { + if (world.getBlock(x, y + 1, z) != ModBlocks.energyPylon && world.getBlock(x, y - 1, z) != ModBlocks.energyPylon) world.setBlock(x, y, z, Blocks.glass); } - TileEnergyStorageCore master = thisTile.getMaster(); - if (master == null) { - LogHelper.error("Master = null reverting!"); - revert(world, x, y, z); - return; - } - if (!master.isOnline()) revert(world, x, y, z); } private void revert(World world, int x, int y, int z){ @@ -124,4 +147,34 @@ public class InvisibleMultiblock extends DraconicEvolutionBlock { else if (meta == 1) world.setBlock(x, y, z, Blocks.redstone_block); } + + @Override + public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int meta) { + TileEntity tile = world.getTileEntity(x, y, z); + TileInvisibleMultiblock thisTile = (tile != null && tile instanceof TileInvisibleMultiblock) ? (TileInvisibleMultiblock) tile : null; + if (thisTile != null && thisTile.getMaster() != null && thisTile.getMaster().isOnline()) + { + world.setBlockMetadataWithNotify(x, y, z, 0, 2); + + thisTile.getMaster().isStructureStillValid(true); + } + super.breakBlock(world, x, y, z, p_149749_5_, meta); + } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { + int meta = world.getBlockMetadata(x, y, z); + if (meta == 0 || meta == 1) { + TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock) ? (TileInvisibleMultiblock) world.getTileEntity(x, y, z) : null; + if (thisTile != null && thisTile.getMaster() != null) { + return AxisAlignedBB.getBoundingBox(thisTile.getMaster().xCoord, thisTile.getMaster().yCoord, thisTile.getMaster().zCoord, thisTile.getMaster().xCoord + 0.5, thisTile.getMaster().yCoord + 0.5, thisTile.getMaster().zCoord + 0.5); + } + return super.getSelectedBoundingBoxFromPool(world, x, y, z); + }else if (meta == 2) { + return AxisAlignedBB.getBoundingBox(x + 0.49, y + 0.49, z + 0.49, x + 0.51, y + 0.51, z + 0.51); + } + return super.getSelectedBoundingBoxFromPool(world, x, y, z); + } + + } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/core/handler/ParticleHandler.java b/src/main/java/com/brandon3055/draconicevolution/common/core/handler/ParticleHandler.java index 1f1e4810..66e042eb 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/core/handler/ParticleHandler.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/core/handler/ParticleHandler.java @@ -1,10 +1,13 @@ package com.brandon3055.draconicevolution.common.core.handler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.EntityFX; import net.minecraft.world.World; import com.brandon3055.draconicevolution.client.render.DistortionParticle; +@SideOnly(Side.CLIENT) public class ParticleHandler { private static Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/ClientProxy.java b/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/ClientProxy.java index 933b67ca..a0090d8d 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/ClientProxy.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/ClientProxy.java @@ -4,6 +4,8 @@ import com.brandon3055.draconicevolution.client.render.*; import com.brandon3055.draconicevolution.common.tileentities.TileCustomSpawner; import com.brandon3055.draconicevolution.common.tileentities.TileEnergyInfuser; import com.brandon3055.draconicevolution.common.tileentities.TileTestBlock; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyPylon; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; import net.minecraft.client.renderer.tileentity.TileEntityMobSpawnerRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.item.Item; @@ -67,5 +69,11 @@ public class ClientProxy extends CommonProxy { render = new TestBlockRenderer(); ClientRegistry.bindTileEntitySpecialRenderer(TileTestBlock.class, render); + + render = new EnergyStorageCoreRenderer(); + ClientRegistry.bindTileEntitySpecialRenderer(TileEnergyStorageCore.class, render); + + render = new EnergyPylonRenderer(); + ClientRegistry.bindTileEntitySpecialRenderer(TileEnergyPylon.class, render); } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/CommonProxy.java b/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/CommonProxy.java index 86e29a6c..fb235305 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/CommonProxy.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/core/proxy/CommonProxy.java @@ -5,6 +5,7 @@ import com.brandon3055.draconicevolution.common.core.network.*; import com.brandon3055.draconicevolution.common.entity.EntityCustomDragon; import com.brandon3055.draconicevolution.common.lib.References; import com.brandon3055.draconicevolution.common.tileentities.*; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyPylon; import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileInvisibleMultiblock; import com.brandon3055.draconicevolution.common.world.DraconicWorldGenerator; @@ -66,6 +67,7 @@ public class CommonProxy { GameRegistry.registerTileEntity(TileGenerator.class, "TileGenerator"); GameRegistry.registerTileEntity(TileEnergyStorageCore.class, "TileEnergyStorageCore"); GameRegistry.registerTileEntity(TileInvisibleMultiblock.class, "TileInvisibleMultiblock"); + GameRegistry.registerTileEntity(TileEnergyPylon.class, "TileEnergyPylon"); if(DraconicEvolution.debug) GameRegistry.registerTileEntity(TileTestBlock.class, "TileTestBlock"); } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/core/utills/Utills.java b/src/main/java/com/brandon3055/draconicevolution/common/core/utills/Utills.java index 85953c41..3c60648d 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/core/utills/Utills.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/core/utills/Utills.java @@ -8,5 +8,17 @@ import net.minecraft.world.World; */ public class Utills { + public static String formatNumber(double value){ + if (value < 1000D) + return String.valueOf(value); + else if (value < 1000000D) + return String.valueOf(Math.round(value/10D)/100D) + "K"; + else if (value < 1000000000D) + return String.valueOf(Math.round(value/10000D)/100D) + "M"; + else if (value < 1000000000000D) + return String.valueOf(Math.round(value/10000000D)/100D) + "B"; + else + return String.valueOf(Math.round(value/10000000000D)/100D) + "T"; + } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/lib/Strings.java b/src/main/java/com/brandon3055/draconicevolution/common/lib/Strings.java index 66835e23..c3570f87 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/lib/Strings.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/lib/Strings.java @@ -50,4 +50,5 @@ public class Strings {// public sta public static final String energyStorageCoreName = "energyStorageCore"; public static final String draconiumName = "draconium"; public static final String invisibleMultiblockName = "invisibleMultiblock"; + public static final String energyPylonName = "energyPylon"; } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/TileParticleGenerator.java b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/TileParticleGenerator.java index adac4ad0..1cdf1703 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/TileParticleGenerator.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/TileParticleGenerator.java @@ -2,6 +2,10 @@ package com.brandon3055.draconicevolution.common.tileentities; import java.util.Random; +import com.brandon3055.draconicevolution.client.render.Particles; +import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation; +import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileEnergyStorageCore; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.nbt.NBTTagCompound; @@ -11,9 +15,10 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import com.brandon3055.draconicevolution.client.render.CustomParticle; import com.brandon3055.draconicevolution.common.core.handler.ParticleHandler; +import net.minecraft.util.AxisAlignedBB; +import org.lwjgl.opengl.GL11; -public class TileParticleGenerator extends TileEntity -{ +public class TileParticleGenerator extends TileEntity { public int red = 0; public int green = 0; public int blue = 0; @@ -45,26 +50,29 @@ public class TileParticleGenerator extends TileEntity public boolean active = true; public boolean signal = false; public boolean inverted = false; - - + TileLocation master = new TileLocation(); + public float rotation = 0; + public boolean stabalizerMode = false; + private int tick = 0; @SideOnly(Side.CLIENT) @Override - public void updateEntity() - { - if (signal && !inverted) - active = true; - else if (!signal && inverted) - active = true; - else - active = false; - - if (tick >= spawn_rate && active) - { + public void updateEntity() { + + if (stabalizerMode && worldObj.isRemote) { + rotation += 0.5F; + spawnStabilizerParticle(); + } + if (stabalizerMode) return; + + if (signal && !inverted) active = true; + else if (!signal && inverted) active = true; + else active = false; + + if (tick >= spawn_rate && active) { tick = 0; - if (worldObj.isRemote) - { + if (worldObj.isRemote) { Random rand = worldObj.rand; float MX = motion_x + (random_motion_x * rand.nextFloat()); @@ -86,33 +94,54 @@ public class TileParticleGenerator extends TileEntity ParticleHandler.spawnCustomParticle(particle); } - } - else - tick++; + } else tick++; } - - public void toggleInverted(){ + + @SideOnly(Side.CLIENT) + private void spawnStabilizerParticle(){ + if (getMaster() == null || worldObj.getTotalWorldTime() % (20) != 1) return; + + double x = xCoord + 0.5; + double y = yCoord + 0.5; + double z = zCoord + 0.5; + int direction = 0; + + if (getMaster().xCoord > xCoord) + direction = 0; + else if (getMaster().xCoord < xCoord) + direction = 1; + else if (getMaster().zCoord > zCoord) + direction = 2; + else if (getMaster().zCoord < zCoord) + direction = 3; + + Particles.EnergyBeamParticle particle = new Particles.EnergyBeamParticle(worldObj, x, y, z, getMaster().xCoord + 0.5, getMaster().zCoord + 0.5, direction, false); + Particles.EnergyBeamParticle particle2 = new Particles.EnergyBeamParticle(worldObj, x, y, z, getMaster().xCoord + 0.5, getMaster().zCoord + 0.5, direction, true); + ParticleHandler.spawnCustomParticle(particle, 60); + ParticleHandler.spawnCustomParticle(particle2, 60); + } + + public void toggleInverted() { inverted = !inverted; } @Override - public Packet getDescriptionPacket() - { + public Packet getDescriptionPacket() { NBTTagCompound tagCompound = new NBTTagCompound(); this.writeToNBT(tagCompound); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tagCompound); } @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) - { + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { readFromNBT(pkt.func_148857_g()); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } @Override - public void writeToNBT(NBTTagCompound compound) - { + public void writeToNBT(NBTTagCompound compound) { + master.writeToNBT(compound, "Key"); + compound.setBoolean("StabalizerMode", stabalizerMode); compound.setInteger("Red", red); compound.setInteger("Green", green); compound.setInteger("Blue", blue); @@ -143,14 +172,15 @@ public class TileParticleGenerator extends TileEntity compound.setFloat("Gravity", gravity); compound.setBoolean("Active", active); compound.setBoolean("Signal", signal); - compound.setBoolean("Inverted", inverted); + compound.setBoolean("Inverted", inverted); super.writeToNBT(compound); } @Override - public void readFromNBT(NBTTagCompound compound) - { + public void readFromNBT(NBTTagCompound compound) { + master.readFromNBT(compound, "Key"); + stabalizerMode = compound.getBoolean("StabalizerMode"); red = compound.getInteger("Red"); green = compound.getInteger("Green"); blue = compound.getInteger("Blue"); @@ -181,9 +211,23 @@ public class TileParticleGenerator extends TileEntity gravity = compound.getFloat("Gravity"); active = compound.getBoolean("Active"); signal = compound.getBoolean("Signal"); - inverted = compound.getBoolean("Inverted"); + inverted = compound.getBoolean("Inverted"); super.readFromNBT(compound); } + public TileEnergyStorageCore getMaster() { + if (master == null) return null; + TileEnergyStorageCore tile = (worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord()) != null && worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord()) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord()) : null; + return tile; + } + + public void setMaster(TileLocation master) { + this.master = master; + } + + @Override + public AxisAlignedBB getRenderBoundingBox() { + return INFINITE_EXTENT_AABB; + } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileEnergyPylon.java b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileEnergyPylon.java new file mode 100644 index 00000000..586d9c0c --- /dev/null +++ b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileEnergyPylon.java @@ -0,0 +1,277 @@ +package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles; + +import cofh.api.energy.EnergyStorage; +import cofh.api.energy.IEnergyHandler; +import com.brandon3055.draconicevolution.client.render.Particles; +import com.brandon3055.draconicevolution.common.blocks.ModBlocks; +import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation; +import com.brandon3055.draconicevolution.common.core.handler.ParticleHandler; +import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.EntityLiving; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +/** + * Created by Brandon on 28/07/2014. + */ +public class TileEnergyPylon extends TileEntity implements IEnergyHandler { + + protected EnergyStorage storage = new EnergyStorage(500000, 0, 0); + public boolean active = false; + public boolean input = false; + public float modelRotation = 0; + public float modelScale = 0; + private TileLocation masterLocation = new TileLocation(); + private int particleRate = 0; + private int updateDelay = 0; + private boolean nextUpdate = false; + + + @Override + public void updateEntity() { + if (nextUpdate) { + updateDelay = 0; + nextUpdate = false; + } + if (active && worldObj.isRemote) { + modelRotation += 1.5; + modelScale += input ? -0.01F : 0.01F; + if ((modelScale < 0 && input)) modelScale = 10000F; + if ((modelScale < 0 && !input)) modelScale = 0F; + spawnParticles(); + } else if (worldObj.isRemote) modelScale = 0.5F; + if (active && input){ + updateInput(); + }else if (active){ + updateOutput(); + } + } + + public void onActivated(){ + if (!active){ + active = isValidStructure(); + findMaster(); + return; + } + findMaster(); + if (input){ + storage.setMaxReceive(0); + storage.setMaxExtract(500000); + }else{ + storage.setMaxReceive(500000); + storage.setMaxExtract(0); + } + } + //input from core out to acceptors + private void updateInput(){ + if (updateDelay > 0){ + updateDelay--; + if (particleRate > 0) particleRate--; + }else if (getMaster() != null && getMaster().isOnline() && storage.getEnergyStored() < storage.getMaxEnergyStored() && getMaster().getEnergyStored() > 0) { + int maxRecived = (int)Math.min(storage.getMaxEnergyStored() - storage.getEnergyStored(), getMaster().getEnergyStored()); + storage.modifyEnergyStored(maxRecived); + getMaster().extractEnergy(maxRecived, false); + if (particleRate < 10) particleRate++; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + }else { + if (particleRate > 0) particleRate--; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + updateDelay = 20; + } + if ((storage.getEnergyStored() > 0)) { + for (int i = 0; i < 6; i++){ + TileEntity tile = worldObj.getTileEntity(xCoord + ForgeDirection.getOrientation(i).offsetX, yCoord + ForgeDirection.getOrientation(i).offsetY, zCoord + ForgeDirection.getOrientation(i).offsetZ); + if (tile != null && tile instanceof IEnergyHandler) { + storage.extractEnergy(((IEnergyHandler)tile).receiveEnergy(ForgeDirection.getOrientation(i).getOpposite(), storage.extractEnergy(storage.getMaxExtract(), true), false), false); + } + } + } + } + //output to core in from generators + private void updateOutput(){ + if (getMaster() == null || !getMaster().isOnline()) return; + if (updateDelay > 0){ + updateDelay--; + if (particleRate > 0) particleRate--; + }else if (storage.getEnergyStored() > 0 && getMaster().isOnline() && getMaster().getEnergyStored() < getMaster().getMaxEnergyStored()){ + int maxSent = (int)Math.min(getMaster().getMaxEnergyStored() - getMaster().getEnergyStored(), storage.getEnergyStored()); + storage.modifyEnergyStored(-maxSent); + getMaster().receiveEnergy(maxSent, false); + + if (particleRate < 10) particleRate++; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + }else { + if (particleRate > 0) particleRate--; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + updateDelay = 20; + } + } + + private TileEnergyStorageCore getMaster(){ + return (worldObj.getTileEntity(masterLocation.getXCoord(), masterLocation.getYCoord(), masterLocation.getZCoord()) != null && worldObj.getTileEntity(masterLocation.getXCoord(), masterLocation.getYCoord(), masterLocation.getZCoord()) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore)worldObj.getTileEntity(masterLocation.getXCoord(), masterLocation.getYCoord(), masterLocation.getZCoord()) : null; + } + + private void findMaster(){ + int yMod = worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1 ? 3 : -3; + int range = 15; + for (int x = xCoord-range; x <= xCoord+range; x++){ + for (int y = yCoord+yMod-(range/2); y <= yCoord+yMod+(range/2); y++){ + for (int z = zCoord-range; z <= zCoord+range; z++){ + if (worldObj.getBlock(x, y, z) == ModBlocks.energyStorageCore){ + masterLocation = new TileLocation(x, y, z); + return; + } + } + } + + } + } + + @SideOnly(Side.CLIENT) + private void spawnParticles(){ + Random rand = new Random(); + int x = masterLocation.getXCoord(); + int y = masterLocation.getYCoord(); + int z = masterLocation.getZCoord(); + int cYCoord = worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1 ? yCoord+1 : yCoord-1; + TileEnergyStorageCore master = (worldObj.getTileEntity(x, y, z) != null && worldObj.getTileEntity(x, y, z) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) worldObj.getTileEntity(x, y, z) : null; + if (master == null || !master.isOnline()) return; + float disMod = master.getTier()==0 ? 0.5F : master.getTier()==1 ? 1F: master.getTier()==2 ? 1F : master.getTier()==3 ? 2F : master.getTier()==4 ? 2F : master.getTier()==5 ? 3F : 4F; + double spawnX; + double spawnY; + double spawnZ; + double targetX; + double targetY; + double targetZ; + if (input){ + spawnX = x+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + spawnY = y+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + spawnZ = z+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + targetX = xCoord + 0.5; + targetY = cYCoord + 0.5; + targetZ = zCoord + 0.5; + if (rand.nextFloat() < 0.1F) { + Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(worldObj, spawnX, spawnY, spawnZ, targetX, targetY, targetZ, true); + ParticleHandler.spawnCustomParticle(passiveParticle, 50); + } + if (particleRate > 0){ + if (particleRate > 10) particleRate = 10; + for (int i = 0; i <= particleRate; i++){ + spawnX = x+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + spawnY = y+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + spawnZ = z+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(worldObj, spawnX, spawnY, spawnZ, targetX, targetY, targetZ, false); + ParticleHandler.spawnCustomParticle(passiveParticle, 50); + } + } + + }else { + targetX = x+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + targetY = y+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + targetZ = z+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + spawnX = xCoord + 0.5; + spawnY = cYCoord + 0.5; + spawnZ = zCoord + 0.5; + if (rand.nextFloat() < 0.1F) { + Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(worldObj, spawnX, spawnY, spawnZ, targetX, targetY, targetZ, true); + ParticleHandler.spawnCustomParticle(passiveParticle, 50); + } + if (particleRate > 0){ + if (particleRate > 10) particleRate = 10; + for (int i = 0; i <= particleRate; i++){ + targetX = x+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + targetY = y+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + targetZ = z+0.5 - disMod + (rand.nextFloat() * (disMod*2)); + Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(worldObj, spawnX, spawnY, spawnZ, targetX, targetY, targetZ, false); + ParticleHandler.spawnCustomParticle(passiveParticle, 50); + } + } + } + } + + private boolean isValidStructure(){ + return (isGlass(xCoord, yCoord+1, zCoord) || isGlass(xCoord, yCoord-1, zCoord)) && (!isGlass(xCoord, yCoord+1, zCoord) || !isGlass(xCoord, yCoord-1, zCoord)); + } + + private boolean isGlass(int x, int y, int z){ + return worldObj.getBlock(x, y, z) == ModBlocks.invisibleMultiblock && worldObj.getBlockMetadata(x, y, z) == 2; + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + super.readFromNBT(compound); + storage.readFromNBT(compound); + active = compound.getBoolean("Active"); + input = compound.getBoolean("Input"); + masterLocation.readFromNBT(compound, "Master"); + particleRate = compound.getShort("ParticleRate"); + } + + @Override + public void writeToNBT(NBTTagCompound compound) { + + super.writeToNBT(compound); + storage.writeToNBT(compound); + compound.setBoolean("Active", active); + compound.setBoolean("Input", input); + masterLocation.writeToNBT(compound, "Master"); + compound.setShort("ParticleRate", (short)particleRate); + } + + @Override + public Packet getDescriptionPacket(){ + NBTTagCompound nbttagcompound = new NBTTagCompound(); + writeToNBT(nbttagcompound); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + readFromNBT(pkt.func_148857_g()); + } + + /* IEnergyHandler */ + @Override + public boolean canConnectEnergy(ForgeDirection from) { + return true; + } + + @Override + public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { + nextUpdate = true; + return storage.receiveEnergy(maxReceive, simulate); + } + + @Override + public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { + nextUpdate = true; + return storage.extractEnergy(maxExtract, simulate); + } + + @Override + public int getEnergyStored(ForgeDirection from) { + return storage.getEnergyStored(); + } + + @Override + public int getMaxEnergyStored(ForgeDirection from) { + return storage.getMaxEnergyStored(); + } + + @Override + public AxisAlignedBB getRenderBoundingBox() { + return INFINITE_EXTENT_AABB; + } +} diff --git a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileEnergyStorageCore.java b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileEnergyStorageCore.java index 8c764566..721f7bf9 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileEnergyStorageCore.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileEnergyStorageCore.java @@ -5,29 +5,42 @@ import cofh.api.energy.IEnergyHandler; import com.brandon3055.draconicevolution.common.blocks.ModBlocks; import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation; import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import com.brandon3055.draconicevolution.common.tileentities.TileParticleGenerator; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; /** * Created by Brandon on 25/07/2014. */ -public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler { +public class TileEnergyStorageCore extends TileEntity { - protected EnergyStorage storage = new EnergyStorage(1000000, 1000000, 1000000); protected TileLocation[] stabilizers = new TileLocation[4]; - protected int tier = 6; + protected int tier = 0; protected boolean online = false; + public float modelRotation = 0; + private double energy = 0; + private double capacity = 0; + private int maxReceive = 1000000; + private int maxExtract = 1000000; + public TileEnergyStorageCore(){ + for (int i = 0; i < stabilizers.length; i++) + { + stabilizers[i] = new TileLocation(); + } + } + @Override public void updateEntity() { - if (tier != 6) - LogHelper.info(tier); + if (!online) return; + if (worldObj.isRemote) modelRotation += 0.5; } @@ -39,51 +52,109 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler if (!findStabalyzers()) return false; if (!setTier(false)) return false; if (!testOrActivateStructureIfValid(false, false)) return false; - if (!testOrActivateStructureIfValid(false, true)) return false; - //LogHelper.info(testOrActivateStructureIfValid(false, true)); - + online = true; + if (!testOrActivateStructureIfValid(false, true)) { + online = false; + deactivateStabilizers(); + return false; + } + activateStabilizers(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); return true; } - public boolean isStructureStillValid(){ + public boolean creativeActivate() { + if (!findStabalyzers()) return false; + if (!setTier(false)) return false; + if (!testOrActivateStructureIfValid(true, false)) return false; + online = true; + if (!testOrActivateStructureIfValid(false, true)) { + online = false; + deactivateStabilizers(); + return false; + } + activateStabilizers(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); return true; } + public boolean isStructureStillValid(boolean update){ + if (!checkStabilizers()) online = false; + if (!testOrActivateStructureIfValid(false, false)) online = false; + if (!areStabilizersActive()) online = false; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + if (!online) deactivateStabilizers(); + if (update && !online) reIntegrate(); + //if (update && !online && worldObj.getTileEntity(xCoord, yCoord + 1, zCoord) != null && worldObj.getTileEntity(xCoord, yCoord + 1, zCoord) instanceof TileInvisibleMultiblock) ((TileInvisibleMultiblock)worldObj.getTileEntity(xCoord, yCoord + 1, zCoord)).isStructureStillValid(); + return online; + } + + private void reIntegrate(){ + for (int x = xCoord - 1; x <= xCoord + 1; x++) { + for (int y = yCoord - 1; y <= yCoord + 1; y++) { + for (int z = zCoord - 1; z <= zCoord + 1; z++) { + if (worldObj.getBlock(x, y, z) == ModBlocks.invisibleMultiblock) + { + if (worldObj.getBlockMetadata(x, y, z) == 0) worldObj.setBlock(x, y, z, ModBlocks.draconium); + else if (worldObj.getBlockMetadata(x, y, z) == 1) worldObj.setBlock(x, y, z, Blocks.redstone_block); + } + } + } + } + } + private boolean findStabalyzers() { + boolean flag = true; for (int x = xCoord; x <= xCoord + 11; x++) { if (worldObj.getBlock(x, yCoord, zCoord) == ModBlocks.particleGenerator) { + if (worldObj.getBlockMetadata(x, yCoord, zCoord) == 1) { + flag = false; + break; + } stabilizers[0] = new TileLocation(x, yCoord, zCoord); break; } else if (x == xCoord + 11) { - return false; + flag = false; } } for (int x = xCoord; x >= xCoord - 11; x--) { if (worldObj.getBlock(x, yCoord, zCoord) == ModBlocks.particleGenerator) { + if (worldObj.getBlockMetadata(x, yCoord, zCoord) == 1) { + flag = false; + break; + } stabilizers[1] = new TileLocation(x, yCoord, zCoord); break; } else if (x == xCoord - 11) { - return false; + flag = false; } } for (int z = zCoord; z <= zCoord + 11; z++) { if (worldObj.getBlock(xCoord, yCoord, z) == ModBlocks.particleGenerator) { + if (worldObj.getBlockMetadata(xCoord, yCoord, z) == 1) { + flag = false; + break; + } stabilizers[2] = new TileLocation(xCoord, yCoord, z); break; } else if (z == zCoord + 11) { - return false; + flag = false; } } for (int z = zCoord; z >= zCoord - 11; z--) { if (worldObj.getBlock(xCoord, yCoord, z) == ModBlocks.particleGenerator) { + if (worldObj.getBlockMetadata(xCoord, yCoord, z) == 1) { + flag = false; + break; + } stabilizers[3] = new TileLocation(xCoord, yCoord, z); break; } else if (z == zCoord - 11) { - return false; + flag = false; } } - return true; + return flag; } private boolean setTier(boolean force) { @@ -106,7 +177,6 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler for (int x = 0; x <= range; x++) { if (testForOrActivateDraconium(xCoord - x, yCoord, zCoord, false, false)) { xNeg = x; - if (xNeg != xPos) return false; break; } } @@ -114,7 +184,6 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler for (int y = 0; y <= range; y++) { if (testForOrActivateDraconium(xCoord, yCoord + y, zCoord, false, false)) { yPos = y; - if (yPos != xNeg) return false; break; } } @@ -122,7 +191,6 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler for (int y = 0; y <= range; y++) { if (testForOrActivateDraconium(xCoord, yCoord - y, zCoord, false, false)) { yNeg = y; - if (yNeg != yPos) return false; break; } } @@ -130,7 +198,6 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler for (int z = 0; z <= range; z++) { if (testForOrActivateDraconium(xCoord, yCoord, zCoord + z, false, false)) { zPos = z; - if (zPos != yNeg) return false; break; } } @@ -138,17 +205,16 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler for (int z = 0; z <= range; z++) { if (testForOrActivateDraconium(xCoord, yCoord, zCoord - z, false, false)) { zNeg = z; - if (zNeg != zPos) return false; break; } } + if (zNeg != zPos || zNeg != yNeg || zNeg != yPos || zNeg != xNeg || zNeg != xPos) return false; tier = xPos; if (tier > 1) tier++; if (tier == 1){ if (testForOrActivateDraconium(xCoord + 1, yCoord + 1, zCoord, false, false)) tier = 2; } - //LogHelper.info(""+tier); return true; } @@ -521,6 +587,99 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler return online; } + private void activateStabilizers(){ + for (int i = 0; i < stabilizers.length; i++) + { + if (stabilizers[i] == null){ + LogHelper.error("activateStabilizers stabalizers["+i+"] == null!!!"); + return; + } + TileParticleGenerator tile = (worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) != null && worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) instanceof TileParticleGenerator) ? (TileParticleGenerator) worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) : null; + if (tile == null) + { + LogHelper.error("Missing Tile Entity (Particle Generator)"); + return; + } + tile.stabalizerMode = true; + tile.setMaster(new TileLocation(xCoord, yCoord, zCoord)); + worldObj.setBlockMetadataWithNotify(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord(), 1, 2); + } + double capacity = 0; + switch (tier){ + case 0: + capacity = 45500000D; + break; + case 1: + capacity = 273000000D; + break; + case 2: + capacity = 1640000000D; + break; + case 3: + capacity = 9880000000D; + break; + case 4: + capacity = 59300000000D; + break; + case 5: + capacity = 356000000000D; + break; + case 6: + capacity = 2140000000000D; + break; + } + this.capacity = capacity; + } + + public void deactivateStabilizers(){ + for (int i = 0; i < stabilizers.length; i++) + { + if (stabilizers[i] == null){ + LogHelper.error("activateStabilizers stabalizers["+i+"] == null!!!"); + }else { + TileParticleGenerator tile = (worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) != null && worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) instanceof TileParticleGenerator) ? (TileParticleGenerator) worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) : null; + if (tile == null) { + //LogHelper.error("Missing Tile Entity (Particle Generator)"); + }else { + tile.stabalizerMode = false; + worldObj.setBlockMetadataWithNotify(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord(), 0, 2); + } + } + } + } + + private boolean areStabilizersActive(){ + for (int i = 0; i < stabilizers.length; i++) + { + if (stabilizers[i] == null){ + LogHelper.error("activateStabilizers stabalizers["+i+"] == null!!!"); + return false; + } + TileParticleGenerator tile = (worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) != null && worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) instanceof TileParticleGenerator) ? (TileParticleGenerator) worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) : null; + if (tile == null) + { + //LogHelper.error("Missing Tile Entity (Particle Generator)"); + return false; + } + if (!tile.stabalizerMode || worldObj.getBlockMetadata(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) != 1) return false; + } + return true; + } + + private boolean checkStabilizers(){ + for (int i = 0; i < stabilizers.length; i++) + { + if (stabilizers[i] == null) return false; + TileParticleGenerator gen = (worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) != null && worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) instanceof TileParticleGenerator) ? (TileParticleGenerator)worldObj.getTileEntity(stabilizers[i].getXCoord(), stabilizers[i].getYCoord(), stabilizers[i].getZCoord()) : null; + if (gen == null || !gen.stabalizerMode) return false; + if (gen.getMaster().xCoord != xCoord || gen.getMaster().yCoord != yCoord || gen.getMaster().zCoord != zCoord) return false; + } + return true; + } + + public int getTier(){ + return tier; + } /** * ############################################################### */ @@ -528,8 +687,10 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler @Override public void writeToNBT(NBTTagCompound compound) { - storage.writeToNBT(compound); super.writeToNBT(compound); + compound.setBoolean("Online", online); + compound.setShort("Tier", (short)tier); + compound.setDouble("Energy", energy); for (int i = 0; i < stabilizers.length; i++){ if (stabilizers[i] != null) stabilizers[i].writeToNBT(compound, String.valueOf(i)); @@ -538,12 +699,39 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler @Override public void readFromNBT(NBTTagCompound compound) { - storage.readFromNBT(compound); - super.readFromNBT(compound); + online = compound.getBoolean("Online"); + tier = (int)compound.getShort("Tier"); + energy = compound.getDouble("Energy"); for (int i = 0; i < stabilizers.length; i++){ if (stabilizers[i] != null) stabilizers[i].readFromNBT(compound, String.valueOf(i)); } + double capacity = 0; + switch (tier){ + case 0: + capacity = 45500000D;//000 + break; + case 1: + capacity = 273000000D;//000 + break; + case 2: + capacity = 1640000000D;//000 + break; + case 3: + capacity = 9880000000D;//000 + break; + case 4: + capacity = 59300000000D;//000 + break; + case 5: + capacity = 356000000000D;//000 + break; + case 6: + capacity = 2140000000000D;//000 + break; + } + this.capacity = capacity; + super.readFromNBT(compound); } @Override @@ -558,31 +746,37 @@ public class TileEnergyStorageCore extends TileEntity implements IEnergyHandler readFromNBT(pkt.func_148857_g()); } - /* IEnergyHandler */ - @Override - public boolean canConnectEnergy(ForgeDirection from) { - return true; + /* EnergyHandler */ + + public int receiveEnergy(int maxReceive, boolean simulate) { + double energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); + + if (!simulate) { + energy += energyReceived; + } + return (int)energyReceived; } - @Override - public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { - - return storage.receiveEnergy(maxReceive, simulate); - } - - @Override - public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { + public int extractEnergy(int maxExtract, boolean simulate) { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - return storage.extractEnergy(maxExtract, simulate); + double energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); + + if (!simulate) { + energy -= energyExtracted; + } + return (int)energyExtracted; + } + + public double getEnergyStored() { + return energy; + } + + public double getMaxEnergyStored() { + return capacity; } @Override - public int getEnergyStored(ForgeDirection from) { - return storage.getEnergyStored(); - } - - @Override - public int getMaxEnergyStored(ForgeDirection from) { - return storage.getMaxEnergyStored(); + public AxisAlignedBB getRenderBoundingBox() { + return INFINITE_EXTENT_AABB; } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileInvisibleMultiblock.java b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileInvisibleMultiblock.java index 8275938a..df9b8b26 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileInvisibleMultiblock.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/TileInvisibleMultiblock.java @@ -1,18 +1,21 @@ package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles; +import com.brandon3055.draconicevolution.common.blocks.ModBlocks; import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation; import com.brandon3055.draconicevolution.common.core.utills.LogHelper; +import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; /** * Created by Brandon on 26/07/2014. */ public class TileInvisibleMultiblock extends TileEntity { - public TileLocation master; + public TileLocation master = new TileLocation(); public boolean isMasterOnline() { TileEnergyStorageCore tile = (worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord()) != null && worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord()) instanceof TileEnergyStorageCore) ? (TileEnergyStorageCore) worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord()) : null; @@ -31,13 +34,15 @@ public class TileInvisibleMultiblock extends TileEntity { @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); - master.writeToNBT(compound, "Key"); + //if (master != null) + master.writeToNBT(compound, "Key"); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); - master.readFromNBT(compound, "Key"); + //if (master != null) + master.readFromNBT(compound, "Key"); } @Override @@ -52,4 +57,20 @@ public class TileInvisibleMultiblock extends TileEntity { readFromNBT(pkt.func_148857_g()); } + public void isStructureStillValid(){ + if (getMaster() == null) { + LogHelper.error("{Tile} Master = null reverting!"); + revert(); + return; + } + if (!getMaster().isOnline()) revert(); + } + + private void revert(){ + int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); + if (meta == 0) + worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.draconium); + else if (meta == 1) + worldObj.setBlock(xCoord, yCoord, zCoord, Blocks.redstone_block); + } } diff --git a/src/main/resources/assets/draconicevolution/models/power_sphere_layer_2.obj b/src/main/resources/assets/draconicevolution/models/pylon_sphere.obj similarity index 100% rename from src/main/resources/assets/draconicevolution/models/power_sphere_layer_2.obj rename to src/main/resources/assets/draconicevolution/models/pylon_sphere.obj diff --git a/src/main/resources/assets/draconicevolution/models/stabilizer_sphere.obj b/src/main/resources/assets/draconicevolution/models/stabilizer_sphere.obj new file mode 100644 index 00000000..62dd9430 --- /dev/null +++ b/src/main/resources/assets/draconicevolution/models/stabilizer_sphere.obj @@ -0,0 +1,41 @@ +# Blender v2.70 (sub 0) OBJ File: 'stabilizer_sphere.blend' +# www.blender.org +mtllib stabilizer_sphere.mtl +o Icosphere +v 0.000000 -1.000000 0.000000 +v 0.723600 -0.447215 0.525720 +v -0.276385 -0.447215 0.850640 +v -0.894425 -0.447215 0.000000 +v -0.276385 -0.447215 -0.850640 +v 0.723600 -0.447215 -0.525720 +v 0.276385 0.447215 0.850640 +v -0.723600 0.447215 0.525720 +v -0.723600 0.447215 -0.525720 +v 0.276385 0.447215 -0.850640 +v 0.894425 0.447215 0.000000 +v 0.000000 1.000000 0.000000 +vt 0.000000 0.000000 +vt 1.000000 0.000000 +vt 1.000000 1.000000 +usemtl None +s off +f 1/1 2/2 3/3 +f 2/1 1/2 6/3 +f 1/1 3/2 4/3 +f 1/1 4/2 5/3 +f 1/1 5/2 6/3 +f 2/1 6/2 11/3 +f 3/1 2/2 7/3 +f 4/1 3/2 8/3 +f 5/1 4/2 9/3 +f 6/1 5/2 10/3 +f 2/1 11/2 7/3 +f 3/1 7/2 8/3 +f 4/1 8/2 9/3 +f 5/1 9/2 10/3 +f 6/1 10/2 11/3 +f 7/1 11/2 12/3 +f 8/1 7/2 12/3 +f 9/1 8/2 12/3 +f 10/1 9/2 12/3 +f 11/1 10/2 12/3 diff --git a/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_active_face.png b/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_active_face.png new file mode 100644 index 00000000..696b981d Binary files /dev/null and b/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_active_face.png differ diff --git a/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_input.png b/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_input.png new file mode 100644 index 00000000..53b22a5d Binary files /dev/null and b/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_input.png differ diff --git a/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_output.png b/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_output.png new file mode 100644 index 00000000..c0dd7ffc Binary files /dev/null and b/src/main/resources/assets/draconicevolution/textures/blocks/energy_pylon_output.png differ diff --git a/src/main/resources/assets/draconicevolution/textures/models/ParticleGenTextureSheet.png b/src/main/resources/assets/draconicevolution/textures/models/ParticleGenTextureSheet.png index 64b69684..5aeda8f7 100644 Binary files a/src/main/resources/assets/draconicevolution/textures/models/ParticleGenTextureSheet.png and b/src/main/resources/assets/draconicevolution/textures/models/ParticleGenTextureSheet.png differ diff --git a/src/main/resources/assets/draconicevolution/textures/models/pylon_sphere_texture.png b/src/main/resources/assets/draconicevolution/textures/models/pylon_sphere_texture.png new file mode 100644 index 00000000..0efaa891 Binary files /dev/null and b/src/main/resources/assets/draconicevolution/textures/models/pylon_sphere_texture.png differ diff --git a/src/main/resources/assets/draconicevolution/textures/models/stabilizer_beam.png b/src/main/resources/assets/draconicevolution/textures/models/stabilizer_beam.png new file mode 100644 index 00000000..4a933d42 Binary files /dev/null and b/src/main/resources/assets/draconicevolution/textures/models/stabilizer_beam.png differ diff --git a/src/main/resources/assets/draconicevolution/textures/models/stabilizer_sphere.png b/src/main/resources/assets/draconicevolution/textures/models/stabilizer_sphere.png new file mode 100644 index 00000000..9ad563ad Binary files /dev/null and b/src/main/resources/assets/draconicevolution/textures/models/stabilizer_sphere.png differ