Jump to content

Codemetry

Members
  • Posts

    17
  • Joined

  • Last visited

Posts posted by Codemetry

  1. 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. 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?

  3. 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.

  4. 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?

  5. 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");
    		}
    	}
    }

     

  6. 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");
    		}
    	}

     

  7. 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.

×
×
  • Create New...

Important Information

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