aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub <53441451+kuba6000@users.noreply.github.com>2022-12-19 12:42:21 +0100
committerGitHub <noreply@github.com>2022-12-19 12:42:21 +0100
commit6c0754925ee51bc8828b23533af946e4ee596d6d (patch)
tree4e828cf137abfcd91ea3486d3e44b1ff8c1e3859 /src
parent18bdd470fea79ef3e111c48018eebfa7bac0d305 (diff)
downloadGT5-Unofficial-6c0754925ee51bc8828b23533af946e4ee596d6d.tar.gz
GT5-Unofficial-6c0754925ee51bc8828b23533af946e4ee596d6d.tar.bz2
GT5-Unofficial-6c0754925ee51bc8828b23533af946e4ee596d6d.zip
Make EIC animation only visual (#251)
* ITS RENDERING ! * Ok * Stupid muffler upgrade * Fix * Fix Former-commit-id: 0b341e9b42530c41572a2b743f788cff4ffc653f
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java69
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java3
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/net/EICPacket.java56
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java98
4 files changed, 192 insertions, 34 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java
new file mode 100644
index 0000000000..4aebcab47a
--- /dev/null
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/renderer/BW_EICPistonVisualizer.java
@@ -0,0 +1,69 @@
+package com.github.bartimaeusnek.bartworks.client.renderer;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import gregtech.api.GregTech_API;
+import net.minecraft.client.particle.EntityFX;
+import net.minecraft.client.renderer.RenderBlocks;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.world.World;
+import org.lwjgl.opengl.GL11;
+
+@SideOnly(Side.CLIENT)
+public class BW_EICPistonVisualizer extends EntityFX {
+
+ public BW_EICPistonVisualizer(World world, int x, int y, int z, int age) {
+ super(world, (double) x, ((double) y), (double) z);
+ this.prevPosX = this.posX;
+ this.prevPosY = this.posY;
+ this.prevPosZ = this.posZ;
+ this.particleMaxAge = age;
+ }
+
+ @Override
+ public void onUpdate() {
+ if (this.particleAge++ >= this.particleMaxAge) this.setDead();
+ }
+
+ @Override
+ public void renderParticle(
+ Tessellator p_70539_1_,
+ float p_70539_2_,
+ float p_70539_3_,
+ float p_70539_4_,
+ float p_70539_5_,
+ float p_70539_6_,
+ float p_70539_7_) {
+ Tessellator tessellator = Tessellator.instance;
+ GL11.glDisable(GL11.GL_CULL_FACE);
+ GL11.glDepthMask(false);
+ double f11 = this.prevPosX + (this.posX - this.prevPosX) * (double) p_70539_2_ - interpPosX;
+ double f12 = this.prevPosY + (this.posY - this.prevPosY) * (double) p_70539_2_ - interpPosY;
+ double f13 = this.prevPosZ + (this.posZ - this.prevPosZ) * (double) p_70539_2_ - interpPosZ;
+
+ RenderBlocks.getInstance().blockAccess = this.worldObj;
+ tessellator.setTranslation(f11 - this.posX, f12 - this.posY, f13 - this.posZ);
+ RenderBlocks.getInstance().setRenderFromInside(false);
+ RenderBlocks.getInstance()
+ .renderBlockUsingTexture(
+ GregTech_API.sBlockMetal5,
+ (int) this.posX,
+ (int) this.posY,
+ (int) this.posZ,
+ GregTech_API.sBlockMetal5.getIcon(0, 2));
+ tessellator.setTranslation(0d, 0d, 0d);
+
+ GL11.glEnable(GL11.GL_CULL_FACE);
+ GL11.glDepthMask(true);
+ }
+
+ @Override
+ public int getFXLayer() {
+ return 1;
+ }
+
+ @Override
+ public boolean shouldRenderInPass(int pass) {
+ return pass == 2;
+ }
+}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java
index 4ae8c10992..611c208456 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java
@@ -63,7 +63,8 @@ public class BW_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet>
new CircuitProgrammerPacket(),
new MetaBlockPacket(),
new OreDictCachePacket(),
- new ServerJoinedPackage()
+ new ServerJoinedPackage(),
+ new EICPacket()
};
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/EICPacket.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/EICPacket.java
new file mode 100644
index 0000000000..b62d880c4c
--- /dev/null
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/EICPacket.java
@@ -0,0 +1,56 @@
+package com.github.bartimaeusnek.bartworks.common.net;
+
+import com.github.bartimaeusnek.bartworks.API.SideReference;
+import com.github.bartimaeusnek.bartworks.common.tileentities.multis.GT_TileEntity_ElectricImplosionCompressor;
+import com.github.bartimaeusnek.bartworks.util.Coords;
+import com.google.common.io.ByteArrayDataInput;
+import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.net.GT_Packet_New;
+import io.netty.buffer.ByteBuf;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+
+public class EICPacket extends GT_Packet_New {
+ private Coords coords;
+ private boolean bool;
+
+ public EICPacket() {
+ super(true);
+ }
+
+ public EICPacket(Coords coords, boolean bool) {
+ super(false);
+ this.coords = coords;
+ this.bool = bool;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 5;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(coords.x);
+ aOut.writeInt(coords.y);
+ aOut.writeInt(coords.z);
+ aOut.writeBoolean(bool);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new EICPacket(new Coords(aData.readInt(), aData.readInt(), aData.readInt()), aData.readBoolean());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (SideReference.Side.Client) {
+ TileEntity te = aWorld.getTileEntity(coords.x, coords.y, coords.z);
+ if (!(te instanceof IGregTechTileEntity)) return;
+ IMetaTileEntity mte = ((IGregTechTileEntity) te).getMetaTileEntity();
+ if (!(mte instanceof GT_TileEntity_ElectricImplosionCompressor)) return;
+ if (bool && !((IGregTechTileEntity) te).hasMufflerUpgrade()) ((IGregTechTileEntity) te).addMufflerUpgrade();
+ }
+ }
+}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java
index c643b3c23d..c3ef47c98a 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java
@@ -29,7 +29,11 @@ import static gregtech.api.enums.GT_Values.V;
import static gregtech.api.enums.Textures.BlockIcons.*;
import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
+import com.github.bartimaeusnek.bartworks.MainMod;
+import com.github.bartimaeusnek.bartworks.client.renderer.BW_EICPistonVisualizer;
import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler;
+import com.github.bartimaeusnek.bartworks.common.net.EICPacket;
+import com.github.bartimaeusnek.bartworks.util.Coords;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
@@ -37,7 +41,10 @@ import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
+import gregtech.api.enums.SoundResource;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
@@ -49,6 +56,7 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import java.util.ArrayList;
+import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChunkCoordinates;
@@ -61,7 +69,7 @@ public class GT_TileEntity_ElectricImplosionCompressor
public static GT_Recipe.GT_Recipe_Map eicMap;
private static final boolean pistonEnabled = !ConfigHandler.disablePistonInEIC;
private Boolean piston = true;
- private static final String sound = GregTech_API.sSoundList.get(5);
+ private static final SoundResource sound = SoundResource.RANDOM_EXPLODE;
private final ArrayList<ChunkCoordinates> chunkCoordinates = new ArrayList<>(5);
public GT_TileEntity_ElectricImplosionCompressor(int aID, String aName, String aNameRegional) {
@@ -208,7 +216,6 @@ public class GT_TileEntity_ElectricImplosionCompressor
.addInputBus("Any bottom casing", 1)
.addInputHatch("Any bottom casing", 1)
.addOutputBus("Any bottom casing", 1)
- .addMaintenanceHatch("Any bottom casing", 1)
.addEnergyHatch("Bottom and top middle", 2)
.toolTipFinisher(MULTIBLOCK_ADDED_BY_BARTWORKS);
return tt;
@@ -283,13 +290,25 @@ public class GT_TileEntity_ElectricImplosionCompressor
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
- if (pistonEnabled && aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isActive() && aTick % 10 == 0)
- togglePiston(aBaseMetaTileEntity);
+ if (pistonEnabled && aBaseMetaTileEntity.isActive() && aTick % 20 == 0) {
+ if (aBaseMetaTileEntity.isClientSide()) animatePiston(aBaseMetaTileEntity);
+ else if (aBaseMetaTileEntity.hasMufflerUpgrade())
+ MainMod.BW_Network_instance.sendPacketToAllPlayersInRange(
+ aBaseMetaTileEntity.getWorld(),
+ new EICPacket(
+ new Coords(
+ aBaseMetaTileEntity.getXCoord(),
+ aBaseMetaTileEntity.getYCoord(),
+ aBaseMetaTileEntity.getZCoord()),
+ true),
+ aBaseMetaTileEntity.getXCoord(),
+ aBaseMetaTileEntity.getZCoord());
+ }
}
@Override
public void setExtendedFacing(ExtendedFacing newExtendedFacing) {
- super.setExtendedFacing(newExtendedFacing);
+ super.setExtendedFacing(newExtendedFacing); // Will call stopMachine
updateChunkCoordinates();
}
@@ -300,46 +319,52 @@ public class GT_TileEntity_ElectricImplosionCompressor
}
public void stopMachine() {
- if (pistonEnabled) this.resetPiston();
+ this.resetPiston();
super.stopMachine();
}
private void resetPiston() {
+ if (!pistonEnabled) return;
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();
if (!aBaseMetaTileEntity.isServerSide()) return;
- if (!this.piston && this.mMachine) {
+ if (!this.piston) {
chunkCoordinates.forEach(c ->
aBaseMetaTileEntity.getWorld().setBlock(c.posX, c.posY, c.posZ, GregTech_API.sBlockMetal5, 2, 3));
this.piston = !this.piston;
}
}
- private void togglePiston(IGregTechTileEntity aBaseMetaTileEntity) {
- if (aBaseMetaTileEntity.getWorld().isRemote) return;
+ private void activatePiston() {
+ if (!pistonEnabled) return;
+ IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();
+ if (!aBaseMetaTileEntity.isServerSide()) return;
if (this.piston) {
- for (ChunkCoordinates c : chunkCoordinates) {
- if (aBaseMetaTileEntity.getBlock(c.posX, c.posY, c.posZ) != GregTech_API.sBlockMetal5
- || aBaseMetaTileEntity.getMetaID(c.posX, c.posY, c.posZ) != 2) {
- this.explodeMultiblock();
- return;
- }
- aBaseMetaTileEntity.getWorld().setBlockToAir(c.posX, c.posY, c.posZ);
- }
-
- } else {
- chunkCoordinates.forEach(c ->
- aBaseMetaTileEntity.getWorld().setBlock(c.posX, c.posY, c.posZ, GregTech_API.sBlockMetal5, 2, 3));
- if (!getBaseMetaTileEntity().hasMufflerUpgrade())
- GT_Utility.sendSoundToPlayers(
- aBaseMetaTileEntity.getWorld(),
- sound,
- 1f,
- 1f,
- chunkCoordinates.get(0).posX,
- chunkCoordinates.get(0).posY,
- chunkCoordinates.get(0).posZ);
+ chunkCoordinates.forEach(c -> aBaseMetaTileEntity.getWorld().setBlockToAir(c.posX, c.posY, c.posZ));
+ this.piston = !this.piston;
}
- this.piston = !this.piston;
+ }
+
+ private void animatePiston(IGregTechTileEntity aBaseMetaTileEntity) {
+ if (!aBaseMetaTileEntity.getWorld().isRemote) return;
+
+ if (!getBaseMetaTileEntity().hasMufflerUpgrade())
+ GT_Utility.doSoundAtClient(
+ sound,
+ 10,
+ 1f,
+ 1f,
+ chunkCoordinates.get(0).posX,
+ chunkCoordinates.get(0).posY,
+ chunkCoordinates.get(0).posZ);
+ chunkCoordinates.forEach(c -> {
+ spawnVisualPistonBlock(aBaseMetaTileEntity.getWorld(), c.posX, c.posY, c.posZ, 10);
+ });
+ }
+
+ @SideOnly(Side.CLIENT)
+ private void spawnVisualPistonBlock(World world, int x, int y, int z, int age) {
+ BW_EICPistonVisualizer pistonVisualizer = new BW_EICPistonVisualizer(world, x, y, z, age);
+ Minecraft.getMinecraft().effectRenderer.addEffect(pistonVisualizer);
}
@Override
@@ -356,8 +381,15 @@ public class GT_TileEntity_ElectricImplosionCompressor
@Override
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack itemStack) {
- if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 6, 0)) return false;
- return this.mMaintenanceHatches.size() == 1 && this.mEnergyHatches.size() == 2;
+ boolean isOK = checkPiece(STRUCTURE_PIECE_MAIN, 1, 6, 0);
+ isOK = isOK && this.mMaintenanceHatches.size() == 1 && this.mEnergyHatches.size() == 2;
+ if (isOK) {
+ activatePiston();
+ return true;
+ } else {
+ resetPiston();
+ return false;
+ }
}
@Override