mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
please sir... no more rendering...
This commit is contained in:
parent
92b0fed4d5
commit
68528b651f
7 changed files with 144 additions and 6 deletions
|
@ -24,4 +24,7 @@ public interface IAtomicReconstructor extends IEnergyTile {
|
|||
Lens getLens();
|
||||
|
||||
Direction getOrientation();
|
||||
|
||||
void resetBeam(int maxAge);
|
||||
int getTTL();
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class ActuallyAdditionsClient {
|
|||
}
|
||||
|
||||
private static void setupSpecialRenders() {
|
||||
ClientRegistry.bindTileEntityRenderer(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getTileEntityType(), RenderReconstructorLens::new);
|
||||
ClientRegistry.bindTileEntityRenderer(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getTileEntityType(), ReconstructorRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(ActuallyBlocks.DISPLAY_STAND.getTileEntityType(), RenderDisplayStand::new);
|
||||
ClientRegistry.bindTileEntityRenderer(ActuallyBlocks.EMPOWERER.getTileEntityType(), RenderEmpowerer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(ActuallyBlocks.BATTERY_BOX.getTileEntityType(), RenderBatteryBox::new);
|
||||
|
|
|
@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.blocks.render;
|
|||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import de.ellpeck.actuallyadditions.api.lens.ILensItem;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
|
@ -20,18 +21,25 @@ import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.vector.Quaternion;
|
||||
|
||||
public class RenderReconstructorLens extends TileEntityRenderer<TileEntityAtomicReconstructor> {
|
||||
public class ReconstructorRenderer extends TileEntityRenderer<TileEntityAtomicReconstructor> {
|
||||
|
||||
public RenderReconstructorLens(TileEntityRendererDispatcher rendererDispatcherIn) {
|
||||
public ReconstructorRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
|
||||
super(rendererDispatcherIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(TileEntityAtomicReconstructor tile, float partialTicks, MatrixStack matrices, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay) {
|
||||
ItemStack stack = tile.inv.getStackInSlot(0);
|
||||
//default color 0x1b6dff
|
||||
Direction direction = tile.getOrientation();
|
||||
float rot = 360.0f - direction.getOpposite().toYRot(); //Sigh...
|
||||
|
||||
AssetUtil.renderLaser(matrices, buffer, 0,0,0, rot, 0, 5, 0, 0x1b6dff, 0.8f * tile.getProgress(), 0.2f);
|
||||
tile.decTTL();
|
||||
if (!StackUtil.isValid(stack) || !(stack.getItem() instanceof ILensItem)) {
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package de.ellpeck.actuallyadditions.mod.blocks.render;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.renderer.RenderState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class RenderTypes extends RenderType {
|
||||
public RenderTypes(String NameIn, VertexFormat FormatIn, int GLMode, int BufferSize, boolean useDelegate, boolean needsSorting, Runnable setupTask, Runnable ClearTask) {
|
||||
super(NameIn, FormatIn, GLMode, BufferSize, useDelegate, needsSorting, setupTask, ClearTask);
|
||||
}
|
||||
|
||||
/* public static final RenderType LASER = create("actuallyadditions:laser", DefaultVertexFormats.POSITION_COLOR,
|
||||
GL11.GL_QUADS, 256, false, true,
|
||||
RenderType.State.builder()
|
||||
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
|
||||
.setTextureState(NO_TEXTURE)
|
||||
.setOutputState(RenderType.OUTLINE_TARGET)
|
||||
.createCompositeState(true));*/
|
||||
public static final RenderType LASER = create("actuallyadditions:laser", DefaultVertexFormats.POSITION_COLOR_LIGHTMAP,
|
||||
GL11.GL_QUADS, 256, false, true,
|
||||
RenderType.State.builder()
|
||||
.setTransparencyState(ADDITIVE_TRANSPARENCY)
|
||||
.setTextureState(NO_TEXTURE)
|
||||
.setOutputState(RenderType.TRANSLUCENT_TARGET)
|
||||
.setLightmapState(RenderState.LIGHTMAP)
|
||||
.setAlphaState(RenderState.DEFAULT_ALPHA)
|
||||
.setCullState(RenderState.NO_CULL)
|
||||
.createCompositeState(true));
|
||||
}
|
|
@ -239,7 +239,7 @@ public class MethodHandler implements IMethodHandler {
|
|||
BlockPos hitBlock = tile.getPosition().relative(sideToManipulate, i + 1);
|
||||
|
||||
if (currentLens.invoke(tile.getWorldObject().getBlockState(hitBlock), hitBlock, tile) || i >= distance - 1) {
|
||||
TileEntityAtomicReconstructor.shootLaser(tile.getWorldObject(), tile.getX(), tile.getY(), tile.getZ(), hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens);
|
||||
TileEntityAtomicReconstructor.shootLaser(tile, tile.getWorldObject(), tile.getX(), tile.getY(), tile.getZ(), hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
|
|||
public int counter;
|
||||
private int currentTime;
|
||||
private int oldEnergy;
|
||||
private int ttl = 0;
|
||||
private int maxAge = 0;
|
||||
|
||||
public TileEntityAtomicReconstructor() {
|
||||
super(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.getTileEntityType(), 1);
|
||||
|
@ -52,11 +54,34 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
|
|||
this.lazyEnergy = LazyOptional.of(() -> this.storage);
|
||||
}
|
||||
|
||||
public static void shootLaser(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens) {
|
||||
public static void shootLaser(IAtomicReconstructor tile, World world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens) {
|
||||
world.playSound(null, startX, startY, startZ, SoundHandler.reconstructor, SoundCategory.BLOCKS, 0.35F, 1.0F);
|
||||
AssetUtil.spawnLaserWithTimeServer(world, startX, startY, startZ, endX, endY, endZ, currentLens.getColor(), 25, 0, 0.2F, 0.8F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTTL() {
|
||||
return this.ttl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBeam(int maxAge) {
|
||||
this.ttl = maxAge;
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
|
||||
public float getProgress(){
|
||||
if (maxAge > 0)
|
||||
return (float)ttl / (float)maxAge;
|
||||
else
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public void decTTL() {
|
||||
if (this.ttl > 0)
|
||||
this.ttl--;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
|
||||
super.writeSyncableNBT(compound, type);
|
||||
|
|
|
@ -12,23 +12,31 @@ package de.ellpeck.actuallyadditions.mod.util;
|
|||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderTypes;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
|
||||
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.particles.IParticleData;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
@ -226,11 +234,72 @@ public final class AssetUtil {
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
public static void spawnLaserWithTimeClient(double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
TileEntity tile = mc.level.getBlockEntity(new BlockPos(startX, startY, startZ));
|
||||
if(tile instanceof TileEntityAtomicReconstructor)
|
||||
((TileEntityAtomicReconstructor) tile).resetBeam(maxAge);
|
||||
|
||||
if (mc.player.distanceToSqr(startX, startY, startZ) <= 64 || mc.player.distanceToSqr(endX, endY, endZ) <= 64) {
|
||||
|
||||
/* if (mc.player.distanceToSqr(startX, startY, startZ) <= 64 || mc.player.distanceToSqr(endX, endY, endZ) <= 64) {
|
||||
Particle fx = new ParticleBeam(mc.level, startX, startY, startZ, endX, endY, endZ, color, maxAge, rotationTime, size, alpha);
|
||||
mc.level.addParticle((IParticleData) fx, startX, startY, startZ, 0, 0, 0);
|
||||
}*/
|
||||
}
|
||||
/* @OnlyIn(Dist.CLIENT)
|
||||
public static void renderLaser(MatrixStack matrixStack, IRenderTypeBuffer buffer, float x, float y, float z, float tx, float ty, float tz, float rotation, int color, float beamWidth) {
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static void renderLaser(MatrixStack matrixStack, IRenderTypeBuffer buffer, float offX, float offY, float offZ, float yaw, float pitch, float length, float rotationTime, int color, float alpha, float beamWidth) {
|
||||
World world = Minecraft.getInstance().level;
|
||||
int r = (color >> 16) & 0xFF;
|
||||
int g = (color >> 8) & 0xFF;
|
||||
int b = color & 0xFF;
|
||||
int a = (int) (alpha * 255);
|
||||
|
||||
int lightmap = LightTexture.pack(MAX_LIGHT_X, MAX_LIGHT_Y);
|
||||
|
||||
float roll = rotationTime > 0.0f ? 360.0f * (world.getGameTime() % rotationTime / rotationTime) : 0.0f;
|
||||
|
||||
IVertexBuilder builder = buffer.getBuffer(RenderTypes.LASER);
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0.5f, 0.5f, 0.5f);
|
||||
matrixStack.translate(offX, offY, offZ);
|
||||
|
||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(yaw));
|
||||
matrixStack.mulPose(Vector3f.XP.rotationDegrees(pitch));
|
||||
matrixStack.mulPose(Vector3f.ZP.rotationDegrees(roll));
|
||||
|
||||
Matrix4f matrix = matrixStack.last().pose();
|
||||
|
||||
//Draw laser tube faces
|
||||
for (int i = 0; i < 4; i++) {
|
||||
float width = beamWidth * (i / 4.0f);
|
||||
//top
|
||||
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
//bottom
|
||||
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
//left
|
||||
builder.vertex(matrix, -width, width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, -width, -width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, -width, -width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, -width, width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
//right
|
||||
builder.vertex(matrix, width, width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, width, -width, 0.0f).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, width, -width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
builder.vertex(matrix, width, width, -length).color(r, g, b, a).uv2(lightmap).endVertex();
|
||||
}
|
||||
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
//Thanks to feldim2425 for this.
|
||||
|
|
Loading…
Reference in a new issue