Fixed crash when Server tries to load KeyMappings.

This commit is contained in:
2021-08-18 16:15:02 +01:00
parent 3334e8325a
commit 7cb24ce57d
3 changed files with 14 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import com.micle.totemofreviving.TotemOfReviving;
import com.micle.totemofreviving.network.C2SRequestPlayerRevive; import com.micle.totemofreviving.network.C2SRequestPlayerRevive;
import com.micle.totemofreviving.network.C2SRequestTotemCharge; import com.micle.totemofreviving.network.C2SRequestTotemCharge;
import com.micle.totemofreviving.network.C2SRequestTotemTarget; import com.micle.totemofreviving.network.C2SRequestTotemTarget;
import com.micle.totemofreviving.setup.ModKeyMappings;
import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.KeyMapping; import net.minecraft.client.KeyMapping;
@ -25,13 +26,13 @@ public class StrawTotemItem extends Item {
public static final String TAG_TARGET_NAME = "target_name"; public static final String TAG_TARGET_NAME = "target_name";
public static final String TAG_FAIL_CHANCE = "fail_chance"; public static final String TAG_FAIL_CHANCE = "fail_chance";
public static final int STARTING_FAIL_CHANCE = 45; public static final int STARTING_FAIL_CHANCE = 45;
private static final KeyMapping KEY_LSHIFT = new KeyMapping("StrawTotemItem_LSHIFT", InputConstants.KEY_LSHIFT, KeyMapping.CATEGORY_INTERFACE);
public StrawTotemItem() { public StrawTotemItem() {
super(new Item.Properties().tab(CreativeModeTab.TAB_MISC).stacksTo(1).rarity(Rarity.UNCOMMON)); super(new Item.Properties().tab(CreativeModeTab.TAB_MISC).stacksTo(1).rarity(Rarity.UNCOMMON));
} }
@Override @Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) { public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) {
super.appendHoverText(stack, world, tooltip, flag); super.appendHoverText(stack, world, tooltip, flag);
tooltip.add(new TextComponent(ChatFormatting.GOLD + "Charges: " + ChatFormatting.GRAY + stack.getOrCreateTag().getInt(TAG_CHARGE_AMOUNT))); tooltip.add(new TextComponent(ChatFormatting.GOLD + "Charges: " + ChatFormatting.GRAY + stack.getOrCreateTag().getInt(TAG_CHARGE_AMOUNT)));
@ -39,7 +40,7 @@ public class StrawTotemItem extends Item {
tooltip.add(new TextComponent(ChatFormatting.GOLD + "Fail Chance: " + ChatFormatting.GRAY + stack.getOrCreateTag().getInt(TAG_FAIL_CHANCE))); tooltip.add(new TextComponent(ChatFormatting.GOLD + "Fail Chance: " + ChatFormatting.GRAY + stack.getOrCreateTag().getInt(TAG_FAIL_CHANCE)));
tooltip.add(new TextComponent( ChatFormatting.DARK_GRAY + "" + ChatFormatting.ITALIC + "\"Feels kinda funky.\"")); tooltip.add(new TextComponent( ChatFormatting.DARK_GRAY + "" + ChatFormatting.ITALIC + "\"Feels kinda funky.\""));
tooltip.add(new TextComponent("")); tooltip.add(new TextComponent(""));
if (KEY_LSHIFT.isDown()) { if (ModKeyMappings.KEYMAP_UI_LSHIFT.isDown()) {
tooltip.add(new TextComponent(ChatFormatting.YELLOW + "R-CLICK")); tooltip.add(new TextComponent(ChatFormatting.YELLOW + "R-CLICK"));
tooltip.add(new TextComponent(ChatFormatting.GOLD + "When other hand is empty: attempt to revive target.")); tooltip.add(new TextComponent(ChatFormatting.GOLD + "When other hand is empty: attempt to revive target."));
tooltip.add(new TextComponent(ChatFormatting.GOLD + "When other hand has " + ChatFormatting.GRAY + "Straw Reviving Charge" + ChatFormatting.GOLD + ": charge totem.")); tooltip.add(new TextComponent(ChatFormatting.GOLD + "When other hand has " + ChatFormatting.GRAY + "Straw Reviving Charge" + ChatFormatting.GOLD + ": charge totem."));

View File

@ -4,6 +4,7 @@ import com.micle.totemofreviving.TotemOfReviving;
import com.micle.totemofreviving.network.C2SRequestPlayerRevive; import com.micle.totemofreviving.network.C2SRequestPlayerRevive;
import com.micle.totemofreviving.network.C2SRequestTotemCharge; import com.micle.totemofreviving.network.C2SRequestTotemCharge;
import com.micle.totemofreviving.network.C2SRequestTotemTarget; import com.micle.totemofreviving.network.C2SRequestTotemTarget;
import com.micle.totemofreviving.setup.ModKeyMappings;
import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.KeyMapping; import net.minecraft.client.KeyMapping;
@ -23,20 +24,20 @@ public class TotemOfRevivingItem extends Item {
public static final String TAG_CHARGE_AMOUNT = "charge"; public static final String TAG_CHARGE_AMOUNT = "charge";
public static final String TAG_TARGET_INDEX = "target_index"; public static final String TAG_TARGET_INDEX = "target_index";
public static final String TAG_TARGET_NAME = "target_name"; public static final String TAG_TARGET_NAME = "target_name";
private static final KeyMapping KEY_LSHIFT = new KeyMapping("TotemOfRevivingItem_LSHIFT", InputConstants.KEY_LSHIFT, KeyMapping.CATEGORY_INTERFACE);
public TotemOfRevivingItem() { public TotemOfRevivingItem() {
super(new Item.Properties().tab(CreativeModeTab.TAB_MISC).stacksTo(1).rarity(Rarity.RARE)); super(new Item.Properties().tab(CreativeModeTab.TAB_MISC).stacksTo(1).rarity(Rarity.RARE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) { public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) {
super.appendHoverText(stack, world, tooltip, flag); super.appendHoverText(stack, world, tooltip, flag);
tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "Charges: " + ChatFormatting.BLUE + stack.getOrCreateTag().getInt(TAG_CHARGE_AMOUNT)) { tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "Charges: " + ChatFormatting.BLUE + stack.getOrCreateTag().getInt(TAG_CHARGE_AMOUNT)) {
}); });
tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "Target: " + ChatFormatting.BLUE + stack.getOrCreateTag().getString(TAG_TARGET_NAME))); tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "Target: " + ChatFormatting.BLUE + stack.getOrCreateTag().getString(TAG_TARGET_NAME)));
tooltip.add(new TextComponent("")); tooltip.add(new TextComponent(""));
if (KEY_LSHIFT.isDown()) { if (ModKeyMappings.KEYMAP_UI_LSHIFT.isDown()) {
tooltip.add(new TextComponent(ChatFormatting.AQUA + "R-CLICK")); tooltip.add(new TextComponent(ChatFormatting.AQUA + "R-CLICK"));
tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "When other hand is empty: attempt to revive target.")); tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "When other hand is empty: attempt to revive target."));
tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "When other hand has " + ChatFormatting.BLUE + "Reviving Charge" + ChatFormatting.DARK_AQUA + ": charge totem.")); tooltip.add(new TextComponent(ChatFormatting.DARK_AQUA + "When other hand has " + ChatFormatting.BLUE + "Reviving Charge" + ChatFormatting.DARK_AQUA + ": charge totem."));

View File

@ -0,0 +1,8 @@
package com.micle.totemofreviving.setup;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
public class ModKeyMappings {
public static final KeyMapping KEYMAP_UI_LSHIFT = new KeyMapping("KEYMAP_UI_LSHIFT", InputConstants.KEY_LSHIFT, KeyMapping.CATEGORY_INTERFACE);
}