v1.1.0
Add configuration file, and properties contained within Fix server functionality where a server might use a hub server. Add gitignore for vscode folder.
This commit is contained in:
parent
873fafbccb
commit
6847fb3367
6 changed files with 96 additions and 35 deletions
|
@ -5,10 +5,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import dev.zontreck.mcmods.configs.WMDClientConfig;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
@ -20,19 +20,25 @@ public class CheckInventory extends TimerTask
|
|||
@Override
|
||||
public void run() {
|
||||
|
||||
if(!WatchMyDurability.isInGame)return;
|
||||
//WatchMyDurability.LOGGER.info("TICKING CHECK INVENTORY EVENT");
|
||||
// Get the player inventory
|
||||
Inventory inv = WatchMyDurability._player.getInventory();
|
||||
|
||||
if(checkList("_armor", inv.armor)) Soundify();
|
||||
if(checkList("_items", inv.items)) Soundify();
|
||||
if(checkList("_offhand", inv.offhand)) Soundify();
|
||||
|
||||
try {
|
||||
|
||||
if(!WatchMyDurability.isInGame)return;
|
||||
//WatchMyDurability.LOGGER.info("TICKING CHECK INVENTORY EVENT");
|
||||
// Get the player inventory
|
||||
Inventory inv = Minecraft.getInstance().player.getInventory();
|
||||
|
||||
checkList("_armor", inv.armor);
|
||||
checkList("_items", inv.items);
|
||||
checkList("_offhand", inv.offhand);
|
||||
|
||||
|
||||
PushItems("_armor", inv.armor);
|
||||
PushItems("_items", inv.items);
|
||||
PushItems("_offhand", inv.offhand);
|
||||
PushItems("_armor", inv.armor);
|
||||
PushItems("_items", inv.items);
|
||||
PushItems("_offhand", inv.offhand);
|
||||
} catch (Exception e) {
|
||||
WatchMyDurability.LOGGER.warn(": : : : [ERROR] : : : :");
|
||||
WatchMyDurability.LOGGER.warn("A error in the WatchMyDurability timer code has occurred. This could happen with hub worlds and the server transfers that occur. If this happened in another instance, please report this error to the developer, along with what you were doing.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -54,14 +60,15 @@ public class CheckInventory extends TimerTask
|
|||
ItemRegistry.register(type,items);
|
||||
}
|
||||
|
||||
public void Soundify()
|
||||
public void Soundify(SoundEvent sound)
|
||||
{
|
||||
//WatchMyDurability.LOGGER.info("PLAY ALERT SOUND");
|
||||
WatchMyDurability._player.playSound(SoundEvents.ITEM_BREAK, 1.0f, 1.0f);
|
||||
Minecraft.getInstance().player.playSound(sound, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
public boolean checkList(String type, NonNullList<ItemStack> stacks){
|
||||
public void checkList(String type, NonNullList<ItemStack> stacks){
|
||||
Integer slotNum = 0;
|
||||
//boolean ret=false;
|
||||
for (ItemStack is1 : stacks) {
|
||||
if(is1.isDamageableItem() && is1.isDamaged() && !ItemRegistry.contains(type, slotNum, WatchMyDurability.REGISTRY.GetNewItem(is1))){
|
||||
|
||||
|
@ -72,19 +79,27 @@ public class CheckInventory extends TimerTask
|
|||
percent = cur * 100 / max;
|
||||
|
||||
//WatchMyDurability.LOGGER.debug("ITEM DURABILITY: "+cur+"; MAXIMUM: "+max+"; PERCENT: "+percent);
|
||||
if(percent <= 10)
|
||||
{
|
||||
Component X = Component.literal(is1.getDisplayName().getString()+" is about to break!");
|
||||
WatchMyDurability._player.displayClientMessage(X, false);
|
||||
// Play Sound
|
||||
return true;
|
||||
} else return false;
|
||||
for (Integer entry : WMDClientConfig.alertPercents.get()) {
|
||||
Integer idx = WMDClientConfig.alertPercents.get().indexOf(entry);
|
||||
String entryStr = WMDClientConfig.alertMessages.get().get(idx);
|
||||
|
||||
if(percent <= entry){
|
||||
String replaced = entryStr.replaceAll("!item!", is1.getDisplayName().getString());
|
||||
WatchMyDurability.LOGGER.info("Enqueue alert for an item. Playing sound for item: "+is1.getDisplayName().getString());
|
||||
|
||||
SoundEvent theSound = SoundEvents.ITEM_BREAK;
|
||||
Soundify(theSound);
|
||||
|
||||
Component X = Component.literal(replaced);
|
||||
Minecraft.getInstance().player.displayClientMessage(X, false);
|
||||
break; // Rule applies, break out of this loop, move to next item.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slotNum ++;
|
||||
}
|
||||
|
||||
return false;
|
||||
//return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package dev.zontreck.mcmods;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
import dev.zontreck.mcmods.configs.WMDClientConfig;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.User;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.config.ModConfig.Type;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
|
||||
|
||||
import java.util.Timer;
|
||||
|
@ -31,7 +33,6 @@ public class WatchMyDurability
|
|||
/// DO NOT USE FROM ANY THIRD PARTY PACKAGES
|
||||
public static User CurrentUser = null; // This is initialized by the client
|
||||
public static boolean isInGame = false; // This locks the timer thread
|
||||
public static LocalPlayer _player = null; // Updated on login!
|
||||
public static ItemRegistry REGISTRY;
|
||||
|
||||
|
||||
|
@ -42,6 +43,7 @@ public class WatchMyDurability
|
|||
|
||||
// Register the commonSetup method for modloading
|
||||
modEventBus.addListener(this::commonSetup);
|
||||
ModLoadingContext.get().registerConfig(Type.CLIENT, WMDClientConfig.SPEC, "watchmydurability-client.toml");
|
||||
|
||||
// Register ourselves for server and other game events we are interested in
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
@ -70,13 +72,13 @@ public class WatchMyDurability
|
|||
@SubscribeEvent
|
||||
public static void onClientSetup(FMLClientSetupEvent event)
|
||||
{
|
||||
//LOGGER.info(": : : CLIENT SETUP : : :");
|
||||
LOGGER.info(": : : CLIENT SETUP : : :");
|
||||
// Some client setup code
|
||||
//LOGGER.info("HELLO FROM CLIENT SETUP");
|
||||
//LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
|
||||
WatchMyDurability.CurrentUser = Minecraft.getInstance().getUser();
|
||||
|
||||
time.schedule(new CheckInventory(), 10000, 10000);
|
||||
time.schedule(new CheckInventory(), WMDClientConfig.TimerVal.get()*1000, WMDClientConfig.TimerVal.get()*1000);
|
||||
|
||||
ItemRegistry.Initialize();
|
||||
|
||||
|
@ -91,14 +93,22 @@ public class WatchMyDurability
|
|||
public static void onJoin(ClientPlayerNetworkEvent.LoggingIn event){
|
||||
// Joined
|
||||
//LOGGER.info("PLAYER LOGGED IN");
|
||||
WatchMyDurability._player = event.getPlayer();
|
||||
LOGGER.info(": : : PLAYER LOGGED IN : : :");
|
||||
WatchMyDurability.isInGame=true;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLeave(ClientPlayerNetworkEvent.LoggingOut event){
|
||||
//LOGGER.info("PLAYER LOGGED OUT");
|
||||
LOGGER.info(": : : PLAYER LOGGED OUT : : :");
|
||||
WatchMyDurability.isInGame=false;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClone(ClientPlayerNetworkEvent.Clone event)
|
||||
{
|
||||
LOGGER.info(": : : : PLAYER RESPAWNED OR MOVED TO A NEW WORLD : : : :");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package dev.zontreck.mcmods.configs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
public class WMDClientConfig {
|
||||
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
|
||||
public static final ForgeConfigSpec SPEC;
|
||||
|
||||
public static ForgeConfigSpec.ConfigValue<List<Integer>> alertPercents;
|
||||
public static ForgeConfigSpec.ConfigValue<List<String>> alertMessages;
|
||||
public static ForgeConfigSpec.ConfigValue<Integer> TimerVal;
|
||||
static{
|
||||
List<Integer> alerts1 = new ArrayList<>();
|
||||
alerts1.add(10);
|
||||
|
||||
List<String> alerts2 = new ArrayList<>();
|
||||
alerts2.add("!item! is about to break");
|
||||
|
||||
|
||||
BUILDER.push("Alerts");
|
||||
BUILDER.comment("Both of the following lists must have the same number of entries. NOTE: Percents do NOT stack. After the first rule is applied, it will move to the next item, so please make the list ascend, and not descend. Example: 10, 50").define("VERSION", "1.0.0");
|
||||
|
||||
alertPercents = BUILDER.comment("The list of alerts you want at what percentages of remaining durability").define("Percents", alerts1);
|
||||
alertMessages = BUILDER.comment("The messages you want displayed when a alert is triggered. You must have the same amount of messages as alerts").define("Messages", alerts2);
|
||||
TimerVal = BUILDER.comment("How many seconds between timer ticks to check your inventory items?").define("Timer", 5);
|
||||
|
||||
BUILDER.pop();
|
||||
SPEC=BUILDER.build();
|
||||
}
|
||||
}
|
Reference in a new issue