Jump to content

Roland

Members
  • Posts

    9
  • Joined

  • Last visited

Everything posted by Roland

  1. I tried it: @Mod(MyLogger.MOD_ID) @Mod.EventBusSubscriber(modid = MyLogger.MOD_ID, value = Dist.DEDICATED_SERVER) public class MyLogger { // ... But: 1) It works only if I add "@OnlyIn(Dist.DEDICATED_SERVER)" above every event handler like this: @SubscribeEvent @OnlyIn(Dist.DEDICATED_SERVER) public void onPlayerTick(TickEvent.PlayerTickEvent event) { // ... 2) My command event handler stop working. Handler: @SubscribeEvent @OnlyIn(Dist.DEDICATED_SERVER) public void onPlayerEnteredCommand(CommandEvent event) { String playerName = Objects.requireNonNull(event.getParseResults().getContext().getSource().getPlayer()).getGameProfile().getName(); if (playersCanExecListOfCommands.get(playerName) != true) { event.setCanceled(true); } } Error: [Server thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: null Index: 1 Listeners: 0: NORMAL 1: ASM: ru.tester.mylogger.MyMod@59a50d8a onPlayerEnteredCommand(Lnet/minecraftforge/event/CommandEvent;)V java.lang.NullPointerException at java.base/java.util.Objects.requireNonNull(Objects.java:208) at TRANSFORMER/mylogger@1.19.2-3.0.0/ru.tester.mylogger.MyLogger.onPlayerEnteredCommand(PinMod.java:94) at TRANSFORMER/mylogger@1.19.2-3.0.0/ru.tester.mylogger.__MyLogger_onPlayerEnteredCommand_CommandEvent.invoke(.dynamic)
  2. Hello. I write anti-griefer server-side-only mod. It has connection to database. So I need to run in on multiplayer only, not in single player. I spent some time trying to determine is it singleplayer or not and how to "stop" (not load? not run?) mod correctly, but still no ideas. Now I have the following code, that I copy in every method of my mod. Looks ugly and not right. Checking: private boolean isSinglePlayer() { try { if (ServerLifecycleHooks.getCurrentServer().isSingleplayer()) return true; } catch (Exception e) { return true; } return false; } Using: @SubscribeEvent public void serverLoad(RegisterCommandsEvent event) throws IOException { if (isSinglePlayer()) { return; } // ... } Just in case: ServerLifeCycleHooks is needed because I don't know any other GLOBAL class that can return me current server. try-catch is needed because "current server" may not even exist. And using my "serverLoad" method in every other methods... Ugh. I'm speechless. Can you tell me, guys, how to do it correctly?
  3. I understand. There is no need in any state for logger for now. Thank you for answering!
  4. Sorry for wasting your time. My last question (in this thread, haha). Is that okay approach for Minecraft mods? It this approach okay for mod development? // Somewhere in main Mod class (marked as @Mod): (new LogThread()).start(); // Thread class (example with SQL insert query): public class LogThread extends Thread { public void run() { try { db.createStatement().executeUpdate("INSERT INTO ..."); } catch (Exception e) { // ... } } }
  5. Strings only? Okay, thanks, now I got it.
  6. Thank you! But I need integer representation of current dimention. Because I want to put it to database as integer. BTW, I have tried the following with not result. I miss something simple, because I have no idea what are "ResourceKey", "ResourceLocation" and so on. And why they are implemented. LOGGER.info(String.valueOf(player.level.dimension())); // Log: // ResourceKey[minecraft:dimension / minecraft:overworld] LOGGER.info(String.valueOf(Level.OVERWORLD)); // Log: // ResourceKey[minecraft:dimension / minecraft:overworld] LOGGER.info(String.valueOf(player.level.dimensionTypeId())); // Log: // ResourceKey[minecraft:dimension_type / minecraft:overworld] LOGGER.info(String.valueOf(player.level.dimensionType())); // Log: // DimensionType[fixedTime=OptionalLong.empty, hasSkyLight=true, hasCeiling=false, ultraWarm=false, natural=true, coordinateScale=1.0, bedWorks=true, respawnAnchorWorks=false, minY=-64, height=384, logicalHeight=384, infiniburn=TagKey[minecraft:block / minecraft:infiniburn_overworld], effectsLocation=minecraft:overworld, ambientLight=0.0, monsterSettings=MonsterSettings[piglinSafe=false, hasRaids=true, monsterSpawnLightTest=[0-7], monsterSpawnBlockLightLimit=0]] LOGGER.info(String.valueOf(player.level.dimension() == Level.OVERWORLD)); // Log: // true Added later: My guess is that the dimension is stored as an enum somewhere. And so I can get its numeric representation. Seems I'm wrong... Yes, I know. Already, haha. It's okay for now. Very interesting! But if tick is gone it will never repeat... And if I want to write some kind of logger... Well. Do I need to create new threads with SQL-insert-queries? The reason is: I _need_ to write some data to database exactly when it happened and never-never-never skip writing operations. I think MineCraft hasn't things like queues? Thank you! I'm new in modding. Any information is useful. Does Forge community has some guides may be? I google every time I need something. It's not the best way to learn something new. And to code correctly. Oh, thank you, sir! That's why I wondering how it work twice a time... I'll fix it right now.
  7. Hello. I'm writing anti-griefing mod. I'm trying to find out in what kind of dimension player currently is. My code sample (just to show that I have ServerPlayer instance and nothing more): public void onServerTick(TickEvent.ServerTickEvent event) throws SQLException { List<ServerPlayer> pl = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers(); for (ServerPlayer player : pl) { // How to get player's dimension??? player.getDimension() not exist MC version is 1.19.2. Help, please.
  8. Okay, I got it. My code was like: INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(Mod.MOD, "main"), () -> "1.1", s -> true, s -> true); But it should be like: private static final String PROTOCOL_VERSION = "1.1"; // ... INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(Mod.MOD, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); So the answer is: 1) You have to have networking in your mod. Even if you dont use it; 2) It should be written as example above.
  9. Hello. I'm writing my first mod. It must be installed on both sides (server and client). But when I install it on server and then try to connect without the mod on client it let me connect to server. Yes, Forge is installed to server and client. For example, I can't do the same with Industrial Craft 2 Classic or "Iron Chests" mod (it not let me connect to server without client-side part). Why is it happening? What I do wrong? How to force client to install my mod? I was googling about 6 hours yesterday with no result.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.