Codemetry
-
Posts
17 -
Joined
-
Last visited
Posts posted by Codemetry
-
-
4 hours ago, diesieben07 said:
There is no better way than to check every tick.
How do I check if the chest contents are loaded?
-
3 minutes ago, diesieben07 said:
Doesn't matter.
There is no event. The chest contents could change at any point. Please explain what exactly you are trying to achieve.
Read the contents of a chest upon opening, and detect its changes.
I wanted the packet name to check the source code and see if there is any way I can detect.
-
2 hours ago, diesieben07 said:
Inventory contents are sent later in a separate packet.
Do you know the packet type name?
Which event should I handle and access the chest contents inside the event handler?
-
16 hours ago, diesieben07 said:
EntityPlayer#openContainer to get the currently open Container. Then Container#inventorySlots to get all Slots. Then Slot#getStack to get the ItemStack in that slot.
Firstly, EntityPlayer#openContainer is assigned the container of the opened chest AFTER the initialization (GuiScreen#initGui) of the opened GuiChest (the container is stored in GuiContainer). So, I changed to try to access the chest contents in InitGuiEvent.Post event handler.
Secondly, I found that the container stored in GuiContainer is a ContainerChest containing the player inventory AND the chest inventory. Therefore, it is not accurate to access the container and directly get the item stacks via it. Then, I found that ContainerChest#getLowerChestInventory returns the chest inventory (somehow it is called lower inventory).
Finally, I checked the runtime type of the inventory returned by ContainerChest#getLowerChestInventory. It turns out to be ContainerLocalMenu. The only place which constructs new ContainerLocalMenus is NetHandlerPlayClient#handleOpenWindow. However, the method accepts a packet that does not store the chest inventory contents.
Where did I go wrong? How do I access the chest contents?
-
15 hours ago, diesieben07 said:
EntityPlayer#openContainer to get the currently open Container. Then Container#inventorySlots to get all Slots. Then Slot#getStack to get the ItemStack in that slot.
It doesn't work. It seems to always access the player inventory.
-
How do I read the items in an opened chest (chest gui opened), on client side?
-
How do I intercept chat message before sent from client to server? Is there an event for it?
-
When inventory opened, KeyInputEvent and MouseEvent do not get fired. How do I detect key inputs and mouse inputs when inventory is opened?
-
36 minutes ago, Draco18s said:
mc here is almost certainly the result of calling Minecraft.getMinecraft(), which won't work on a server (it'll crash the server).
I am working on a client side mod.
19 hours ago, MairwunNx said:if you updated to 1.14.4: Where did you get the method `addChatMessage` and `ChatComponentText` class?
Sorry I was in a rush and copied from my old java file.
-
Bump.
I have updated to 1.14.4 - 28.1.0.
I did some testing and found that:
- EntityJoinWorldEvent is fired once when joining a server (and a world) from the multiplayer menu
- EntityJoinWorldEvent is fired multiple times (usually 6 - 10) when switching between worlds on a server or servers on a bungee network
- The Worlds returned by EntityJoinWorldEvents are not the same instance
- The EntityJoinWorldEvents are not the same instance (that means I did not register more than once)
I have already added the following check into EntityJoinWorldEvent handler
mc.thePlayer == event.entity
Here is my handler in case:
@SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { if (mc.thePlayer == event.entity) { mc.thePlayer.addChatMessage( new ChatComponentText("hello")); } }
Does anyone know why this is happening?
-
When setting up the project, I executed "gradlew genEclipseRuns" and "gradlew eclipse", but there aren't any run configurations (Client / Server).
-
28 minutes ago, Animefan8888 said:
Sorry 1.8.9 is an extremely outdated version and we no longer support it on this forum. Please update to receive support. Once a forum moderator sees this they will lock it.
Updated
-
2 minutes ago, SerpentDagger said:
It would be helpful if you could show the whole classes, as the event system is impacted by that.
package com.example.examplemod; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ServerData; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION) public class ExampleMod { public static final String MODID = "examplemod"; public static final String VERSION = "1.0"; Minecraft mc; @EventHandler public void preInit(FMLPreInitializationEvent event) { mc = Minecraft.getMinecraft(); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { if (!event.world.isRemote) { mc.thePlayer.sendChatMessage("hello"); } } }
-
1 hour ago, SerpentDagger said:
What's the current state of the code?
By this do you mean you want to send a message to the player, or send a message via the player?
via the player to the server
1 hour ago, Animefan8888 said:Post your code. And this includes how you registered your event handler.
Minecraft mc; @EventHandler public void preInit(FMLPreInitializationEvent event) { mc = Minecraft.getMinecraft(); MinecraftForge.EVENT_BUS.register(this); }
@SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { if (!event.world.isRemote) { mc.thePlayer.sendChatMessage("hello"); } }
-
16 minutes ago, Animefan8888 said:
The even is fired on both the client and the server. Make sure to only do your code on the logical server by checking if World#isRemote is false.
I am new to forge modding, so please forgive me for my basic questions.
I am trying to make the player send a chat message when joined a server world. Before ensuring World#isRemote is false, the chat message is sent 3 times every 3 seconds. When I added the check, no chat message is sent.
-
Why is it fired multiple times when a player joins a server (and a world)? Are there any alternative events?
Read items in chest when opened on client side
in Modder Support
Posted
Thanks for helping me.