Mr Bonobo
Members-
Posts
20 -
Joined
-
Last visited
Everything posted by Mr Bonobo
-
Hello, Should I be worried if I get this warning? [03:28:11] [Render thread/WARN] [minecraft/ClientRecipeBook]: Unknown recipe category: [!!!com.mojang.logging.LogUtils$1ToString@479f738a=>java.lang.NullPointerException:Cannot invoke "Object.toString()" because the return value of "java.util.function.Supplier.get()" is null!!!]/quantum_world:energy_generated_from_energium_block I think its because I return ItemStack.EMPTY on getResultItem(), though vanilla game does the same thing.
-
[SOLVED] DrawString method of GuiComponent abstract class
Mr Bonobo replied to Mr Bonobo's topic in Modder Support
Thanks, If someone has same problem, use protected variable font in AbstractContainerScreen class and draw it : font.draw(variables); If you want to delete inventory and title name, you can override renderLables method and not use super() method. -
[SOLVED] DrawString method of GuiComponent abstract class
Mr Bonobo posted a topic in Modder Support
Hi, how to put a String on block entity GUI screen? I found a method called drawString in GuiComponent class, but I dont know how to pass a Font variable to it (*define font variable, i dont need a custom font, simple minecraft or java lib one would do it). I tried looking how Font is created, but constructor requires function with resourceLoc to fontSet, fontSet needs textureManager and etc... So it kinda gets really complicated. Minecraft version is 1.19.1 -
Writing to compoundNBT, or checking when client connects?
Mr Bonobo posted a topic in Modder Support
Hello, how can I write VoxelShape inside TileEntity-CompoundNBT tag? Or if its not possible or not-effective, how do I fire event when Client player connects to the server? -
How to start/test mod from InteliJ on DEDICATED SERVER, and not on LAN? When i try to run server separately it just completes and stops (its purpose is for testing if it registers/compiles classes without errors, or...?), tried searching for it with IP adress on CLIENT, but surely didnt find anything, because server successfully exits with no errors. Sorry for asking such an obvious question, but I didnt find it anywhere on the internet.
-
Wow! Very good and full-explanitory post. It solved probably all my questions. Only one question came from it: if i create packet, which is sent from a SERVER and handled by a CLIENT, I dont need to use enqueueWork then, or I should add this scheduled task always to prevent bugs/overlapping even on CLIENT side??
-
Ok, I somewhat managed to make it work in different way by accessing capability values with: public static void handle(PacketTriggerElectricGen message, Supplier<NetworkEvent.Context> contextSupplier) { contextSupplier.get().enqueueWork(() -> { contextSupplier.get().getSender().getServerWorld().getTileEntity(message.blockPos). getCapability(new UtilCapabilities().UTIL_CAP).ifPresent(st -> { And context shouldnt be in CLIENT-side, because this packet is triggered by sendToServer(new etc...) from CLIENTside, only sender should be a CLIENT. Even though i tested with DistExecutor which side it is, and it shows its always a CLIENT, but maybe its SERVER after all if I managed to access SERVER side capability values.
-
What is the new way of adding task to work queue? What i want to do in old way: public static void handle(Packet message, Supplier<NetworkEvent.Context> contextSupplier) { FMLCommonHandler.instance().getWorldThread(contextSupplier.netHandler).addScheduledTask(() -> New way: public static void handle(Packetmessage, Supplier<NetworkEvent.Context> contextSupplier) { contextSupplier.get().enqueueWork(() -> { If contexSupplier is CLIENT, it will add task on CLIENT. So what should i do to add task on DEDICATED_SERVER, even though contextSupplier is CLIENT?
-
[SOLVED]-kinda Packet handler / Simple channel
Mr Bonobo replied to Mr Bonobo's topic in Modder Support
Thank you for replies, I made it static and thought its the way to go because only example I stumbled upon on the internet (atleast as new forge versions goes) about packets, handling and creating was with Static Itemhandler on packet class (which is as bad as Static BlockPos if I understood it correctly?) And yes, its because Im testing everything on singleplayer, and I don't think its possible to do it server-client separate at least with Intelij-gradle. And about other question, I will now post whole code which is non-static, with every single usage / function and try to make it as simple and understandable as possible (I renamed classes/functions/variables): Full error code: Error code { [22:02:22] [Client thread/ERROR] [ne.mi.fm.ne.NetworkRegistry/NETREGISTRY]: Attempted to register channel mod:main_channel even though registry phase is over [22:02:22] [Client thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client java.lang.IllegalArgumentException: Registration of network channels is locked at net.minecraftforge.fml.network.NetworkRegistry.createInstance(NetworkRegistry.java:130) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.NetworkRegistry.access$000(NetworkRegistry.java:49) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.NetworkRegistry$ChannelBuilder.createNetworkInstance(NetworkRegistry.java:400) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.NetworkRegistry$ChannelBuilder.simpleChannel(NetworkRegistry.java:409) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at com.Vidas.Mod.Packages.PacketHandler.<init>(PacketHandler.java:16) ~[main/:?] {} at com.Vidas.Mod.TileEntities.ElectricGeneratorScreen.<init>(ElectricGeneratorScreen.java:48) ~[main/:?] {} at net.minecraftforge.fml.network.FMLPlayMessages$OpenContainer.lambda$null$0(FMLPlayMessages.java:287) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_241] {} at net.minecraftforge.fml.network.FMLPlayMessages$OpenContainer.lambda$handle$1(FMLPlayMessages.java:284) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.NetworkEvent$Context.enqueueWork(NetworkEvent.java:185) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.FMLPlayMessages$OpenContainer.handle(FMLPlayMessages.java:282) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.simple.IndexedMessageCodec.lambda$tryDecode$3(IndexedMessageCodec.java:114) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_241] {} at net.minecraftforge.fml.network.simple.IndexedMessageCodec.tryDecode(IndexedMessageCodec.java:114) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.simple.IndexedMessageCodec.consume(IndexedMessageCodec.java:147) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.simple.SimpleChannel.networkEventListener(SimpleChannel.java:65) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212) ~[eventbus-1.0.0-service.jar:?] {} at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204) ~[eventbus-1.0.0-service.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-1.0.0-service.jar:?] {} at net.minecraftforge.fml.network.NetworkInstance.dispatch(NetworkInstance.java:82) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraftforge.fml.network.NetworkHooks.lambda$onCustomPayload$0(NetworkHooks.java:69) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_241] {} at net.minecraftforge.fml.network.NetworkHooks.onCustomPayload(NetworkHooks.java:69) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraft.client.network.play.ClientPlayNetHandler.handleCustomPayload(ClientPlayNetHandler.java:1916) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:runtimedistcleaner:A} at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:61) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:11) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:140) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B} at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:110) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B} at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B} at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:893) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.client.Minecraft.run(Minecraft.java:384) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.client.main.Main.main(Main.java:128) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {pl:runtimedistcleaner:A} at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_241] {} at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_241] {} at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_241] {} at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_241] {} at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-3.2.0.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50) [modlauncher-3.2.0.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:68) [modlauncher-3.2.0.jar:?] {} at cpw.mods.modlauncher.Launcher.run(Launcher.java:80) [modlauncher-3.2.0.jar:?] {} at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-3.2.0.jar:?] {} at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:101) [forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {} } Registering PacketHandler class in Main mod class: public Mod() { PacketHandler packetHandler = new PacketHandler(); packetHandler.registerMessages(); } private void setup(final FMLCommonSetupEvent event) { //PacketHandler packetHandler = new PacketHandler(); //packetHandler.registerMessages(); } //Disclaimer: I tried it registering in both setup and main constructor - it fails both times here? PacketHandler class: public class PacketHandler { public String string = "1"; public SimpleChannel simpleChannel = NetworkRegistry.ChannelBuilder //Creaing SimpleChannel object .named(new ResourceLocation("mod", "main_channel")) .clientAcceptedVersions(string::equals) .serverAcceptedVersions(string::equals) .networkProtocolVersion(() -> string) .simpleChannel(); public void registerMessages() { int index = 0; Packet packet = new Packet (); simpleChannel.registerMessage(index++, Packet.class, Packet::encode, Packet::new, packet::handle); Packet class: public class Packet { private BlockPos blockPos; public Packet (PacketBuffer buffer) { this.blockPos = buffer.readBlockPos(); } public Packet (BlockPos blockPos) { this.blockPos = blockPos; } public Packet () { } //This constructor is only to create object without any value for PacketHandler class public void encode(PacketBuffer buffer) { buffer.writeBlockPos(this.blockPos); } public void handle(Packet message, Supplier<NetworkEvent.Context> contextSupplier) { contextSupplier.get().enqueueWork(() -> { //Thread-safe zone if (contextSupplier.get().getDirection().getOriginationSide().isClient()) { //this is always CLIENT side Where I try to send packet (and where error occurs): private PacketHandler packetHandler = new PacketHandler(); @Override //Minecraft-forge implemented class/method for Screen Gui protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { //Happens every tick, after block container is opened. Only on CLIENT packetHandler.simpleChannel.sendToServer(new Packet(container.getBlockPos())); //Error occurs here //Further code just for context: GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); assert this.minecraft != null; this.minecraft.getTextureManager().bindTexture(GUI); int relX = (this.width - this.xSize) / 2; int relY = (this.height - this.ySize) / 2; Error code suggests that it cant register, because its unavailable/locked at that phase, so it fails registering first time on game setup? (though i tried searching for keywords with ctrl-f and didnt find any errors) Also, I tried changing BlockPos to simple Int variable, still same error occured. -
[SOLVED]-kinda Packet handler / Simple channel
Mr Bonobo replied to Mr Bonobo's topic in Modder Support
This is where i register packet: public MyMod() { ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.COMMON_CONFIG); ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.CLIENT_CONFIG); // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); // Register ourselves for server and other game events we are interested in Config.loadConfig(Config.COMMON_CONFIG, FMLPaths.CONFIGDIR.get().resolve("mymod-common.toml")); Config.loadConfig(Config.CLIENT_CONFIG, FMLPaths.CONFIGDIR.get().resolve("mymod-client.toml")); //Registering packets here: PacketHandler packetHandler = new PacketHandler(); //if non-static class - doesnt work packetHandler.registerMessages(); PacketHandler.registerMessages(); //if static class - works } And im pretty sure,that BlocPos value isnt a problem, because it worked when everything was static. Though i will test that tomorrow with a simple value. (the code im showing works if its static, but the moment I try to convert everything to non-static and register it as a non-static, it fails to do so). -
[SOLVED]-kinda Packet handler / Simple channel
Mr Bonobo replied to Mr Bonobo's topic in Modder Support
Thank you for reply, I'm posting by myself first time, so I'm not familiar with this environment. And non-static is preferable, because I don't want client side to initialize value and use ram when it's not necessary (static values are initialized in both sides, even if I assigned value on server side). So by using non-static value it should be more efficient (if I'm wrong, and it uses ram only when client side requests value from a static member, please correct me, i was using c++ previously, so static and non-static members are kinda new for me) -
Hello, is it possible to make network/package sending class handler a non static member? When i try to register it as a non-static, errors occur. When all members are static, it works fine. Is it because NetworkEvent.Context must be static? Edited part for network example further bellow: Error : java.lang.IllegalArgumentException: Registration of network channels is locked Registering message: //Packet packet = new Packet(); //if handle is non-static simpleChannel.registerMessage(index++, Packet.class, Packet::encode, Packet::new, Packet::handle); //Packet::new, packet::handle; if handle is non-static // Maybe i pass handle wrong, when its non-static? Packet class: public class Packet{ private static BlockPos blockPos; //public Packet () {}; //For passing handler on non-static public Packet(PacketBuffer buffer) { Packet.blockPos = buffer.readBlockPos(); } public Packet(BlockPos blockPos) { Packet.blockPos = blockPos; } public void encode(PacketBuffer buffer) { buffer.writeBlockPos(Packet.blockPos); } public static void handle(packetmessage, Supplier<NetworkEvent.Context> contextSupplier) { //if i make this class non-static, task execution fails contextSupplier.get().enqueueWork(() -> { Edit from here: So I didnt manage to make methods non static etc..., but I managed to solve this problem by using other stuff, which completely diminished necessity of a non-static handler. Also, because I didnt manage to find detailed examples or tutorials (apart official documentation on forge website and few posts, which came in handy but coverd mostly/only basics), on how to make network packet system on new minecraft forge (1.14.4) versions, im posting my code here for future people who might stumble on the same problems: DISCLAIMER: Im not an experienced Minecraft forge mod programmer, nor good programmer in a nutshell, so this code might be non-efficient or have flaws / crashes, especially when testing on DEDICATED_SERVER (tests on LAN worked flawlessly), so read with caution. Registering network packet: public MainModCLass() { // Register the setup method for modloading FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); PacketHandler.registerMessages(); //<--Packet class } PacketHandler class: public class PacketHandler { public static String string = "1"; //<--Just a filler string public static ResourceLocation resourceLocation = new ResourceLocation("mod", "main_channel"); //<--Channel name needs to be unique and cant contain more advanced symbols public static ResourceLocation resourceLocation0 = new ResourceLocation("mod", "main_channel0"); public static final SimpleChannel simpleChannel = NetworkRegistry.ChannelBuilder //<--Registering channels .named(resourceLocation) .clientAcceptedVersions(string::equals) .serverAcceptedVersions(string::equals) .networkProtocolVersion(() -> string) .simpleChannel(); public static final SimpleChannel simpleChannel0 = NetworkRegistry.ChannelBuilder .named(resourceLocation0) .clientAcceptedVersions(string::equals) .serverAcceptedVersions(string::equals) .networkProtocolVersion(() -> string) .simpleChannel(); public static void registerMessages() { int index = 0; simpleChannel.registerMessage(index++, PacketTriggerSEG.class, PacketTriggerSEG::encode, newhandlesimpleChannel0classnewhandle PacketTriggerSEG (when the client requests the server for synchronization to begin) public class PacketTriggerSEG { private BlockPos blockPos; public PacketTriggerSEG(PacketBuffer buffer) { this.blockPos = buffer.readBlockPos(); } public PacketTriggerSEG(BlockPos blockPos) { this.blockPos = blockPos; } public void encode(PacketBuffer buffer) { buffer.writeBlockPos(this.blockPos); } public static void handle(PacketTriggerSEG message, Supplier<NetworkEvent.Context> contextSupplier) { contextSupplier.get().enqueueWork(() -> { //<--Adding a thread-safe, future-runnable task for server contextSupplier.get().getSender().getServerWorld().getTileEntity(message.blockPos). getCapability(new UtilCapabilities().UTIL_CAP).ifPresent(st -> { //<--Getting server world and finding entity in it with a custom capability assigned to tile entity (from other classes which arent shown here) int tickCounter = st.getCounterForTicks(); //<--getCounterForTicks() - function from manually created custom capability PacketHandler.simpleChannel0.send(PacketDistributor.PLAYER.with(() -> //<--Sending packet back to client, to sync value on both sides contextSupplier.get().getSender()), new ValueSynchronizeSEG(message.blockPos, tickCounter)); }); }); contextSupplier.get().setPacketHandled(true); //<--Setting packed as handled, so main thread knows its successful and doesnt show warnings/crashes when it completes } } ValueSynchronizeSEG (when packet of requested info from the server arrives back at the client): public class ValueSynchronizeSEG { private BlockPos blockPos; private int tickCounter; public ValueSynchronizeSEG(PacketBuffer buffer) { this.blockPos = buffer.readBlockPos(); this.tickCounter = buffer.readInt(); } public ValueSynchronizeSEG(BlockPos blockPos, int tickCounter) { this.blockPos = blockPos; this.tickCounter = tickCounter; } public void encode(PacketBuffer buffer) { buffer.writeBlockPos(this.blockPos); buffer.writeInt(this.tickCounter); } public static void handle(ValueSynchronizeSEG message, Supplier<NetworkEvent.Context> contextSupplier) { contextSupplier.get().enqueueWork(() -> { Minecraft.getInstance().world.getTileEntity(message.blockPos).getCapability(new UtilCapabilities().UTIL_CAP).ifPresent( //<--Setting server side capability values ct -> ct.setCounterForTicks(message.tickCounter)); }); contextSupplier.get().setPacketHandled(true); } } Requesting for packet from only client-side: private int loop; <--Simple int to make packets to be sent every second-tick, not every tick @Override public void tick() { if(loop == 1) { PacketHandler.simpleChannel.sendToServer(new PacketTriggerSEG(container.getBlockPos())); loop = 0; } else { loop++; } } //This class is a client-side class, which extends ContainerScreen<YourTileEntityContainerScreenClass> and is efficient, because packets are sent ONLY when GUI is opened by a PlayerEntity. If you rode all this, I hope it was of some help to you. Enjoy.