Added a render for the Marx generator
This commit is contained in:
parent
5a80b2626b
commit
d4bed0d324
|
@ -22,9 +22,14 @@ import blusunrize.immersiveengineering.api.IEProperties;
|
|||
import blusunrize.immersiveengineering.common.IEContent;
|
||||
import blusunrize.immersiveengineering.common.blocks.BlockTypes_MetalsIE;
|
||||
import blusunrize.immersiveengineering.common.blocks.metal.*;
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import ic2.api.item.IC2Items;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.ISyncReceiver;
|
||||
import malte0811.industrialWires.blocks.IWProperties;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWMultiblock;
|
||||
import malte0811.industrialWires.client.render.TileRenderMarx;
|
||||
import malte0811.industrialWires.network.MessageTileSyncIW;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -35,16 +40,27 @@ import net.minecraft.util.ITickable;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable {
|
||||
public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable, ISyncReceiver {
|
||||
// TODO do I want to do this?
|
||||
public static final Set<TileEntityMarx> dischargingMarxes = new HashSet<>();
|
||||
|
||||
private static final String TYPE = "type";
|
||||
private static final String STAGES = "stages";
|
||||
|
||||
public IWProperties.MarxType type = IWProperties.MarxType.NO_MODEL;
|
||||
int stageCount = 0;
|
||||
public int stageCount = 0;
|
||||
public FiringState state = FiringState.CHARGING;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public TileRenderMarx.Discharge dischargeData;
|
||||
|
||||
public TileEntityMarx(EnumFacing facing, IWProperties.MarxType type, boolean mirrored) {
|
||||
this.facing = facing;
|
||||
|
@ -136,8 +152,25 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable
|
|||
|
||||
@Override
|
||||
public void update() {
|
||||
if (state==FiringState.FIRE) {
|
||||
state = FiringState.CHARGING;
|
||||
if (world.isRemote) {
|
||||
dischargingMarxes.remove(this);
|
||||
}
|
||||
} else if (state==FiringState.NEXT_TICK) {
|
||||
state = FiringState.FIRE;
|
||||
if (!world.isRemote) {
|
||||
//TODO server-side effects of Marx discharges (damage (electric+sound), block processing, reset cap voltages, more?
|
||||
} else {
|
||||
dischargingMarxes.add(this);//TODO deal with breaking during discharges
|
||||
}
|
||||
}
|
||||
if (!world.isRemote&&type== IWProperties.MarxType.BOTTOM) {
|
||||
//TODO do stuff and things
|
||||
if (world.getTotalWorldTime()%40==0) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setFloat("energy", stageCount*9*9);
|
||||
IndustrialWires.packetHandler.sendToAll(new MessageTileSyncIW(this, nbt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,4 +178,65 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable
|
|||
public Vec3i getSize() {
|
||||
return new Vec3i(stageCount, 8, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSync(NBTTagCompound nbt) {
|
||||
state = FiringState.NEXT_TICK;
|
||||
if (true||dischargeData==null) {
|
||||
dischargeData = new TileRenderMarx.Discharge();
|
||||
int count = 1;
|
||||
while (count<stageCount) {
|
||||
count <<= 1;
|
||||
}
|
||||
dischargeData.vertices = new Vector3f[2*count];
|
||||
for (int i = 0;i<dischargeData.vertices.length;i++) {
|
||||
dischargeData.vertices[i] = new Vector3f();
|
||||
}
|
||||
dischargeData.vertices[dischargeData.vertices.length-1] = new Vector3f(0, stageCount-1.9375F, 0);
|
||||
}
|
||||
dischargeData.energy = nbt.getFloat("energy");
|
||||
genMarxPoint(0, dischargeData.vertices.length-1);
|
||||
}
|
||||
// Meant to be const
|
||||
private final Vector3f up = new Vector3f(0, 1, 0);
|
||||
private final Vector3f side = new Vector3f(0, 0, 1);
|
||||
//used for calculation buffering
|
||||
private final Vector3f diff = new Vector3f();
|
||||
private final Vector3f center = new Vector3f();
|
||||
private final Vector3f v0 = new Vector3f();
|
||||
private final Matrix4 transform = new Matrix4();
|
||||
/**
|
||||
* @param min The first point of the discharge section to be generated. has to be pre-populated
|
||||
* @param max The last point of the discharge section to be generated. has to be pre-populated
|
||||
*/
|
||||
private void genMarxPoint(int min, int max) {
|
||||
int toGenerate = (min+max)/2;
|
||||
Vector3f.sub(dischargeData.vertices[max], dischargeData.vertices[min], diff);
|
||||
Vector3f.cross(diff, side, v0);
|
||||
transform.setIdentity();
|
||||
double noise = Math.sqrt(stageCount)*world.rand.nextDouble()*1/(1+Math.abs(stageCount/2.0-toGenerate))*.5;
|
||||
if ((max-min)%2==1) {
|
||||
noise *= (toGenerate-min)/(double)(max-min);
|
||||
}
|
||||
v0.scale((float) (noise/v0.length()));
|
||||
diff.scale(1/diff.length());
|
||||
transform.rotate(Math.PI*2*world.rand.nextDouble(), diff.x, diff.y, diff.z);
|
||||
Vector3f.add(dischargeData.vertices[max], dischargeData.vertices[min], center);
|
||||
center.scale(.5F);
|
||||
dischargeData.vertices[toGenerate] = transform.apply(v0);
|
||||
Vector3f.add(dischargeData.vertices[toGenerate], center, dischargeData.vertices[toGenerate]);
|
||||
|
||||
if (toGenerate-min>1) {
|
||||
genMarxPoint(min, toGenerate);
|
||||
}
|
||||
if (max-toGenerate>1) {
|
||||
genMarxPoint(toGenerate, max);
|
||||
}
|
||||
}
|
||||
|
||||
public enum FiringState {
|
||||
CHARGING,
|
||||
NEXT_TICK,
|
||||
FIRE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,14 @@ import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
|
|||
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
|
||||
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
|
||||
import malte0811.industrialWires.blocks.hv.TileEntityJacobsLadder;
|
||||
import malte0811.industrialWires.blocks.hv.TileEntityMarx;
|
||||
import malte0811.industrialWires.client.gui.GuiPanelComponent;
|
||||
import malte0811.industrialWires.client.gui.GuiPanelCreator;
|
||||
import malte0811.industrialWires.client.gui.GuiRSPanelConn;
|
||||
import malte0811.industrialWires.client.gui.GuiRenameKey;
|
||||
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
|
||||
import malte0811.industrialWires.client.render.TileRenderJacobsLadder;
|
||||
import malte0811.industrialWires.client.render.TileRenderMarx;
|
||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||
import malte0811.industrialWires.items.ItemIC2Coil;
|
||||
import malte0811.industrialWires.items.ItemKey;
|
||||
|
@ -148,6 +150,7 @@ public class ClientProxy extends CommonProxy {
|
|||
ModelLoaderRegistry.registerLoader(new PanelModelLoader());
|
||||
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityJacobsLadder.class, new TileRenderJacobsLadder());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMarx.class, new TileRenderMarx());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,9 +45,7 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
|
|||
GlStateManager.disableLighting();
|
||||
GlStateManager.shadeModel(GL11.GL_SMOOTH);
|
||||
|
||||
float oldBX = OpenGlHelper.lastBrightnessX;
|
||||
float oldBY = OpenGlHelper.lastBrightnessY;
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 238, 238);
|
||||
setLightmapDisabled(true);
|
||||
GlStateManager.color(1, .85F, 1, 1);
|
||||
Vec3d[] controls = new Vec3d[tile.size.arcPoints];
|
||||
for (int i = 0; i < tile.size.arcPoints; i++) {
|
||||
|
@ -70,7 +68,7 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
|
|||
tes.draw();*/
|
||||
//END OF DEBUG CODE
|
||||
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, oldBX, oldBY);
|
||||
setLightmapDisabled(false);
|
||||
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.enableLighting();
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016-2017 malte0811
|
||||
*
|
||||
* Industrial Wires is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Industrial Wires is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package malte0811.industrialWires.client.render;
|
||||
|
||||
import malte0811.industrialWires.blocks.IWProperties;
|
||||
import malte0811.industrialWires.blocks.hv.TileEntityMarx;
|
||||
import malte0811.industrialWires.util.MiscUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
public class TileRenderMarx extends TileEntitySpecialRenderer<TileEntityMarx> {
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntityMarx te, double x, double y, double z, float partialTicks, int destroyStage) {
|
||||
if (te.type== IWProperties.MarxType.BOTTOM&&te.state== TileEntityMarx.FiringState.FIRE) {
|
||||
prepare(x, y, z, te);
|
||||
Tessellator tes = Tessellator.getInstance();
|
||||
VertexBuffer vb = tes.getBuffer();
|
||||
|
||||
drawDischarge(te.dischargeData, vb, tes);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.pushMatrix();
|
||||
Vec3i offset = MiscUtils.offset(BlockPos.ORIGIN, te.facing, te.mirrored, 1, 1, 0);
|
||||
GlStateManager.translate(x+offset.getX(), y+offset.getY()+.75, z+offset.getZ());
|
||||
Vec3i facing = te.facing.getDirectionVec();
|
||||
final float pos = .6875F;
|
||||
GlStateManager.translate(-facing.getX()*pos, 0, -facing.getZ()*pos);
|
||||
//draw firing spark gaps
|
||||
for (int i = 0;i<te.stageCount-1;i++) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(0, i, 0);
|
||||
GlStateManager.rotate(-45, facing.getX(), facing.getY(), facing.getZ());
|
||||
GlStateManager.rotate(-Minecraft.getMinecraft().player.rotationYaw+180, 0, 1, 0);
|
||||
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
|
||||
drawDischargeSection(new Vector3f(0, -.2F, 0), new Vector3f(0, .2F, 0), .25F, vb);
|
||||
tes.draw();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
cleanUp();
|
||||
}
|
||||
}
|
||||
private void prepare(double x, double y, double z, TileEntityMarx te) {
|
||||
setLightmapDisabled(true);
|
||||
GlStateManager.pushMatrix();
|
||||
Vec3i offset = MiscUtils.offset(BlockPos.ORIGIN, te.facing, te.mirrored, 1, 4, 1);
|
||||
GlStateManager.translate(x+offset.getX()+.5, y+offset.getY(), z+offset.getZ()+.5);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.shadeModel(GL11.GL_SMOOTH);
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GlStateManager.rotate(-Minecraft.getMinecraft().player.rotationYaw+180, 0, 1, 0);
|
||||
}
|
||||
private void cleanUp() {
|
||||
setLightmapDisabled(false);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
private static final float[] WHITE = {1, 1, 1, 1};
|
||||
private static final float[] WHITE_TRANSPARENT = {1, 1, 1, 0};
|
||||
private void drawDischarge(Discharge d, VertexBuffer vb, Tessellator tes) {
|
||||
if (d!=null&&d.vertices!=null) {
|
||||
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
|
||||
for (int i = 0;i<d.vertices.length-1;i++) {
|
||||
drawDischargeSection(d.vertices[i], d.vertices[i+1], d.diameter, vb);
|
||||
}
|
||||
tes.draw();
|
||||
}
|
||||
}
|
||||
private void drawDischargeSection(Vector3f start, Vector3f end, float diameter, VertexBuffer vb) {
|
||||
drawPart(start, end, diameter/3, diameter/3, WHITE_TRANSPARENT, WHITE, vb);
|
||||
drawPart(start, end, 0, diameter/3, WHITE, WHITE, vb);
|
||||
drawPart(start, end, -diameter/3, diameter/3, WHITE, WHITE_TRANSPARENT, vb);
|
||||
}
|
||||
private void drawPart(Vector3f start, Vector3f end, float offset, float width, float[] color1, float[] color2, VertexBuffer vb) {
|
||||
vb.setTranslation(-offset-width/2, 0, 0);
|
||||
vb.pos(start.x, start.y, start.z).color(color1[0], color1[1], color1[2], color1[3]).endVertex();
|
||||
vb.pos(start.x+width, start.y, start.z).color(color2[0], color2[1], color2[2], color2[3]).endVertex();
|
||||
vb.pos(end.x+width, end.y, end.z).color(color2[0], color2[1], color2[2], color2[3]).endVertex();
|
||||
vb.pos(end.x, end.y, end.z).color(color1[0], color1[1], color1[2], color1[3]).endVertex();
|
||||
vb.setTranslation(0, 0, 0);
|
||||
}
|
||||
public static final class Discharge {
|
||||
public float energy;
|
||||
public Vector3f[] vertices;
|
||||
public float diameter = .25F;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ import blusunrize.immersiveengineering.common.blocks.TileEntityIEBase;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.ISyncReceiver;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -36,7 +37,7 @@ public class MessageTileSyncIW implements IMessage {
|
|||
BlockPos pos;
|
||||
NBTTagCompound nbt;
|
||||
|
||||
public MessageTileSyncIW(TileEntityIEBase tile, NBTTagCompound nbt) {
|
||||
public MessageTileSyncIW(TileEntity tile, NBTTagCompound nbt) {
|
||||
this.pos = tile.getPos();
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue