Fully functional mod for 1.16.4 fabric.
This commit is contained in:
910
src/main/java/markil3/immersive_hud/EventBus.java
Normal file
910
src/main/java/markil3/immersive_hud/EventBus.java
Normal file
@@ -0,0 +1,910 @@
|
||||
/**
|
||||
* Copyright (C) 2021 Markil 3
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package markil3.immersive_hud;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BowItem;
|
||||
import net.minecraft.item.CrossbowItem;
|
||||
import net.minecraft.item.EggItem;
|
||||
import net.minecraft.item.EnderPearlItem;
|
||||
import net.minecraft.item.FilledMapItem;
|
||||
import net.minecraft.item.FishingRodItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.RangedWeaponItem;
|
||||
import net.minecraft.item.ShieldItem;
|
||||
import net.minecraft.item.SnowballItem;
|
||||
import net.minecraft.item.ThrowablePotionItem;
|
||||
import net.minecraft.item.TridentItem;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Contains the logic for changing the HUD.
|
||||
*
|
||||
* @author Markil 3
|
||||
* @version 0.1-1.16.4-fabric
|
||||
*/
|
||||
public class EventBus
|
||||
{
|
||||
/**
|
||||
* The number of ticks that the hand will be onscreen. Every tick is 1/20th
|
||||
* of a second.
|
||||
*/
|
||||
static final int HAND_TIME = 10 * 20;
|
||||
/**
|
||||
* The number of ticks most elements will be onscreen. Every tick is 1/20th
|
||||
* of a second.
|
||||
*/
|
||||
static final int VISUAL_TIME = 6 * 20;
|
||||
/**
|
||||
* The number of ticks that the health and hunger bars will be onscreen.
|
||||
* Every tick is 1/20th of a second.
|
||||
*/
|
||||
static final int HEALTH_TIME = (int) ((float) VISUAL_TIME * 2.5);
|
||||
|
||||
/**
|
||||
* How many more ticks the hand will be onscreen. Every tick is 1/20th of a
|
||||
* second.
|
||||
*/
|
||||
private static int mainHandTime, offHandTime;
|
||||
|
||||
/**
|
||||
* How many more ticks the crosshair will be onscreen. Every tick is 1/20th
|
||||
* of a second.
|
||||
*/
|
||||
private static int crosshairTime;
|
||||
/**
|
||||
* If true, then the hand (and crosshairs) will be locked onto the screen
|
||||
* without disappearing until this flag is updated.
|
||||
*/
|
||||
private static boolean mainHandLock, offHandLock;
|
||||
/**
|
||||
* A bitmask that will lock the corresponding hand without necessarily
|
||||
* showing the crosshairs. The first bit will be the main hand, and the
|
||||
* second will be the offhand.
|
||||
*/
|
||||
private static int mapLock;
|
||||
|
||||
/**
|
||||
* How many more ticks the hotbar will be onscreen. Every tick is 1/20th of
|
||||
* a second.
|
||||
*/
|
||||
private static int hotbarTime;
|
||||
/**
|
||||
* The last hotbar slot that was selected. This is used to check for a
|
||||
* change in the hotbar slot.
|
||||
*/
|
||||
private static int selectedHotbarSlot = -1;
|
||||
/**
|
||||
* The last item that was in this hand. This is used to check for a change
|
||||
* in what was equipped.
|
||||
*/
|
||||
private static Item mainHandItem = null, offHandItem = null;
|
||||
|
||||
/**
|
||||
* How many more ticks the health bar will be onscreen. Every tick is 1/20th
|
||||
* of a second.
|
||||
*/
|
||||
private static int healthTime;
|
||||
/**
|
||||
* Records what the health was previously. Used to check for a change in the
|
||||
* health.
|
||||
* <p>
|
||||
* Note that the display of the armor is linked to this.
|
||||
*/
|
||||
private static float health = -1;
|
||||
/**
|
||||
* Records what the maximum health was previously. Used to check for a
|
||||
* change in the health.
|
||||
*/
|
||||
private static float maxHealth = -1;
|
||||
|
||||
/**
|
||||
* How many more ticks the hunger bar will be onscreen. Every tick is 1/20th
|
||||
* of a second.
|
||||
*/
|
||||
private static int hungerTime;
|
||||
/**
|
||||
* Records what the hunger level was previously. Used to check for a change
|
||||
* in hunger.
|
||||
*/
|
||||
private static int hunger = -1;
|
||||
/**
|
||||
* Records whether or not there was food poisoning. Used to check for a
|
||||
* change in hunger.
|
||||
*/
|
||||
private static boolean isFoodPoisoned = false;
|
||||
|
||||
/**
|
||||
* How many more ticks the mount's health bar will be onscreen. Every tick
|
||||
* is 1/20th of a second.
|
||||
*/
|
||||
private static int mountTime;
|
||||
/**
|
||||
* Records what the health of the mount was previously. Used to check for a
|
||||
* change in the health.
|
||||
*/
|
||||
private static float mountHealth = -1;
|
||||
/**
|
||||
* Records what the maximum health of the mount was previously. Used to
|
||||
* check for a change in the health.
|
||||
*/
|
||||
private static float mountMaxHealth = -1;
|
||||
|
||||
/**
|
||||
* How many more ticks the mount's jump bar will be onscreen. Every tick is
|
||||
* 1/20th of a second.
|
||||
*/
|
||||
private static int jumpTime;
|
||||
|
||||
/**
|
||||
* How many more ticks the experience bar will be onscreen. Every tick is
|
||||
* 1/20th of a second.
|
||||
*/
|
||||
private static int experienceTime;
|
||||
/**
|
||||
* Records what the experience was previously. Used to check for a change in
|
||||
* the health.
|
||||
*/
|
||||
private static float experienceProgress = -1;
|
||||
|
||||
/**
|
||||
* Run whenever the player clicks a mouse button. This brings the hands into
|
||||
* view, and briefly brings the health and hunger into view if the held item
|
||||
* is food.
|
||||
*
|
||||
* @param hand - The hand being triggered
|
||||
* @param clear - Whether the hand it being enabled or disabled.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static void onClick(Hand hand, boolean clear)
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
LivingEntity entity;
|
||||
Item item;
|
||||
Iterator<ItemStack> hands;
|
||||
if (mc.getCameraEntity() instanceof LivingEntity)
|
||||
{
|
||||
entity = (LivingEntity) mc.getCameraEntity();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (clear)
|
||||
{
|
||||
item = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
hands = entity.getItemsHand().iterator();
|
||||
if (hand == Hand.OFF_HAND)
|
||||
{
|
||||
hands.next();
|
||||
}
|
||||
item =
|
||||
Optional.ofNullable(hands.next())
|
||||
.filter(stack -> !stack.isEmpty())
|
||||
.map(ItemStack::getItem)
|
||||
.orElse(null);
|
||||
}
|
||||
crosshairTime = VISUAL_TIME;
|
||||
if (hand == Hand.MAIN_HAND)
|
||||
{
|
||||
mainHandTime = HAND_TIME;
|
||||
mainHandLock = item != null;
|
||||
}
|
||||
else
|
||||
{
|
||||
offHandTime = HAND_TIME;
|
||||
offHandLock = item != null;
|
||||
}
|
||||
if (item != null)
|
||||
{
|
||||
if (item.isFood())
|
||||
{
|
||||
healthTime = HEALTH_TIME;
|
||||
hungerTime = HEALTH_TIME;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Unusing hand " + hand);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run whenever a hand is rendered in 1st person. This brings the player
|
||||
* hands into and out of view as needed.
|
||||
*
|
||||
* @param hand - The hand being rendered.
|
||||
* @param matrixStack - The rendering stack.
|
||||
*
|
||||
* @return If true, then don't render this hand at all.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean onRenderHand(Hand hand, MatrixStack matrixStack)
|
||||
{
|
||||
final int HAND_UP_TIME = 20;
|
||||
switch (hand)
|
||||
{
|
||||
case OFF_HAND:
|
||||
if (offHandTime == 0 && !offHandLock)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!offHandLock && (mapLock & 0b01) == 0)
|
||||
{
|
||||
offHandTime--;
|
||||
if (offHandTime < HAND_UP_TIME)
|
||||
{
|
||||
matrixStack
|
||||
.translate(0,
|
||||
-1.0F * (HAND_UP_TIME - offHandTime) /
|
||||
HAND_UP_TIME,
|
||||
0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MAIN_HAND:
|
||||
if (mainHandTime == 0 && !mainHandLock)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!mainHandLock && (mapLock & 0b10) == 0)
|
||||
{
|
||||
System.out.println("Decreasing main hand time");
|
||||
mainHandTime--;
|
||||
if (mainHandTime < HAND_UP_TIME)
|
||||
{
|
||||
matrixStack
|
||||
.translate(0,
|
||||
-1.0F * (HAND_UP_TIME - mainHandTime) /
|
||||
HAND_UP_TIME,
|
||||
0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the crosshair, adjusting the alpha as
|
||||
* needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the crosshair.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean drawCrosshair()
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
Entity entity = mc.getCameraEntity();
|
||||
boolean changed = false;
|
||||
if (mc.crosshairTarget != null && mc.crosshairTarget
|
||||
.getType() != HitResult.Type.MISS)
|
||||
{
|
||||
if (mc.crosshairTarget.getType() == HitResult.Type
|
||||
.ENTITY)
|
||||
{
|
||||
if (((EntityHitResult) mc.crosshairTarget).getEntity() != entity
|
||||
.getVehicle())
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed || mainHandLock || offHandLock || crosshairTime
|
||||
> 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(crosshairTime > 0 ?
|
||||
crosshairTime :
|
||||
VISUAL_TIME));
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
0F);
|
||||
}
|
||||
if (crosshairTime > 0)
|
||||
{
|
||||
crosshairTime--;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the mount's health, adjusting the alpha
|
||||
* as needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the mount health bar.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean drawMountHealth()
|
||||
{
|
||||
/*
|
||||
* When the health percentage falls to this level or below, the
|
||||
* health bar won't disappear, allowing the player to be constantly
|
||||
* reminded of their low health.
|
||||
*/
|
||||
final float CONST_BOUNDARY = 0.5F;
|
||||
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
Entity entity = mc.getCameraEntity();
|
||||
Entity tmp = entity.getVehicle();
|
||||
LivingEntity mount;
|
||||
boolean changed = false;
|
||||
|
||||
if (tmp == null)
|
||||
{
|
||||
mountHealth = -1;
|
||||
mountMaxHealth = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mount = (LivingEntity) tmp;
|
||||
if (mountHealth != mount.getHealth())
|
||||
{
|
||||
mountHealth = mount.getHealth();
|
||||
changed = true;
|
||||
}
|
||||
if (mountMaxHealth != mount.getMaxHealth())
|
||||
{
|
||||
mountMaxHealth = mount.getMaxHealth();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
mountTime = VISUAL_TIME;
|
||||
}
|
||||
else if (mountTime > 0)
|
||||
{
|
||||
mountTime--;
|
||||
}
|
||||
if (mountTime > 0)
|
||||
{
|
||||
/*
|
||||
* Renders it along with health.
|
||||
*/
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(mountTime));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the armor bar, adjusting the alpha as
|
||||
* needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the armor bar.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean drawArmor()
|
||||
{
|
||||
/*
|
||||
* Sets the armor to fade in and out in sync with the health.
|
||||
* Technically, since this method gets called before health, it will
|
||||
* be 1 tick behind, but I'm not too concerned about it.
|
||||
*/
|
||||
if (healthTime > 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(healthTime));
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
0.0F);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the health bar, adjusting the alpha as
|
||||
* needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the health.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean drawHealth()
|
||||
{
|
||||
/*
|
||||
* When the health percentage falls to this level or below, the
|
||||
* health bar won't disappear, allowing the player to be constantly
|
||||
* reminded of their low health.
|
||||
*/
|
||||
final float CONST_BOUNDARY = 0.5F;
|
||||
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
LivingEntity entity;
|
||||
if (mc.getCameraEntity() instanceof LivingEntity)
|
||||
{
|
||||
entity = (LivingEntity) mc.getCameraEntity();
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
boolean changed = false;
|
||||
|
||||
/*
|
||||
* Resets the transparency from the armor call.
|
||||
*/
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
1F);
|
||||
|
||||
/**
|
||||
* Checks for a change in current or max health.
|
||||
*/
|
||||
if (health != entity.getHealth())
|
||||
{
|
||||
health = entity.getHealth();
|
||||
changed = true;
|
||||
}
|
||||
if (maxHealth != entity.getMaxHealth())
|
||||
{
|
||||
maxHealth = entity.getMaxHealth();
|
||||
changed = true;
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
healthTime = HEALTH_TIME;
|
||||
}
|
||||
else if (healthTime > 0)
|
||||
{
|
||||
healthTime--;
|
||||
}
|
||||
/*
|
||||
* Only makes a change if the player is healthy. Otherwise,
|
||||
* the bar is shown.
|
||||
*/
|
||||
if (health / maxHealth > CONST_BOUNDARY)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(healthTime));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the hunger bar, adjusting the alpha as
|
||||
* needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the hunger bar.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean drawHunger()
|
||||
{
|
||||
/*
|
||||
* When hunger falls to this level or below, the hunger bar won't
|
||||
* disappear, allowing the player to be constantly reminded of their
|
||||
* low hunger.
|
||||
*/
|
||||
final int HUNGER_BOUNDARY = 15;
|
||||
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
PlayerEntity entity;
|
||||
boolean changed = false;
|
||||
|
||||
/*
|
||||
* Resets the transparency from last time.
|
||||
*/
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
1F);
|
||||
if (mc.getCameraEntity() instanceof PlayerEntity)
|
||||
{
|
||||
entity = (PlayerEntity) mc.getCameraEntity();
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hunger != entity.getHungerManager().getFoodLevel())
|
||||
{
|
||||
hunger = entity.getHungerManager().getFoodLevel();
|
||||
changed = true;
|
||||
}
|
||||
if (isFoodPoisoned != entity.hasStatusEffect(StatusEffects
|
||||
.HUNGER))
|
||||
{
|
||||
isFoodPoisoned =
|
||||
entity.hasStatusEffect(StatusEffects.HUNGER);
|
||||
changed = true;
|
||||
}
|
||||
if (hunger <= HUNGER_BOUNDARY)
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
hungerTime = HEALTH_TIME;
|
||||
}
|
||||
else if (hungerTime > 0)
|
||||
{
|
||||
hungerTime--;
|
||||
}
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(hungerTime));
|
||||
/*
|
||||
* Only makes a change if the player is satisfied. Otherwise,
|
||||
* the bar is shown.
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the horse jump bar, adjusting the alpha
|
||||
* as needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the jump bar.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean drawJumpbar()
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
ClientPlayerEntity entity;
|
||||
boolean changed = false;
|
||||
|
||||
if (mc.getCameraEntity() instanceof ClientPlayerEntity)
|
||||
{
|
||||
entity = (ClientPlayerEntity) mc.getCameraEntity();
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (entity.method_3151() > 0)
|
||||
{
|
||||
jumpTime = VISUAL_TIME;
|
||||
}
|
||||
else if (jumpTime > 0)
|
||||
{
|
||||
jumpTime--;
|
||||
}
|
||||
if (experienceTime > 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(jumpTime));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the experience bar, adjusting the alpha
|
||||
* as needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the experience bar.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean drawExperience()
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
ClientPlayerEntity entity;
|
||||
boolean changed = false;
|
||||
|
||||
if (mc.getCameraEntity() instanceof ClientPlayerEntity)
|
||||
{
|
||||
entity = (ClientPlayerEntity) mc.getCameraEntity();
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (experienceProgress != entity.totalExperience)
|
||||
{
|
||||
experienceProgress = entity.totalExperience;
|
||||
changed = true;
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
experienceTime = VISUAL_TIME;
|
||||
}
|
||||
else if (experienceTime > 0)
|
||||
{
|
||||
experienceTime--;
|
||||
}
|
||||
if (experienceTime > 0)
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(experienceTime));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the hotbar. Note that this method does
|
||||
* not directly change the transparency of the hotbar, only checking whether
|
||||
* or not to draw it.
|
||||
*
|
||||
* @return If true, then cancel drawing the hotbar.
|
||||
*
|
||||
* @see #recolorHotbar()
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static boolean updateHotbar()
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
ClientPlayerEntity entity;
|
||||
Item item, handItem = null;
|
||||
boolean changed = false;
|
||||
|
||||
if (mc.getCameraEntity() instanceof ClientPlayerEntity)
|
||||
{
|
||||
entity = (ClientPlayerEntity) mc.getCameraEntity();
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
mainHandLock = offHandLock = false;
|
||||
mapLock = 0;
|
||||
int i = 0;
|
||||
for (ItemStack stack : entity.getItemsHand())
|
||||
{
|
||||
item =
|
||||
Optional.ofNullable(stack)
|
||||
.map(ItemStack::getItem)
|
||||
.orElse(null);
|
||||
if (item != null)
|
||||
{
|
||||
if (item instanceof RangedWeaponItem)
|
||||
{
|
||||
/*
|
||||
* Enables the crosshairs and lock the hand
|
||||
* whenever the bow is drawn.
|
||||
*/
|
||||
if (item instanceof BowItem)
|
||||
{
|
||||
if (entity.isUsingItem() && entity
|
||||
.getActiveHand()
|
||||
.ordinal() == i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
mainHandLock = true;
|
||||
break;
|
||||
case 1:
|
||||
offHandLock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Enables the crosshairs and lock the hand
|
||||
* whenever a loaded crossbow is equipped.
|
||||
*/
|
||||
else if (item instanceof CrossbowItem)
|
||||
{
|
||||
if (CrossbowItem.isCharged(stack))
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
mainHandLock = true;
|
||||
break;
|
||||
case 1:
|
||||
offHandLock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* We don't know how modded items behave
|
||||
* exactly, so we keep it safe and enable the
|
||||
* crosshairs at all times for any shootable
|
||||
* items.
|
||||
*/
|
||||
else
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
mainHandLock = true;
|
||||
break;
|
||||
case 1:
|
||||
offHandLock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Items that have the crosshairs enabled for as long
|
||||
* as the item is actively being used.
|
||||
*/
|
||||
else if (item instanceof TridentItem || item
|
||||
instanceof ShieldItem)
|
||||
{
|
||||
if (entity.isUsingItem() && entity
|
||||
.getActiveHand() != null && entity.getActiveHand()
|
||||
.ordinal() == i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
mainHandLock = true;
|
||||
break;
|
||||
case 1:
|
||||
offHandLock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Items that have the crosshairs enabled for as long
|
||||
* as the item is being held at all.
|
||||
*/
|
||||
else if (item instanceof ThrowablePotionItem ||
|
||||
item instanceof SnowballItem || item instanceof
|
||||
EggItem || item instanceof EnderPearlItem || item
|
||||
instanceof FishingRodItem)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
mainHandLock = true;
|
||||
break;
|
||||
case 1:
|
||||
offHandLock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Maps get special treatment. The hand is locked,
|
||||
* but the crosshairs are not enabled.
|
||||
*/
|
||||
else if (item instanceof FilledMapItem)
|
||||
{
|
||||
mapLock = mapLock | (2 - i);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks for a change in the item
|
||||
*/
|
||||
if (i == 0)
|
||||
{
|
||||
handItem = mainHandItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
handItem = offHandItem;
|
||||
}
|
||||
if (item != handItem)
|
||||
{
|
||||
changed = true;
|
||||
/*
|
||||
* Briefly shows the health and hunger bar whenever
|
||||
* food is switched to.
|
||||
*/
|
||||
if (item.isFood())
|
||||
{
|
||||
healthTime = HEALTH_TIME;
|
||||
hungerTime = HEALTH_TIME;
|
||||
}
|
||||
if (i == 0)
|
||||
{
|
||||
mainHandItem = item;
|
||||
mainHandTime = HAND_TIME;
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
offHandItem = item;
|
||||
offHandTime = HAND_TIME;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks for a change in what slot is used.
|
||||
*/
|
||||
if (selectedHotbarSlot != entity.inventory.selectedSlot)
|
||||
{
|
||||
selectedHotbarSlot = entity.inventory.selectedSlot;
|
||||
mainHandTime = HAND_TIME;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
hotbarTime = VISUAL_TIME;
|
||||
}
|
||||
else if (hotbarTime > 0)
|
||||
{
|
||||
hotbarTime--;
|
||||
}
|
||||
|
||||
return hotbarTime == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the crosshair, adjusting the alpha as
|
||||
* needed.
|
||||
*
|
||||
* @return If true, then cancel drawing the crosshair.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
public static void recolorHotbar()
|
||||
{
|
||||
RenderSystem.color4f(1.0F,
|
||||
1.0F,
|
||||
1.0F,
|
||||
Main.getAlpha(hotbarTime));
|
||||
}
|
||||
}
|
||||
53
src/main/java/markil3/immersive_hud/Main.java
Normal file
53
src/main/java/markil3/immersive_hud/Main.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* This Minecraft mod aims to move the ingame HUD out of the way whenever
|
||||
* possible. Copyright (C) 2021 Markil 3
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package markil3.immersive_hud;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
/**
|
||||
* The main entry point for the Immersive HUD mod.
|
||||
*
|
||||
* @author Markil 3
|
||||
* @version 0.1-1.16.4-fabric
|
||||
*/
|
||||
public class Main implements ModInitializer
|
||||
{
|
||||
@Override
|
||||
public void onInitialize()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method to handle the transparency timing. It will (for the most
|
||||
* part), make
|
||||
*
|
||||
* @param renderTime - How many ticks until the element entirely
|
||||
* disappears.
|
||||
*
|
||||
* @return The new alpha value.
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
static float getAlpha(int renderTime)
|
||||
{
|
||||
return Math.min(renderTime / 20.0F,
|
||||
1.0F);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (C) 2021 Markil 3
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package markil3.immersive_hud.mixin;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import markil3.immersive_hud.EventBus;
|
||||
|
||||
/**
|
||||
* This mixin hooks into the client player class to check for when the hands
|
||||
* move. Note that most of the logic can be found in {@link EventBus}.
|
||||
*
|
||||
* @author Markil 3
|
||||
* @version 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Mixin(ClientPlayerEntity.class)
|
||||
public class ClientPlayerHook
|
||||
{
|
||||
/**
|
||||
* Updates hand timing every time an attack is initiated.
|
||||
*
|
||||
* @param hand - The attacking hand.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "swingHand", at = @At(value = "TAIL"))
|
||||
public void swingHand(Hand hand, CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.onClick(hand, hand == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates hand timing every time an item is used.
|
||||
*
|
||||
* @param hand - The using hand.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "setCurrentHand", at = @At(value = "TAIL"))
|
||||
public void setCurrentHand(Hand hand, CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.onClick(hand, hand == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates hand timing every the hand is no longer being used.
|
||||
*
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "clearActiveItem", at = @At(value = "HEAD"))
|
||||
public void clearActiveItem(CallbackInfo callbackInfo)
|
||||
{
|
||||
if (MinecraftClient.getInstance().cameraEntity instanceof LivingEntity)
|
||||
{
|
||||
EventBus.onClick(((LivingEntity) MinecraftClient.getInstance().cameraEntity)
|
||||
.getActiveHand(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
84
src/main/java/markil3/immersive_hud/mixin/HeldItemHook.java
Normal file
84
src/main/java/markil3/immersive_hud/mixin/HeldItemHook.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (C) 2021 Markil 3
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package markil3.immersive_hud.mixin;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import markil3.immersive_hud.EventBus;
|
||||
|
||||
/**
|
||||
* This mixin hooks into the hand renderer to make the hands move in and out of
|
||||
* view. Note that most of the logic can be found in {@link EventBus}.
|
||||
*
|
||||
* @author Markil 3
|
||||
* @version 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Mixin(HeldItemRenderer.class)
|
||||
public class HeldItemHook
|
||||
{
|
||||
/**
|
||||
* Determines whether or not to render a certain hand.
|
||||
*
|
||||
* @param player
|
||||
* @param tickDelta
|
||||
* @param pitch
|
||||
* @param hand
|
||||
* @param swingProgress
|
||||
* @param item
|
||||
* @param equipProgress
|
||||
* @param matrices
|
||||
* @param vertexConsumers
|
||||
* @param light
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/util/math/MatrixStack;push()V",
|
||||
shift = At.Shift.AFTER), cancellable = true)
|
||||
public void renderHand(AbstractClientPlayerEntity player,
|
||||
float tickDelta,
|
||||
float pitch,
|
||||
Hand hand,
|
||||
float swingProgress,
|
||||
ItemStack item,
|
||||
float equipProgress,
|
||||
MatrixStack matrices,
|
||||
VertexConsumerProvider vertexConsumers,
|
||||
int light,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
if (EventBus.onRenderHand(hand, matrices))
|
||||
{
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
237
src/main/java/markil3/immersive_hud/mixin/HudHook.java
Normal file
237
src/main/java/markil3/immersive_hud/mixin/HudHook.java
Normal file
@@ -0,0 +1,237 @@
|
||||
/**
|
||||
* Copyright (C) 2021 Markil 3
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package markil3.immersive_hud.mixin;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.profiler.DummyProfiler;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import markil3.immersive_hud.EventBus;
|
||||
|
||||
/**
|
||||
* This mixin hooks into the HUD class to modify most of the HUD elements. Note
|
||||
* that most of the logic can be found in {@link EventBus}.
|
||||
*
|
||||
* @author Markil 3
|
||||
* @version 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Mixin(InGameHud.class)
|
||||
public class HudHook
|
||||
{
|
||||
/**
|
||||
* Determines whether or not to draw the crosshair.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderCrosshair", at = @At(value = "HEAD"))
|
||||
public void startCrosshair(MatrixStack stack, CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.drawCrosshair();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets any changes from drawing the crosshair.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderCrosshair", at = @At(value = "TAIL"))
|
||||
public void finishCrosshair(MatrixStack stack, CallbackInfo callbackInfo)
|
||||
{
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the horse jump bar.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountJumpBar", at = @At(value = "HEAD"))
|
||||
public void startJumpbar(MatrixStack stack,
|
||||
int x,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.drawJumpbar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets any changes from drawing the horse jump bar.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountJumpBar", at = @At(value = "TAIL"))
|
||||
public void finishJumpbar(MatrixStack stack,
|
||||
int x,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the experience bar.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderExperienceBar", at = @At(value = "HEAD"),
|
||||
cancellable = true)
|
||||
public void startExperience(MatrixStack stack,
|
||||
int x,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
if (EventBus.drawExperience())
|
||||
{
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets any changes from drawing the experience bar.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderExperienceBar", at = @At(value = "TAIL"))
|
||||
public void finishExperience(MatrixStack stack,
|
||||
int x,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the mount's health.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountHealth", at = @At(value = "HEAD"))
|
||||
public void startMountHealth(MatrixStack stack, CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.drawMountHealth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets any changes from drawing the mount's health.
|
||||
*
|
||||
* @param stack - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderMountHealth", at = @At(value = "TAIL"))
|
||||
public void finishMountHealth(MatrixStack stack, CallbackInfo callbackInfo)
|
||||
{
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not to draw the hotbar.
|
||||
*
|
||||
* @param tickDelta
|
||||
* @param matrices - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderHotbar", at = @At(value = "HEAD"), cancellable =
|
||||
true)
|
||||
public void startHotbar(float tickDelta,
|
||||
MatrixStack matrices,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
if (EventBus.updateHotbar())
|
||||
{
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the actual adjustment to the hotbar as needed.
|
||||
*
|
||||
* @param tickDelta
|
||||
* @param matrices - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderHotbar", at = @At(value = "INVOKE", target =
|
||||
"Lcom/mojang/blaze3d/systems/RenderSystem;color4f(FFFF)V", shift
|
||||
= At.Shift.AFTER))
|
||||
public void adjustHotbar(float tickDelta,
|
||||
MatrixStack matrices,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
EventBus.recolorHotbar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets any changes from drawing the hotbar.
|
||||
*
|
||||
* @param tickDelta
|
||||
* @param matrices - The matrix drawing stack.
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "renderHotbar", at = @At(value = "TAIL"))
|
||||
public void finishHotbar(float tickDelta,
|
||||
MatrixStack matrices,
|
||||
CallbackInfo callbackInfo)
|
||||
{
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
}
|
||||
}
|
||||
85
src/main/java/markil3/immersive_hud/mixin/ProfilerHook.java
Normal file
85
src/main/java/markil3/immersive_hud/mixin/ProfilerHook.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright (C) 2021 Markil 3
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package markil3.immersive_hud.mixin;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.util.profiler.DummyProfiler;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import markil3.immersive_hud.EventBus;
|
||||
|
||||
/**
|
||||
* This class hooks into the profiler to trigger color changes for the status
|
||||
* indicators.
|
||||
*
|
||||
* @author Markil 3
|
||||
* @version 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Mixin(DummyProfiler.class)
|
||||
public class ProfilerHook
|
||||
{
|
||||
/**
|
||||
* Hooks into the profiler to add logic to drawing armor.
|
||||
*
|
||||
* @param section - The profiler section
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "push", at = @At(value = "TAIL"))
|
||||
public void renderArmor(String section, CallbackInfo callbackInfo)
|
||||
{
|
||||
if (section.equals("armor"))
|
||||
{
|
||||
EventBus.drawArmor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks into the profiler to add logic to drawing status bars besides
|
||||
* armor.
|
||||
*
|
||||
* @param section - The profiler section
|
||||
* @param callbackInfo
|
||||
*
|
||||
* @since 0.1-1.16.4-fabric
|
||||
*/
|
||||
@Inject(method = "swap", at = @At(value = "TAIL"))
|
||||
public void renderStatus(String section, CallbackInfo callbackInfo)
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case "health":
|
||||
EventBus.drawHealth();
|
||||
break;
|
||||
case "food":
|
||||
EventBus.drawHunger();
|
||||
break;
|
||||
case "air":
|
||||
/*
|
||||
* Resets the color so that nothing else is bothered.
|
||||
*/
|
||||
RenderSystem.color4f(1, 1, 1, 1F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user