Allows the experience bar to show when looking at certain blocks (anvils, enchantment tables, etc).
This commit is contained in:
@@ -12,6 +12,6 @@ modmenu_version=3.0.1
|
|||||||
fabric_version=0.44.0+1.18
|
fabric_version=0.44.0+1.18
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.2
|
mod_version = 1.3
|
||||||
maven_group = markil3
|
maven_group = markil3
|
||||||
archives_base_name = immersive_hud
|
archives_base_name = immersive_hud
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package markil3.immersive_hud;
|
|||||||
|
|
||||||
import static markil3.immersive_hud.Main.TICKS_PER_SECOND;
|
import static markil3.immersive_hud.Main.TICKS_PER_SECOND;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
@@ -97,6 +99,7 @@ public class ConfigManager
|
|||||||
private double minHealth = 0.5;
|
private double minHealth = 0.5;
|
||||||
private int minHunger = 17;
|
private int minHunger = 17;
|
||||||
private Identifier[] ignoredItems = new Identifier[]{Registry.ITEM.getId(Items.FIREWORK_ROCKET)};
|
private Identifier[] ignoredItems = new Identifier[]{Registry.ITEM.getId(Items.FIREWORK_ROCKET)};
|
||||||
|
private Identifier[] enchantingBlocks = new Identifier[]{Registry.BLOCK.getId(Blocks.ENCHANTING_TABLE), Registry.BLOCK.getId(Blocks.ANVIL), Registry.BLOCK.getId(Blocks.BOOKSHELF), Registry.BLOCK.getId(Blocks.FURNACE), Registry.BLOCK.getId(Blocks.BLAST_FURNACE), Registry.BLOCK.getId(Blocks.SMOKER), Registry.BLOCK.getId(Blocks.GRINDSTONE)};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the instance of this class.
|
* Returns the instance of this class.
|
||||||
@@ -276,6 +279,26 @@ public class ConfigManager
|
|||||||
return this.ignoredItems;
|
return this.ignoredItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains a collection of items that will display the enchantment bar when hovered over.
|
||||||
|
*
|
||||||
|
* @return A set of blocks.
|
||||||
|
*/
|
||||||
|
public Set<Block> getEnchantingItems()
|
||||||
|
{
|
||||||
|
return Arrays.stream(enchantingBlocks).map(Registry.BLOCK::get).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains a collection of items that will display the enchantment bar when hovered over.
|
||||||
|
*
|
||||||
|
* @return An array blocks.
|
||||||
|
*/
|
||||||
|
public Identifier[] getEnchantingdentifiers()
|
||||||
|
{
|
||||||
|
return this.enchantingBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the time that the hands are allowed to display.
|
* Sets the time that the hands are allowed to display.
|
||||||
*
|
*
|
||||||
@@ -367,6 +390,27 @@ public class ConfigManager
|
|||||||
{
|
{
|
||||||
this.ignoredItems = Arrays.stream(items).map(Identifier::new).filter(i -> Registry.ITEM.getOrEmpty(i).isPresent()).toArray(Identifier[]::new);
|
this.ignoredItems = Arrays.stream(items).map(Identifier::new).filter(i -> Registry.ITEM.getOrEmpty(i).isPresent()).toArray(Identifier[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets which items will display the experience bar when hovered over.
|
||||||
|
*
|
||||||
|
* @param items - A set of ignored items.
|
||||||
|
*/
|
||||||
|
public void setEnchantingItems(Block... items)
|
||||||
|
{
|
||||||
|
this.enchantingBlocks = Arrays.stream(items).map(Registry.BLOCK::getId).toArray(Identifier[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets which items won't cause the hands and crosshairs to show when used.
|
||||||
|
*
|
||||||
|
* @param items - A set of ignored items.
|
||||||
|
*/
|
||||||
|
public void setEnchantingItems(String... items)
|
||||||
|
{
|
||||||
|
this.enchantingBlocks = Arrays.stream(items).map(Identifier::new).filter(i -> Registry.BLOCK.getOrEmpty(i).isPresent()).toArray(Identifier[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves changes to this mod's configuration.
|
* Saves changes to this mod's configuration.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package markil3.immersive_hud;
|
|||||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
@@ -218,6 +219,31 @@ public class ModMenu implements ModMenuApi
|
|||||||
})
|
})
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
general.addEntry(entryBuilder
|
||||||
|
.startStrList(new TranslatableText("option.immersive_hud.enchantingList"), Arrays
|
||||||
|
.asList(instance
|
||||||
|
.getEnchantingdentifiers()).stream().map(Identifier::toString)
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.setDefaultValue(Arrays
|
||||||
|
.asList(Blocks.ENCHANTING_TABLE, Blocks.ANVIL, Blocks.BOOKSHELF, Blocks.FURNACE, Blocks.BLAST_FURNACE, Blocks.SMOKER, Blocks.GRINDSTONE).stream().map(b -> Registry.BLOCK.getId(b).toString()).toList())
|
||||||
|
.setTooltip(new TranslatableText("tooltip.immersive_hud.enchantingList"))
|
||||||
|
.setSaveConsumer(val -> instance.setIgnoredItems(val.toArray(new String[0]))).setErrorSupplier(val -> {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Optional<String> item = val.stream().filter(i -> !Registry.BLOCK.getOrEmpty(new Identifier(i)).isPresent()).findFirst();
|
||||||
|
if (item.isPresent())
|
||||||
|
{
|
||||||
|
return Optional.of(new TranslatableText("error.immersive_hud.ignoreList.unknownItem"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (InvalidIdentifierException e)
|
||||||
|
{
|
||||||
|
return Optional.of(new TranslatableText("error.immersive_hud.ignoreList.illegalId"));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
})
|
||||||
|
.build());
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package markil3.immersive_hud;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
@@ -41,6 +43,7 @@ import net.minecraft.item.SnowballItem;
|
|||||||
import net.minecraft.item.ThrowablePotionItem;
|
import net.minecraft.item.ThrowablePotionItem;
|
||||||
import net.minecraft.item.TridentItem;
|
import net.minecraft.item.TridentItem;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
import net.minecraft.util.hit.HitResult;
|
import net.minecraft.util.hit.HitResult;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
@@ -926,16 +929,28 @@ public class TimerUtils
|
|||||||
experienceProgress = entity.totalExperience;
|
experienceProgress = entity.totalExperience;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (experienceTime <= 0 && mc.crosshairTarget != null && mc.crosshairTarget.getType() == HitResult.Type.BLOCK)
|
||||||
|
{
|
||||||
|
Block block = mc.world.getBlockState(((BlockHitResult) mc.crosshairTarget).getBlockPos()).getBlock();
|
||||||
|
Set<Block> ignored = ConfigManager.getInstance().getEnchantingItems();
|
||||||
|
if (ignored.contains(block))
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
experienceTime = experience.getMaxTime() - (experienceTime > 0 ?
|
experienceTime = experience.getMaxTime() - (experienceTime > 0 ?
|
||||||
experience.getFadeInTime() :
|
experience.getFadeInTime() :
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
else if (experienceTime > 0)
|
else if (experienceTime > 0)
|
||||||
{
|
{
|
||||||
experienceTime -= ticks;
|
experienceTime -= ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (experienceTime > 0)
|
if (experienceTime > 0)
|
||||||
{
|
{
|
||||||
stack.push();
|
stack.push();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"option.immersive_hud.minHunger": "Minimum Hunger Fade",
|
"option.immersive_hud.minHunger": "Minimum Hunger Fade",
|
||||||
"option.immersive_hud.showArmor": "Show Armor",
|
"option.immersive_hud.showArmor": "Show Armor",
|
||||||
"option.immersive_hud.ignoreList": "Ignored Items",
|
"option.immersive_hud.ignoreList": "Ignored Items",
|
||||||
|
"option.immersive_hud.enchantingList": "Experience Blocks",
|
||||||
"tooltip.immersive_hud.hotbarMaxTime": "How long the hotbar can be displayed on screen in seconds",
|
"tooltip.immersive_hud.hotbarMaxTime": "How long the hotbar can be displayed on screen in seconds",
|
||||||
"tooltip.immersive_hud.hotbarFadeIn": "How many seconds it takes for the hotbar to fade in",
|
"tooltip.immersive_hud.hotbarFadeIn": "How many seconds it takes for the hotbar to fade in",
|
||||||
"tooltip.immersive_hud.hotbarFadeOut": "How many seconds it takes for the hotbar to move out",
|
"tooltip.immersive_hud.hotbarFadeOut": "How many seconds it takes for the hotbar to move out",
|
||||||
@@ -52,6 +53,7 @@
|
|||||||
"tooltip.immersive_hud.minHunger": "When the hunger level goes below this level, the hunger bar won't fade away",
|
"tooltip.immersive_hud.minHunger": "When the hunger level goes below this level, the hunger bar won't fade away",
|
||||||
"tooltip.immersive_hud.showArmor": "Whether or not the armor bar should display on the HUD",
|
"tooltip.immersive_hud.showArmor": "Whether or not the armor bar should display on the HUD",
|
||||||
"tooltip.immersive_hud.ignoreList": "Which items will not trigger the arm and crosshairs when used",
|
"tooltip.immersive_hud.ignoreList": "Which items will not trigger the arm and crosshairs when used",
|
||||||
|
"tooltip.immersive_hud.enchantingList": "Which blocks will show the experience bar when looked at.",
|
||||||
"error.immersive_hud.ignoreList.unknownItem": "Unknown item %s",
|
"error.immersive_hud.ignoreList.unknownItem": "Unknown item %s",
|
||||||
"error.immersive_hud.ignoreList.illegalId": "%s is not a legal item identifier"
|
"error.immersive_hud.ignoreList.illegalId": "%s is not a legal item identifier"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user