Skip to content

Commit

Permalink
feat: add distance indicator for substitution marker
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed May 5, 2022
1 parent eb3e027 commit ea16168
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import net.minecraft.world.phys.Vec3;

public class SubstitutionJutsuAbility extends Ability implements Ability.Channeled {

public static int MAX_MARKER_DISTANCE = 40;

@Override
public ActivationType activationType() {
return ActivationType.CHANNELED;
Expand Down Expand Up @@ -54,13 +57,11 @@ public void performServer(Player player, INinjaData ninjaData, int ticksActive)
// Activate
ninjaData.useSubstitution(1);
Vec3 loc = ninjaData.getSubstitutionLoc();
if(loc != null) {
double distance = player.position().distanceTo(loc);
if(distance < 40 && player.level.dimension().location().equals(ninjaData.getSubstitutionDimension())) {
spawnLogAt(player, player.position(), ninjaData);
player.teleportTo(loc.x, loc.y, loc.z);
ninjaData.setSubstitutionLoc(null, null);
}
double distance = loc != null ? player.position().distanceTo(loc) : 0;
if(loc != null && distance < 40 && player.level.dimension().location().equals(ninjaData.getSubstitutionDimension())) {
spawnLogAt(player, player.position(), ninjaData);
player.teleportTo(loc.x, loc.y - 2, loc.z);
ninjaData.setSubstitutionLoc(null, null);
} else {
Vec3 originalPosition = player.position();
if(this.randomTeleportPlayer(player, ninjaData)) {
Expand All @@ -70,7 +71,7 @@ public void performServer(Player player, INinjaData ninjaData, int ticksActive)
}
}
} else {
ninjaData.setSubstitutionLoc(player.position(), player.level.dimension().location());
ninjaData.setSubstitutionLoc(player.position().add(0, 2, 0), player.level.dimension().location());
// Mark
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public NarutoInGameGUI(){
this.substitutionOverlay = new SubstitutionGUI(this.minecraft);
this.worldMarkerOverlay = new WorldMarkerGUI(this.minecraft);

this.overlays = new PlayerGUI[]{this.charkaOverlay, this.substitutionOverlay, this.worldMarkerOverlay};
this.overlays = new PlayerGUI[]{this.worldMarkerOverlay, this.substitutionOverlay, this.charkaOverlay};

MinecraftForge.EVENT_BUS.addListener(this::renderGameOverlay);
MinecraftForge.EVENT_BUS.addListener(this::clientTickEvent);
Expand All @@ -63,7 +63,7 @@ public void clientTickEvent(TickEvent.ClientTickEvent event) {
}

@SubscribeEvent
public void renderGameOverlay(RenderGameOverlayEvent event) {
public void renderGameOverlay(RenderGameOverlayEvent.Pre event) {
if(event.getType() != RenderGameOverlayEvent.ElementType.ALL) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector4f;
import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.abilities.jutsus.SubstitutionJutsuAbility;
import com.sekwah.narutomod.capabilities.NinjaCapabilityHandler;
import com.sekwah.narutomod.util.ColorUtil;
import net.minecraft.client.Minecraft;
Expand All @@ -28,6 +29,7 @@ public class WorldMarkerGUI extends GuiComponent implements PlayerGUI {
private int screenWidth;
private int screenHeight;
private final int intTextColor;
private final int outOfRangeColor;
private final int intTextOutline;
private Vec3 substitutionLoc;

Expand All @@ -36,7 +38,9 @@ public WorldMarkerGUI(Minecraft mc) {

Color textColor = new Color(255, 255, 255);
Color textOutline = new Color(0, 0, 0);
Color outOfRangeColor = new Color(255, 99, 99);
this.intTextColor = ColorUtil.toMCColor(textColor).getValue();
this.outOfRangeColor = ColorUtil.toMCColor(outOfRangeColor).getValue();
this.intTextOutline = ColorUtil.toMCColor(textOutline).getValue();
}

Expand All @@ -61,7 +65,7 @@ public void render(PoseStack matrixStack, Matrix4f worldMatrix, Vec3 cameraPos)
RenderSystem.enableBlend();
RenderSystem.setShaderTexture(0, LOG_TEXTURE);

Vector4f vec = new Vector4f((float) (substitutionLoc.x - cameraPos.x), (float) (substitutionLoc.y - cameraPos.y + 1.5), (float) (substitutionLoc.z - cameraPos.z), 1F);
Vector4f vec = new Vector4f((float) (substitutionLoc.x - cameraPos.x), (float) (substitutionLoc.y - cameraPos.y), (float) (substitutionLoc.z - cameraPos.z), 1F);
double distance = cameraPos.distanceTo(substitutionLoc);
vec.transform(worldMatrix);
vec.perspectiveDivide();
Expand All @@ -71,7 +75,7 @@ public void render(PoseStack matrixStack, Matrix4f worldMatrix, Vec3 cameraPos)


if(vec.z() > 0 && vec.z() < 1) {
float fadeOut = (float) Math.max(Math.min(0.4f, ((distance) / 8) - 0.3), 0);
float fadeOut = (float) Math.max(Math.min(0.6f, ((distance) / 8) - 0.5), 0);
RenderSystem.setShaderColor(1, 1, 1, fadeOut);
float scale = (float) (0.5 / Math.pow((distance + 30) / 80, 2));
matrixStack.pushPose();
Expand All @@ -81,6 +85,7 @@ public void render(PoseStack matrixStack, Matrix4f worldMatrix, Vec3 cameraPos)
0, 0,
32, 32,
32, 32);
centeredTextOutlined(matrixStack, Math.round(distance) + " M", 0, 11, distance < SubstitutionJutsuAbility.MAX_MARKER_DISTANCE ? intTextColor : outOfRangeColor, intTextOutline);
matrixStack.popPose();
}

Expand Down

0 comments on commit ea16168

Please sign in to comment.