Skip to content

Commit

Permalink
feat: adding logic to render info over the world
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed May 5, 2022
1 parent bbde117 commit d823e4b
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/sekwah/narutomod/NarutoMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.sekwah.narutomod.client.gui.NarutoInGameGUI;
import com.sekwah.narutomod.client.keybinds.NarutoKeyHandler;
import com.sekwah.narutomod.client.renderer.NarutoRenderEvents;
import com.sekwah.narutomod.client.renderer.NarutoWorldRenderEvents;
import com.sekwah.narutomod.commands.NarutoCommands;
import com.sekwah.narutomod.client.renderer.entity.config.NarutoConfig;
import com.sekwah.narutomod.entity.NarutoDataSerialisers;
Expand Down Expand Up @@ -72,6 +73,7 @@ public NarutoMod() {
private void clientSetup(FMLClientSetupEvent event) {
NarutoRenderEvents.registerRenderTypes();
NarutoKeyHandler.registerKeyBinds();
NarutoWorldRenderEvents.registerEvents();
}

private void setup(FMLCommonSetupEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public void performServer(Player player, INinjaData ninjaData, int ticksActive)
player.displayClientMessage(new TranslatableComponent("jutsu.cast.substitution"), false);
// Activate
ninjaData.useSubstitution(1);
Vec3 loc = ninjaData.getSubstitutionLoc();
if(loc != null) {
double distance = player.position().distanceTo(loc);
if(distance < 40) {
player.teleportTo(loc.x, loc.y, loc.z);
}
}
} else {
player.displayClientMessage(new TranslatableComponent("jutsu.cast.substitution_mark"), false);
ninjaData.setSubstitutionLoc(player.position());
// Mark
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface INinjaData extends INBTSerializable<Tag> {
void addStamina(float amount);

Vec3 getSubstitutionLoc();
void setSubstitutionLoc(Vec3 loc);

DoubleJumpData getDoubleJumpData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ public Vec3 getSubstitutionLoc() {
return this.substitutionLocation;
}

@Override
public void setSubstitutionLoc(Vec3 loc) {
this.substitutionLocation = loc;
}

@Override
public DoubleJumpData getDoubleJumpData() {
return this.doubleJumpData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class SubstitutionGUI extends GuiComponent {

private static final ResourceLocation LOG_TEXTURE = new ResourceLocation(NarutoMod.MOD_ID, "textures/gui/jutsu/jutsu_substiutution.png");
public static final ResourceLocation LOG_TEXTURE = new ResourceLocation(NarutoMod.MOD_ID, "textures/gui/jutsu/jutsu_substiutution.png");

private final Minecraft minecraft;
private int screenWidth;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sekwah.narutomod.client.renderer;

import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.RenderType;
import org.lwjgl.opengl.GL11;

public class NarutoRenderTypes extends RenderType {

public static final RenderType JUTSU_INFO = create("narutomod_jutsu_overlay",
DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, 256/*bufferSize*/,
false/*affectsCrumbling*/, false/*sortOnUpload*/, RenderType.CompositeState.builder()
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
.setWriteMaskState(COLOR_WRITE)
.setCullState(CULL)
.createCompositeState(false)
);

public NarutoRenderTypes(String p_173178_, VertexFormat p_173179_, VertexFormat.Mode p_173180_, int p_173181_, boolean p_173182_, boolean p_173183_, Runnable p_173184_, Runnable p_173185_) {
super(p_173178_, p_173179_, p_173180_, p_173181_, p_173182_, p_173183_, p_173184_, p_173185_);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.sekwah.narutomod.client.renderer;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import com.sekwah.narutomod.client.gui.SubstitutionGUI;
import com.sekwah.narutomod.client.renderer.worldinfo.SubstitutionWorldMarkerRenderer;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraftforge.client.event.RenderLevelLastEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class NarutoWorldRenderEvents {

public static void registerEvents() {
MinecraftForge.EVENT_BUS.register(NarutoWorldRenderEvents.class);
}

@SubscribeEvent
public static void renderLevelLast(RenderLevelLastEvent event) {
Minecraft mc = Minecraft.getInstance();
if(mc.options.hideGui || mc.level == null || mc.player == null) {
return;
}
Camera camera = mc.getEntityRenderDispatcher().camera;
PoseStack poseStack = event.getPoseStack();
Matrix4f matrix = event.getProjectionMatrix();
float partialTicks = event.getPartialTick();
MultiBufferSource multiBufferSource = mc.renderBuffers().bufferSource();
SubstitutionWorldMarkerRenderer.render(poseStack, camera, matrix, multiBufferSource, partialTicks);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
package com.sekwah.narutomod.client.renderer.worldinfo;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f;
import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.client.gui.SubstitutionGUI;
import com.sekwah.narutomod.client.renderer.NarutoRenderTypes;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;

public class SubstitutionWorldMarkerRenderer {
public static void render() {

public static void render(PoseStack poseStack, Camera camera, Matrix4f matrix, MultiBufferSource multiBufferSource, float partialTicks) {
int textureWidth = 19;
int textureHeight = 18;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, SubstitutionGUI.LOG_TEXTURE);
poseStack.pushPose();
poseStack.translate(camera.getPosition().x, camera.getPosition().y, camera.getPosition().z);

VertexConsumer vertexConsumer = multiBufferSource.getBuffer(NarutoRenderTypes.JUTSU_INFO);

poseStack.popPose();
}
}

0 comments on commit d823e4b

Please sign in to comment.