Skip to content

Commit

Permalink
Add render for Drops Teleport - for #196
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Oct 19, 2024
1 parent 7974e4a commit f201408
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

import com.direwolf20.justdirethings.client.renderactions.MiscRenders;
import com.direwolf20.justdirethings.client.renderactions.ThingFinder;
import com.direwolf20.justdirethings.client.renderers.OurRenderTypes;
import com.direwolf20.justdirethings.client.renderers.RenderHelpers;
import com.direwolf20.justdirethings.common.items.interfaces.Ability;
import com.direwolf20.justdirethings.common.items.interfaces.ToggleableTool;
import com.direwolf20.justdirethings.util.NBTHelpers;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
import org.joml.Matrix4f;

import java.awt.*;

public class RenderLevelLast {
@SubscribeEvent
Expand All @@ -27,11 +38,50 @@ static void renderWorldLastEvent(RenderLevelStageEvent evt) {
ThingFinder.render(evt, player, heldItemMain);
if (toggleableTool.canUseAbilityAndDurability(heldItemMain, Ability.VOIDSHIFT) && ToggleableTool.getCustomSetting(heldItemMain, Ability.VOIDSHIFT.getName()) == 0)
MiscRenders.renderTransparentPlayer(evt, player, heldItemMain);
if (toggleableTool.canUseAbility(heldItemMain, Ability.DROPTELEPORT) && ToggleableTool.getCustomSetting(heldItemMain, Ability.DROPTELEPORT.getName()) == 0) {
NBTHelpers.BoundInventory boundInventory = ToggleableTool.getBoundInventory(heldItemMain);
if (boundInventory != null && player.level().dimension().equals(boundInventory.globalPos().dimension())) {
renderSelectedBlock(evt, boundInventory.globalPos().pos(), boundInventory.direction());
}
}
}
if (heldItemOff.getItem() instanceof ToggleableTool toggleableTool) {
ThingFinder.render(evt, player, heldItemOff);
if (toggleableTool.canUseAbilityAndDurability(heldItemOff, Ability.VOIDSHIFT) && ToggleableTool.getCustomSetting(heldItemOff, Ability.VOIDSHIFT.getName()) == 0)
MiscRenders.renderTransparentPlayer(evt, player, heldItemOff);
if (toggleableTool.canUseAbility(heldItemOff, Ability.DROPTELEPORT) && ToggleableTool.getCustomSetting(heldItemMain, Ability.DROPTELEPORT.getName()) == 0) {
NBTHelpers.BoundInventory boundInventory = ToggleableTool.getBoundInventory(heldItemOff);
if (boundInventory != null && player.level().dimension().equals(boundInventory.globalPos().dimension())) {
renderSelectedBlock(evt, boundInventory.globalPos().pos(), boundInventory.direction());
}
}
}
}

public static void renderSelectedBlock(RenderLevelStageEvent event, BlockPos pos, Direction direction) {
final Minecraft mc = Minecraft.getInstance();

MultiBufferSource.BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource();

Vec3 view = mc.gameRenderer.getMainCamera().getPosition();

PoseStack matrix = event.getPoseStack();
matrix.pushPose();
matrix.translate(-view.x(), -view.y(), -view.z());

matrix.pushPose();
matrix.translate(pos.getX(), pos.getY(), pos.getZ());
matrix.translate(-0.005f, -0.005f, -0.005f);
matrix.scale(1.01f, 1.01f, 1.01f);
//matrix.mulPose(Axis.YP.rotationDegrees(-90.0F));

Matrix4f positionMatrix = matrix.last().pose();
RenderHelpers.renderBoxSolid(matrix, positionMatrix, buffer, BlockPos.ZERO, 0, 1, 0, 0.25f);
RenderHelpers.renderFaceSolid(matrix, positionMatrix, buffer, BlockPos.ZERO, direction, 0, 0, 1, 0.25f);
RenderHelpers.renderLines(matrix, BlockPos.ZERO, BlockPos.ZERO, Color.WHITE, buffer);
matrix.popPose();

matrix.popPose();
buffer.endBatch(OurRenderTypes.TRANSPARENT_BOX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.AABB;
Expand Down Expand Up @@ -167,6 +168,42 @@ public static void renderBoxSolid(PoseStack pose, Matrix4f matrix, MultiBufferSo
renderBoxSolid(pose.last(), matrix, buffer, x, y, z, xEnd, yEnd, zEnd, r, g, b, alpha);
}

public static void renderFaceSolid(PoseStack pose, Matrix4f matrix, MultiBufferSource buffer, BlockPos pos, Direction direction, float r, float g, float b, float alpha) {
double x = pos.getX() - 0.001;
double y = pos.getY() - 0.001;
double z = pos.getZ() - 0.001;
double xEnd = pos.getX() + 1.0015;
double yEnd = pos.getY() + 1.0015;
double zEnd = pos.getZ() + 1.0015;

switch (direction) {
case DOWN:
// Draw on the bottom face (y = pos.getY())
renderBoxSolid(pose.last(), matrix, buffer, x, y - 0.001, z, xEnd, y, zEnd, r, g, b, alpha);
break;
case UP:
// Draw on the top face (y = pos.getY() + 1)
renderBoxSolid(pose.last(), matrix, buffer, x, yEnd, z, xEnd, yEnd + 0.0015, zEnd, r, g, b, alpha);
break;
case NORTH:
// Draw on the north face (z = pos.getZ())
renderBoxSolid(pose.last(), matrix, buffer, x, y, z - 0.001, xEnd, yEnd, z, r, g, b, alpha);
break;
case SOUTH:
// Draw on the south face (z = pos.getZ() + 1)
renderBoxSolid(pose.last(), matrix, buffer, x, y, zEnd, xEnd, yEnd, zEnd + 0.0015, r, g, b, alpha);
break;
case WEST:
// Draw on the west face (x = pos.getX())
renderBoxSolid(pose.last(), matrix, buffer, x - 0.001, y, z, x, yEnd, zEnd, r, g, b, alpha);
break;
case EAST:
// Draw on the east face (x = pos.getX() + 1)
renderBoxSolid(pose.last(), matrix, buffer, xEnd, y, z, xEnd + 0.0015, yEnd, zEnd, r, g, b, alpha);
break;
}
}

public static void renderBoxSolid(PoseStack pose, Matrix4f matrix, MultiBufferSource buffer, AABB aabb, float r, float g, float b, float alpha) {
float minX = (float) aabb.minX;
float minY = (float) aabb.minY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum Ability {
SPLASH(SettingType.TOGGLE, 20, 250, UseType.PASSIVE, BindingType.CUSTOM_ONLY, Registration.UPGRADE_SPLASH),

//Tier 3
DROPTELEPORT(SettingType.TOGGLE, 2, 100, UseType.PASSIVE, BindingType.CUSTOM_ONLY, Registration.UPGRADE_DROPTELEPORT),
DROPTELEPORT(SettingType.TOGGLE, 2, 100, UseType.PASSIVE, BindingType.CUSTOM_ONLY, CustomSettingType.RENDER, Registration.UPGRADE_DROPTELEPORT),
VOIDSHIFT(SettingType.SLIDER, 1, 50, UseType.USE, BindingType.LEFT_AND_CUSTOM,
AbilityMethods::voidShift, CustomSettingType.RENDER), //FE Per block traveled
NEGATEFALLDAMAGE(SettingType.SLIDER, 1, 50, UseType.PASSIVE, BindingType.CUSTOM_ONLY, Registration.UPGRADE_NEGATEFALLDAMAGE),
Expand Down

0 comments on commit f201408

Please sign in to comment.