From efee0706afc31283c9ac46e3923396462be4572e Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 17 Jul 2024 10:37:12 +0200 Subject: [PATCH] you can, in fact, wire a WIAJ into a particle renderer --- .../java/com/hbm/items/tool/ItemWandD.java | 29 +++- src/main/java/com/hbm/main/ClientProxy.java | 58 ++++++++ .../java/com/hbm/particle/ParticleDebris.java | 124 ++++++++++++++++++ .../render/tileentity/RendererObjTester.java | 5 +- src/main/java/com/hbm/wiaj/WorldInAJar.java | 4 +- 5 files changed, 211 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/hbm/particle/ParticleDebris.java diff --git a/src/main/java/com/hbm/items/tool/ItemWandD.java b/src/main/java/com/hbm/items/tool/ItemWandD.java index e890a3def..2f41c52fa 100644 --- a/src/main/java/com/hbm/items/tool/ItemWandD.java +++ b/src/main/java/com/hbm/items/tool/ItemWandD.java @@ -2,16 +2,20 @@ package com.hbm.items.tool; import java.util.List; +import com.hbm.explosion.vanillant.ExplosionVNT; +import com.hbm.explosion.vanillant.standard.BlockAllocatorStandard; import com.hbm.lib.Library; -import com.hbm.world.gen.component.Component; -import com.hbm.world.gen.component.CivilianFeatures.RuralHouse1; +import com.hbm.packet.AuxParticlePacketNT; +import com.hbm.packet.PacketDispatcher; + +import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; -import net.minecraft.world.gen.structure.StructureBoundingBox; public class ItemWandD extends Item { @@ -35,13 +39,28 @@ public class ItemWandD extends Item { //PollutionHandler.incrementPollution(world, pos.blockX, pos.blockY, pos.blockZ, PollutionType.SOOT, 15); - int i = pos.blockX >> 4; + /*int i = pos.blockX >> 4; int j = pos.blockZ >> 4; i = (i << 4) + 8; j = (j << 4) + 8; Component comp = new RuralHouse1(world.rand, i, j); - comp.addComponentParts(world, world.rand, new StructureBoundingBox(i, j, i + 32, j + 32)); + comp.addComponentParts(world, world.rand, new StructureBoundingBox(i, j, i + 32, j + 32));*/ + + ExplosionVNT vnt = new ExplosionVNT(world, pos.blockX + 0.5, pos.blockY + 1, pos.blockZ + 0.5, 25F); + vnt.makeStandard(); + vnt.setSFX(); + vnt.setBlockAllocator(new BlockAllocatorStandard(32)); + vnt.explode(); + + for(int i = 0; i < 10; i++) { + NBTTagCompound data = new NBTTagCompound(); + data.setString("type", "debris"); + PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.blockX + world.rand.nextGaussian() * 3, pos.blockY - 2, pos.blockZ + world.rand.nextGaussian() * 3), new TargetPoint(world.provider.dimensionId, pos.blockX, pos.blockY, pos.blockZ, 100)); + } + NBTTagCompound data = new NBTTagCompound(); + data.setString("type", "oomph"); + PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, pos.blockX, pos.blockY, pos.blockZ), new TargetPoint(world.provider.dimensionId, pos.blockX, pos.blockY, pos.blockZ, 100)); /*TimeAnalyzer.startCount("setBlock"); world.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.dirt); diff --git a/src/main/java/com/hbm/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index 4b4d82843..cdb651dd0 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -124,6 +124,7 @@ import com.hbm.tileentity.turret.*; import com.hbm.util.BobMathUtil; import com.hbm.util.ColorUtil; import com.hbm.util.fauxpointtwelve.BlockPos; +import com.hbm.wiaj.WorldInAJar; import com.hbm.wiaj.cannery.Jars; import cpw.mods.fml.client.registry.ClientRegistry; @@ -985,6 +986,7 @@ public class ClientProxy extends ServerProxy { } //mk3, only use this one + @Override public void effectNT(NBTTagCompound data) { World world = Minecraft.getMinecraft().theWorld; @@ -1001,6 +1003,62 @@ public class ClientProxy extends ServerProxy { double y = data.getDouble("posY"); double z = data.getDouble("posZ"); + if("oomph".equals(type)) { + for(int i = 0; i < 15; i++) { + ParticleRocketFlame fx = new ParticleRocketFlame(man, world, x, y, z).setScale(5F); + fx.prevPosX = fx.posX; + fx.prevPosY = fx.posY; + fx.prevPosZ = fx.posZ; + fx.motionX = rand.nextGaussian() * 0.5; + fx.motionY = rand.nextDouble() * 3; + fx.motionZ = rand.nextGaussian() * 0.5; + fx.setMaxAge(70 + rand.nextInt(20)); + fx.noClip = true; + Minecraft.getMinecraft().effectRenderer.addEffect(fx); + } + + ParticleMukeWave wave = new ParticleMukeWave(man, world, x, y + 2, z); + Minecraft.getMinecraft().effectRenderer.addEffect(wave); + } + + if("debris".equals(type)) { + int ix = (int) Math.floor(x); + int iy = (int) Math.floor(y); + int iz = (int) Math.floor(z); + Vec3 motion = Vec3.createVectorHelper(1, 0, 0); + motion.rotateAroundZ((float) -Math.toRadians(45 + rand.nextFloat() * 25)); + motion.rotateAroundY((float) (rand.nextDouble() * Math.PI * 2)); + ParticleDebris particle = new ParticleDebris(world, x, y, z, motion.xCoord, motion.yCoord, motion.zCoord); + WorldInAJar wiaj = new WorldInAJar(16, 16, 16); + particle.world = wiaj; + + int cX = (int) Math.floor(x + 0.5); + int cY = (int) Math.floor(y + 0.5); + int cZ = (int) Math.floor(z + 0.5); + + for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) for(int k = 0; k < 2; k++) + wiaj.setBlock(7 + i, 7 + j, 7 + k, world.getBlock(cX + i, cY + j, cZ + k), world.getBlockMetadata(cX + i, cY+ j, cZ + k)); + + for(int layer = 2; layer <= 8; layer++) { + for(int i = 0; i < 50; i++) { + int jx = -layer + rand.nextInt(layer * 2 + 1); + int jy = -layer + rand.nextInt(layer * 2 + 1); + int jz = -layer + rand.nextInt(layer * 2 + 1); + + if(wiaj.getBlock(7 + jx + 1, 7 + jy, 7 + jz) != Blocks.air || wiaj.getBlock(7 + jx - 1, 7 + jy, 7 + jz) != Blocks.air || + wiaj.getBlock(7 + jx, 7 + jy + 1, 7 + jz) != Blocks.air || wiaj.getBlock(7 + jx, 7 + jy - 1, 7 + jz) != Blocks.air || + wiaj.getBlock(7 + jx, 7 + jy, 7 + jz + 1) != Blocks.air || wiaj.getBlock(7 + jx, 7 + jy, 7 + jz - 1) != Blocks.air) { + + Block b = world.getBlock(cX + jx, cY + jy, cZ + jz); + int m = world.getBlockMetadata(cX + jx, cY + jy, cZ + jz); + wiaj.setBlock(7 + jx, 7+ jy, 7 + jz, b, m); + } + } + } + + Minecraft.getMinecraft().effectRenderer.addEffect(particle); + } + if("missileContrail".equals(type)) { if(Vec3.createVectorHelper(player.posX - x, player.posY - y, player.posZ - z).lengthVector() > 350) return; diff --git a/src/main/java/com/hbm/particle/ParticleDebris.java b/src/main/java/com/hbm/particle/ParticleDebris.java new file mode 100644 index 000000000..e9b4bb9eb --- /dev/null +++ b/src/main/java/com/hbm/particle/ParticleDebris.java @@ -0,0 +1,124 @@ +package com.hbm.particle; + +import java.util.Random; + +import org.lwjgl.opengl.GL11; + +import com.hbm.wiaj.WorldInAJar; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +public class ParticleDebris extends EntityFX { + + private RenderBlocks renderer; + public WorldInAJar world; + public static Random rng = new Random(); + + public ParticleDebris(World world, double x, double y, double z) { + super(world, x, y, z); + } + + public ParticleDebris(World world, double x, double y, double z, double mx, double my, double mz) { + super(world, x, y, z); + double mult = 3; + this.motionX = mx * mult; + this.motionY = my * mult; + this.motionZ = mz * mult; + this.particleMaxAge = 100; + this.particleGravity = 0.15F; + this.noClip = true; + } + + @Override + public int getFXLayer() { + return 3; + } + + @Override + public void onUpdate() { + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; + + if(this.particleAge > 5) this.noClip = false; + + rng.setSeed(this.getEntityId()); + this.prevRotationPitch = this.rotationPitch; + this.prevRotationYaw = this.rotationYaw; + this.rotationPitch += rng.nextFloat() * 10; + this.rotationYaw += rng.nextFloat() * 10; + + if(this.getEntityId() % 3 == 0) { + TextureManager man = Minecraft.getMinecraft().renderEngine; + ParticleRocketFlame fx = new ParticleRocketFlame(man, worldObj, posX, posY, posZ).setScale(1F); + fx.prevPosX = fx.posX; + fx.prevPosY = fx.posY; + fx.prevPosZ = fx.posZ; + fx.setMaxAge(50); + Minecraft.getMinecraft().effectRenderer.addEffect(fx); + } + + this.motionY -= this.particleGravity; + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + + this.particleAge++; + if(this.onGround) this.setDead(); + } + + @Override + public void renderParticle(Tessellator tess, float interp, float fX, float fY, float fZ, float sX, float sZ) { + + if(world == null) return; + + if(renderer == null) { + renderer = new RenderBlocks(world); + } + + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + double dX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)interp; + double dY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)interp; + double dZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)interp; + + float pX = (float) ((this.prevPosX + (this.posX - this.prevPosX) * (double) interp - dX)); + float pY = (float) ((this.prevPosY + (this.posY - this.prevPosY) * (double) interp - dY)); + float pZ = (float) ((this.prevPosZ + (this.posZ - this.prevPosZ) * (double) interp - dZ)); + + renderer.enableAO = true; + world.lightlevel = worldObj.getLightBrightnessForSkyBlocks((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ), 0); + + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL11.GL_BLEND); + //OpenGlHelper.glBlendFunc(770, 771, 1, 0); + + GL11.glPushMatrix(); + GL11.glTranslatef(pX, pY, pZ); + GL11.glRotated(prevRotationPitch + (rotationPitch - prevRotationPitch) * interp, 0, 1, 0); + GL11.glRotated(prevRotationYaw + (rotationYaw - prevRotationYaw) * interp, 0, 0, 1); + GL11.glTranslated(-world.sizeX / 2D, -world.sizeY / 2D, -world.sizeZ / 2D); + + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + GL11.glShadeModel(GL11.GL_SMOOTH); + Tessellator.instance.startDrawingQuads(); + + for(int ix = 0; ix < world.sizeX; ix++) { + for(int iy = 0; iy < world.sizeY; iy++) { + for(int iz = 0; iz < world.sizeZ; iz++) { + renderer.renderBlockByRenderType(world.getBlock(ix, iy, iz), ix, iy, iz); + } + } + } + + Tessellator.instance.draw(); + GL11.glShadeModel(GL11.GL_FLAT); + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/com/hbm/render/tileentity/RendererObjTester.java b/src/main/java/com/hbm/render/tileentity/RendererObjTester.java index 22e1d25a7..c22a2a287 100644 --- a/src/main/java/com/hbm/render/tileentity/RendererObjTester.java +++ b/src/main/java/com/hbm/render/tileentity/RendererObjTester.java @@ -34,7 +34,7 @@ public class RendererObjTester extends TileEntitySpecialRenderer { @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { GL11.glPushMatrix(); - GL11.glTranslated(x + 0.5, y + 2, z + 0.5); + GL11.glTranslated(x + 0.5, y + 1, z + 0.5); GL11.glRotated(15, 0, 0, 1); GL11.glDisable(GL11.GL_CULL_FACE); @@ -50,9 +50,9 @@ public class RendererObjTester extends TileEntitySpecialRenderer { renderer = new RenderBlocks(world); } renderer.enableAO = true; + world.lightlevel = tileEntity.getWorldObj().getLightBrightnessForSkyBlocks(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 0); RenderHelper.disableStandardItemLighting(); - Minecraft.getMinecraft().entityRenderer.disableLightmap(f); GL11.glPushMatrix(); GL11.glTranslated(-2.5, 0, -2.5); @@ -72,7 +72,6 @@ public class RendererObjTester extends TileEntitySpecialRenderer { GL11.glShadeModel(GL11.GL_FLAT); GL11.glPopMatrix(); - Minecraft.getMinecraft().entityRenderer.enableLightmap(f); RenderHelper.enableStandardItemLighting(); GL11.glTranslated(0, 2.1, 0.5); diff --git a/src/main/java/com/hbm/wiaj/WorldInAJar.java b/src/main/java/com/hbm/wiaj/WorldInAJar.java index 7f2fc1266..2b8ff6e8b 100644 --- a/src/main/java/com/hbm/wiaj/WorldInAJar.java +++ b/src/main/java/com/hbm/wiaj/WorldInAJar.java @@ -19,6 +19,8 @@ public class WorldInAJar implements IBlockAccess { public int sizeX; public int sizeY; public int sizeZ; + + public int lightlevel = 15; private Block[][][] blocks; private short[][][] meta; @@ -87,7 +89,7 @@ public class WorldInAJar implements IBlockAccess { @Override @SideOnly(Side.CLIENT) public int getLightBrightnessForSkyBlocks(int x, int y, int z, int blockBrightness) { - return 15; //always be on fullbright + return lightlevel; } //redstone could theoretically be implemented, but we will wait for now