mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58:34 +01:00
Added proper laser rendering instead of the particles
This commit is contained in:
parent
2e96e00182
commit
9337a6e6aa
4 changed files with 199 additions and 5 deletions
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* This file ("RenderLaserRelay.java") is part of the Actually Additions mod for Minecraft.
|
||||||
|
* It is created and owned by Ellpeck and distributed
|
||||||
|
* under the Actually Additions License to be found at
|
||||||
|
* http://ellpeck.de/actaddlicense
|
||||||
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||||
|
*
|
||||||
|
* © 2015-2016 Ellpeck
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.ellpeck.actuallyadditions.mod.blocks.render;
|
||||||
|
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench.WrenchMode;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||||
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class RenderLaserRelay extends TileEntitySpecialRenderer{
|
||||||
|
|
||||||
|
private static final float[] COLOR = new float[]{1F, 0F, 0F};
|
||||||
|
private static final float[] COLOR_ITEM = new float[]{43F/255F, 158F/255F, 39/255F};
|
||||||
|
private static final float[] COLOR_FLUIDS = new float[]{139F/255F, 94F/255F, 1F};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float par5, int par6){
|
||||||
|
if(tile instanceof TileEntityLaserRelay){
|
||||||
|
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
|
||||||
|
|
||||||
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||||
|
if(player != null){
|
||||||
|
PlayerSave data = PlayerData.getDataFromPlayer(player);
|
||||||
|
WrenchMode mode = WrenchMode.values()[data.theCompound.getInteger("LaserWrenchMode")];
|
||||||
|
if(mode != WrenchMode.NO_PARTICLES){
|
||||||
|
ItemStack stack = player.getHeldItemMainhand();
|
||||||
|
if(mode == WrenchMode.ALWAYS_PARTICLES || (stack != null && stack.getItem() instanceof ItemLaserWrench)){
|
||||||
|
ConcurrentSet<IConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(tile.getPos(), tile.getWorld());
|
||||||
|
if(connections != null && !connections.isEmpty()){
|
||||||
|
for(IConnectionPair pair : connections){
|
||||||
|
if(!pair.doesSuppressRender() && tile.getPos().equals(pair.getPositions()[0])){
|
||||||
|
BlockPos first = tile.getPos();
|
||||||
|
BlockPos second = pair.getPositions()[1];
|
||||||
|
float[] color = relay.type == LaserType.ITEM ? COLOR_ITEM : (relay.type == LaserType.FLUID ? COLOR_FLUIDS : COLOR);
|
||||||
|
|
||||||
|
AssetUtil.renderLaser(first.getX()+0.5, first.getY()+0.5, first.getZ()+0.5, second.getX()+0.5, second.getY()+0.5, second.getZ()+0.5, 120, 0.5F, 0.05, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||||
import net.minecraft.client.resources.IResourceManager;
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||||
|
@ -153,6 +154,14 @@ public class ClientProxy implements IProxy{
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDisplayStand.class, new RenderDisplayStand());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDisplayStand.class, new RenderDisplayStand());
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEmpowerer.class, new RenderEmpowerer());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEmpowerer.class, new RenderEmpowerer());
|
||||||
|
|
||||||
|
TileEntitySpecialRenderer laser = new RenderLaserRelay();
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayEnergy.class, laser);
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayEnergyAdvanced.class, laser);
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayEnergyExtreme.class, laser);
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayItem.class, laser);
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayItemWhitelist.class, laser);
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayFluids.class, laser);
|
||||||
|
|
||||||
//VillagerRegistry.INSTANCE().registerVillagerSkin(ConfigIntValues.JAM_VILLAGER_ID.getValue(), new ResourceLocation(ModUtil.MOD_ID, "textures/entity/villager/jamVillager.png"));
|
//VillagerRegistry.INSTANCE().registerVillagerSkin(ConfigIntValues.JAM_VILLAGER_ID.getValue(), new ResourceLocation(ModUtil.MOD_ID, "textures/entity/villager/jamVillager.png"));
|
||||||
|
|
||||||
for(Item item : COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING){
|
for(Item item : COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING){
|
||||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@ -35,9 +36,6 @@ import java.util.Set;
|
||||||
public abstract class TileEntityLaserRelay extends TileEntityBase{
|
public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
|
|
||||||
public static final int MAX_DISTANCE = 15;
|
public static final int MAX_DISTANCE = 15;
|
||||||
private static final float[] COLOR = new float[]{1F, 0F, 0F};
|
|
||||||
private static final float[] COLOR_ITEM = new float[]{43F/255F, 158F/255F, 39/255F};
|
|
||||||
private static final float[] COLOR_FLUIDS = new float[]{139F/255F, 94F/255F, 1F};
|
|
||||||
|
|
||||||
public final LaserType type;
|
public final LaserType type;
|
||||||
|
|
||||||
|
@ -86,7 +84,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*@Override
|
||||||
public void updateEntity(){
|
public void updateEntity(){
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(this.worldObj.isRemote){
|
if(this.worldObj.isRemote){
|
||||||
|
@ -116,7 +114,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate(){
|
public void invalidate(){
|
||||||
|
@ -139,4 +137,9 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
|
|
||||||
super.validate();
|
super.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AxisAlignedBB getRenderBoundingBox(){
|
||||||
|
return INFINITE_EXTENT_AABB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.client.renderer.RenderHelper;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.VertexBuffer;
|
import net.minecraft.client.renderer.VertexBuffer;
|
||||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
||||||
|
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -202,4 +203,119 @@ public final class AssetUtil{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Thanks to feldim2425 for this.
|
||||||
|
//I can't do rendering code. Ever.
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public static void renderLaser(double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ, int rotationTime, float alpha, double beamWidth, float[] color){
|
||||||
|
Tessellator tessy = Tessellator.getInstance();
|
||||||
|
VertexBuffer render = tessy.getBuffer();
|
||||||
|
World world = Minecraft.getMinecraft().theWorld;
|
||||||
|
|
||||||
|
GlStateManager.disableFog();
|
||||||
|
|
||||||
|
float r = color[0];
|
||||||
|
float g = color[1];
|
||||||
|
float b = color[2];
|
||||||
|
|
||||||
|
Vec3d vec1 = new Vec3d(firstX, firstY, firstZ);
|
||||||
|
Vec3d vec2 = new Vec3d(secondX, secondY, secondZ);
|
||||||
|
Vec3d combinedVec = vec2.subtract(vec1);
|
||||||
|
|
||||||
|
double rot = rotationTime > 0 ? (360F*(((float)world.getTotalWorldTime()%(float)rotationTime)/(float)rotationTime)) : 0;
|
||||||
|
double pitch = Math.atan2(combinedVec.yCoord, Math.sqrt(combinedVec.xCoord*combinedVec.xCoord+combinedVec.zCoord*combinedVec.zCoord));
|
||||||
|
double yaw = Math.atan2(-combinedVec.zCoord, combinedVec.xCoord);
|
||||||
|
|
||||||
|
double length = combinedVec.lengthVector();
|
||||||
|
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
|
||||||
|
GlStateManager.disableLighting();
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||||
|
GlStateManager.depthMask(false);
|
||||||
|
GlStateManager.translate(firstX-TileEntityRendererDispatcher.staticPlayerX, firstY-TileEntityRendererDispatcher.staticPlayerY, firstZ-TileEntityRendererDispatcher.staticPlayerZ);
|
||||||
|
GlStateManager.rotate((float)(180*yaw/Math.PI), 0, 1, 0);
|
||||||
|
GlStateManager.rotate((float)(180*pitch/Math.PI), 0, 0, 1);
|
||||||
|
GlStateManager.rotate((float)rot, 1, 0, 0);
|
||||||
|
|
||||||
|
/*if(r != r2 || g != g2 || b != b2){
|
||||||
|
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
|
Minecraft.getMinecraft().renderEngine.bindTexture(ClientUtil.LIGHT_BEAM_GRADIENT);
|
||||||
|
|
||||||
|
render.pos(length, -beamWidth, beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, beamWidth, beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, -beamWidth, beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(length, beamWidth, beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, beamWidth, -beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, -beamWidth, -beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, -beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, -beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, beamWidth, -beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(length, -beamWidth, -beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, -beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, -beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, beamWidth, beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, beamWidth, -beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, -beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, beamWidth, beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(length, beamWidth, -beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, -beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, -beamWidth, -beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, -beamWidth, beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, beamWidth).tex(1, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, -beamWidth).tex(1, 0).color(r, g, b, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, -beamWidth, -beamWidth).tex(1, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(length, -beamWidth, beamWidth).tex(1, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, beamWidth).tex(0, 1).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, -beamWidth).tex(0, 0).color(r2, g2, b2, alpha).endVertex();
|
||||||
|
tessy.draw();
|
||||||
|
}
|
||||||
|
else{*/
|
||||||
|
GlStateManager.disableTexture2D();
|
||||||
|
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
|
||||||
|
render.pos(length, beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, -beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, -beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
|
||||||
|
render.pos(length, -beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(0, -beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
render.pos(length, -beamWidth, -beamWidth).color(r, g, b, alpha).endVertex();
|
||||||
|
tessy.draw();
|
||||||
|
|
||||||
|
GlStateManager.enableTexture2D();
|
||||||
|
//}
|
||||||
|
|
||||||
|
GlStateManager.disableBlend();
|
||||||
|
GlStateManager.enableLighting();
|
||||||
|
GlStateManager.depthMask(true);
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
|
||||||
|
GlStateManager.enableFog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue