Move landmine radius render into its own renderer, get rid of BlockHighlightRenderHandler

This commit is contained in:
Vincent Lee committed 2020-07-15 12:13:11 -05:00
1 parent 17f1fd5977
commit 64274319b6
7 files changed
+171 -180

No files matched your search

@@ -1,168 +0,0 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.core.handler;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.*;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import vazkii.botania.api.subtile.RadiusDescriptor;
import vazkii.botania.api.subtile.TileEntitySpecialFlower;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.common.Botania;
import vazkii.botania.common.core.helper.PlayerHelper;
import vazkii.botania.common.entity.EntityMagicLandmine;
import vazkii.botania.common.item.ItemTwigWand;
import vazkii.botania.common.item.ModItems;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public final class BlockHighlightRenderHandler {
private BlockHighlightRenderHandler() {}
public static void onWorldRenderLast(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getInstance();
RayTraceResult pos = mc.objectMouseOver;
MatrixStack ms = event.getMatrixStack();
IRenderTypeBuffer.Impl buffers = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer());
/* Needed because RenderState.CullState doesn't actually disable if you pass false, it keeps the current state.
And we go into this method with cull enabled.
*/
RenderSystem.disableCull();
ms.push();
double offY = -1.0 / 16 + 0.005;
for (Entity e : mc.world.getAllEntities()) {
if (e instanceof EntityMagicLandmine) {
BlockPos bpos = e.func_233580_cy_();
AxisAlignedBB aabb = new AxisAlignedBB(bpos).offset(0, offY, 0).grow(2.5, 0, 2.5);
float gs = (float) (Math.sin(ClientTickHandler.total / 20) + 1) * 0.2F + 0.6F;
int r = (int) (105 * gs);
int g = (int) (25 * gs);
int b = (int) (145 * gs);
int color = r << 16 | g << 8 | b;
int alpha = 32;
if (e.ticksExisted < 8) {
alpha *= Math.min((e.ticksExisted + event.getPartialTicks()) / 8F, 1F);
} else if (e.ticksExisted > 47) {
alpha *= Math.min(1F - (e.ticksExisted - 47 + event.getPartialTicks()) / 8F, 1F);
}
renderRectangle(ms, buffers, aabb, false, color, (byte) alpha);
offY += 0.001;
}
}
ms.pop();
buffers.finish();
}
public static void renderRectangle(MatrixStack ms, IRenderTypeBuffer buffers, AxisAlignedBB aabb, boolean inner, @Nullable Integer color, byte alpha) {
ms.push();
ms.translate(aabb.minX, aabb.minY, aabb.minZ);
if (color == null) {
color = MathHelper.hsvToRGB(ClientTickHandler.ticksInGame % 200 / 200F, 0.6F, 1F);
}
int r = (color >> 16 & 0xFF);
int g = (color >> 8 & 0xFF);
int b = (color & 0xFF);
float f = 1F / 16F;
float x = (float) (aabb.maxX - aabb.minX - f);
float z = (float) (aabb.maxZ - aabb.minZ - f);
IVertexBuilder buffer = buffers.getBuffer(RenderHelper.RECTANGLE);
Matrix4f mat = ms.getLast().getMatrix();
buffer.pos(mat, x, f, f).color(r, g, b, alpha).endVertex();
buffer.pos(mat, f, f, f).color(r, g, b, alpha).endVertex();
buffer.pos(mat, f, f, z).color(r, g, b, alpha).endVertex();
buffer.pos(mat, x, f, z).color(r, g, b, alpha).endVertex();
if (inner) {
x += f;
z += f;
float f1 = f + f / 4F;
alpha *= 2;
buffer.pos(mat, x, f1, 0).color(r, g, b, alpha).endVertex();
buffer.pos(mat, 0, f1, 0).color(r, g, b, alpha).endVertex();
buffer.pos(mat, 0, f1, z).color(r, g, b, alpha).endVertex();
buffer.pos(mat, x, f1, z).color(r, g, b, alpha).endVertex();
}
ms.pop();
}
public static void renderCircle(MatrixStack ms, IRenderTypeBuffer buffers, BlockPos center, double radius) {
ms.push();
double x = center.getX() + 0.5;
double y = center.getY();
double z = center.getZ() + 0.5;
ms.translate(x, y, z);
int color = MathHelper.hsvToRGB(ClientTickHandler.ticksInGame % 200 / 200F, 0.6F, 1F);
int r = (color >> 16 & 0xFF);
int g = (color >> 8 & 0xFF);
int b = (color & 0xFF);
int alpha = 32;
float f = 1F / 16F;
int totalAngles = 360;
int drawAngles = 360;
int step = totalAngles / drawAngles;
radius -= f;
IVertexBuilder buffer = buffers.getBuffer(RenderHelper.CIRCLE);
Matrix4f mat = ms.getLast().getMatrix();
Runnable centerFunc = () -> buffer.pos(mat, 0, f, 0).color(r, g, b, alpha).endVertex();
List<Runnable> vertexFuncs = new ArrayList<>();
for (int i = 0; i < totalAngles + 1; i += step) {
double rad = (totalAngles - i) * Math.PI / 180.0;
float xp = (float) (Math.cos(rad) * radius);
float zp = (float) (Math.sin(rad) * radius);
vertexFuncs.add(() -> buffer.pos(mat, xp, f, zp).color(r, g, b, alpha).endVertex());
}
RenderHelper.triangleFan(centerFunc, vertexFuncs);
radius += f;
float f1 = f + f / 4F;
int alpha2 = 64;
centerFunc = () -> buffer.pos(mat, 0, f1, 0).color(r, g, b, alpha2).endVertex();
vertexFuncs.clear();
for (int i = 0; i < totalAngles + 1; i += step) {
double rad = (totalAngles - i) * Math.PI / 180.0;
float xp = (float) (Math.cos(rad) * radius);
float zp = (float) (Math.sin(rad) * radius);
vertexFuncs.add(() -> buffer.pos(mat, xp, f1, zp).color(r, g, b, alpha2).endVertex());
}
RenderHelper.triangleFan(centerFunc, vertexFuncs);
ms.pop();
}
}
@@ -93,7 +93,7 @@ public final class ModelHandler {
RenderingRegistry.registerEntityRenderingHandler(ModEntities.PLAYER_MOVER, RenderNoop::new);
RenderingRegistry.registerEntityRenderingHandler(ModEntities.SIGNAL_FLARE, RenderNoop::new);
RenderingRegistry.registerEntityRenderingHandler(ModEntities.FLAME_RING, RenderNoop::new);
RenderingRegistry.registerEntityRenderingHandler(ModEntities.MAGIC_LANDMINE, RenderNoop::new);
RenderingRegistry.registerEntityRenderingHandler(ModEntities.MAGIC_LANDMINE, RenderMagicLandmine::new);
RenderingRegistry.registerEntityRenderingHandler(ModEntities.MAGIC_MISSILE, RenderNoop::new);
RenderingRegistry.registerEntityRenderingHandler(ModEntities.FALLING_STAR, RenderNoop::new);
RenderingRegistry.registerEntityRenderingHandler(ModEntities.THROWN_ITEM, m -> new ItemRenderer(m, Minecraft.getInstance().getItemRenderer()));
@@ -50,6 +50,7 @@ import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.client.fx.FXLightning;
import vazkii.botania.client.fx.ModParticles;
import vazkii.botania.client.render.entity.RenderMagicLandmine;
import vazkii.botania.client.render.world.SkyblockRenderEvents;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
@@ -130,7 +131,7 @@ public class ClientProxy implements IProxy {
forgeBus.addListener(ClientTickHandler::renderTick);
forgeBus.addListener(BoundTileRenderer::onWorldRenderLast);
forgeBus.addListener(BossBarHandler::onBarRender);
forgeBus.addListener(BlockHighlightRenderHandler::onWorldRenderLast);
forgeBus.addListener(RenderMagicLandmine::onWorldRenderLast);
forgeBus.addListener(AstrolabePreviewHandler::onWorldRenderLast);
forgeBus.addListener(SkyblockRenderEvents::onRender);
forgeBus.addListener(ItemDodgeRing::onKeyDown);
@@ -0,0 +1,70 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.render.entity;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.render.tile.RenderTileSpecialFlower;
import vazkii.botania.common.entity.EntityMagicLandmine;
import javax.annotation.Nonnull;
public class RenderMagicLandmine extends EntityRenderer<EntityMagicLandmine> {
private static final double INITIAL_OFFSET = -1.0 / 16 + 0.005;
// Global y offset so that overlapping landmines do not Z-fight
public static double offY = INITIAL_OFFSET;
public RenderMagicLandmine(EntityRendererManager renderManager) {
super(renderManager);
}
public static void onWorldRenderLast(RenderWorldLastEvent evt) {
offY = INITIAL_OFFSET;
}
@Override
public void render(EntityMagicLandmine e, float entityYaw, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffers, int light) {
super.render(e, entityYaw, partialTicks, ms, buffers, light);
ms.push();
AxisAlignedBB aabb = e.getBoundingBox().offset(e.getPositionVec().scale(-1));
float gs = (float) (Math.sin(ClientTickHandler.total / 20) + 1) * 0.2F + 0.6F;
int r = (int) (105 * gs);
int g = (int) (25 * gs);
int b = (int) (145 * gs);
int color = r << 16 | g << 8 | b;
int alpha = 32;
if (e.ticksExisted < 8) {
alpha *= Math.min((e.ticksExisted + partialTicks) / 8F, 1F);
} else if (e.ticksExisted > 47) {
alpha *= Math.min(1F - (e.ticksExisted - 47 + partialTicks) / 8F, 1F);
}
RenderTileSpecialFlower.renderRectangle(ms, buffers, aabb, false, color, (byte) alpha);
offY += 0.001;
ms.pop();
}
@Nonnull
@Override
public ResourceLocation getEntityTexture(@Nonnull EntityMagicLandmine entity) {
return AtlasTexture.LOCATION_BLOCKS_TEXTURE;
}
}
@@ -9,6 +9,7 @@
package vazkii.botania.client.render.tile;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
@@ -17,18 +18,22 @@ import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.*;
import net.minecraft.util.math.vector.Matrix4f;
import vazkii.botania.api.subtile.RadiusDescriptor;
import vazkii.botania.api.subtile.TileEntitySpecialFlower;
import vazkii.botania.client.core.handler.BlockHighlightRenderHandler;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.common.core.helper.PlayerHelper;
import vazkii.botania.common.item.ItemTwigWand;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.equipment.bauble.ItemMonocle;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class RenderTileSpecialFlower extends TileEntityRenderer<TileEntity> {
@@ -58,9 +63,9 @@ public class RenderTileSpecialFlower extends TileEntityRenderer<TileEntity> {
ms.push();
ms.translate(-tile.getPos().getX(), -tile.getPos().getY(), -tile.getPos().getZ());
if (descriptor.isCircle()) {
BlockHighlightRenderHandler.renderCircle(ms, buffers, descriptor.getSubtileCoords(), descriptor.getCircleRadius());
renderCircle(ms, buffers, descriptor.getSubtileCoords(), descriptor.getCircleRadius());
} else {
BlockHighlightRenderHandler.renderRectangle(ms, buffers, descriptor.getAABB(), true, null, (byte) 32);
renderRectangle(ms, buffers, descriptor.getAABB(), true, null, (byte) 32);
}
ms.pop();
}
@@ -78,4 +83,88 @@ public class RenderTileSpecialFlower extends TileEntityRenderer<TileEntity> {
}
return false;
}
private static void renderCircle(MatrixStack ms, IRenderTypeBuffer buffers, BlockPos center, double radius) {
ms.push();
double x = center.getX() + 0.5;
double y = center.getY();
double z = center.getZ() + 0.5;
ms.translate(x, y, z);
int color = MathHelper.hsvToRGB(ClientTickHandler.ticksInGame % 200 / 200F, 0.6F, 1F);
int r = (color >> 16 & 0xFF);
int g = (color >> 8 & 0xFF);
int b = (color & 0xFF);
int alpha = 32;
float f = 1F / 16F;
int totalAngles = 360;
int drawAngles = 360;
int step = totalAngles / drawAngles;
radius -= f;
IVertexBuilder buffer = buffers.getBuffer(RenderHelper.CIRCLE);
Matrix4f mat = ms.getLast().getMatrix();
Runnable centerFunc = () -> buffer.pos(mat, 0, f, 0).color(r, g, b, alpha).endVertex();
List<Runnable> vertexFuncs = new ArrayList<>();
for (int i = 0; i < totalAngles + 1; i += step) {
double rad = (totalAngles - i) * Math.PI / 180.0;
float xp = (float) (Math.cos(rad) * radius);
float zp = (float) (Math.sin(rad) * radius);
vertexFuncs.add(() -> buffer.pos(mat, xp, f, zp).color(r, g, b, alpha).endVertex());
}
RenderHelper.triangleFan(centerFunc, vertexFuncs);
radius += f;
float f1 = f + f / 4F;
int alpha2 = 64;
centerFunc = () -> buffer.pos(mat, 0, f1, 0).color(r, g, b, alpha2).endVertex();
vertexFuncs.clear();
for (int i = 0; i < totalAngles + 1; i += step) {
double rad = (totalAngles - i) * Math.PI / 180.0;
float xp = (float) (Math.cos(rad) * radius);
float zp = (float) (Math.sin(rad) * radius);
vertexFuncs.add(() -> buffer.pos(mat, xp, f1, zp).color(r, g, b, alpha2).endVertex());
}
RenderHelper.triangleFan(centerFunc, vertexFuncs);
ms.pop();
}
public static void renderRectangle(MatrixStack ms, IRenderTypeBuffer buffers, AxisAlignedBB aabb, boolean inner, @Nullable Integer color, byte alpha) {
ms.push();
ms.translate(aabb.minX, aabb.minY, aabb.minZ);
if (color == null) {
color = MathHelper.hsvToRGB(ClientTickHandler.ticksInGame % 200 / 200F, 0.6F, 1F);
}
int r = (color >> 16 & 0xFF);
int g = (color >> 8 & 0xFF);
int b = (color & 0xFF);
float f = 1F / 16F;
float x = (float) (aabb.maxX - aabb.minX - f);
float z = (float) (aabb.maxZ - aabb.minZ - f);
IVertexBuilder buffer = buffers.getBuffer(RenderHelper.RECTANGLE);
Matrix4f mat = ms.getLast().getMatrix();
buffer.pos(mat, x, f, f).color(r, g, b, alpha).endVertex();
buffer.pos(mat, f, f, f).color(r, g, b, alpha).endVertex();
buffer.pos(mat, f, f, z).color(r, g, b, alpha).endVertex();
buffer.pos(mat, x, f, z).color(r, g, b, alpha).endVertex();
if (inner) {
x += f;
z += f;
float f1 = f + f / 4F;
alpha *= 2;
buffer.pos(mat, x, f1, 0).color(r, g, b, alpha).endVertex();
buffer.pos(mat, 0, f1, 0).color(r, g, b, alpha).endVertex();
buffer.pos(mat, 0, f1, z).color(r, g, b, alpha).endVertex();
buffer.pos(mat, x, f1, z).color(r, g, b, alpha).endVertex();
}
ms.pop();
}
}
@@ -41,8 +41,7 @@ public class EntityMagicLandmine extends Entity {
setMotion(Vector3d.ZERO);
super.tick();
float range = 2.5F;
float range = getWidth() / 2;
float r = 0.2F;
float g = 0F;
float b = 0.2F;
@@ -64,7 +63,7 @@ public class EntityMagicLandmine extends Entity {
}
if (!world.isRemote) {
List<PlayerEntity> players = world.getEntitiesWithinAABB(PlayerEntity.class, new AxisAlignedBB(getPosX() - range, getPosY() - range, getPosZ() - range, getPosX() + range, getPosY() + range, getPosZ() + range));
List<PlayerEntity> players = world.getEntitiesWithinAABB(PlayerEntity.class, getBoundingBox());
for (PlayerEntity player : players) {
player.attackEntityFrom(DamageSource.causeIndirectMagicDamage(this, summoner), 10);
player.addPotionEffect(new EffectInstance(Effects.BLINDNESS, 25, 0));
@@ -59,7 +59,7 @@ public final class ModEntities {
.setShouldReceiveVelocityUpdates(true)
.build("");
public static final EntityType<EntityMagicLandmine> MAGIC_LANDMINE = EntityType.Builder.<EntityMagicLandmine>create(EntityMagicLandmine::new, EntityClassification.MISC)
.size(0, 0)
.size(5F, 0.1F)
.setTrackingRange(128)
.setUpdateInterval(40)
.setShouldReceiveVelocityUpdates(false)