Jump to content

Cobra111783

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by Cobra111783

  1. 4 hours ago, Zeher_Monkey said:

    Yes, look into AbstractFurnaceTileEntity and FurnaceScreen to see how vanilla handles values like the Burn Time, and the Cook Progress, ie the white arrow inside the Furnace GUI.

    Cool. I just wanted to make sure that was the best way to handle things with capabilities (since I'll have to copy the "current energy" from the EnergyStorage into the trackedIntArray whenever it changes). Thanks! 🙂

  2. I currently have a block that uses the Forge Energy capability (via EnergyStorage). I want to display a power bar on the UI, but otherwise don't need the energy level on the client-side. I was doing this by syncing the TilleEntity's energy level, but this seems like a lot of unnecessary network traffic. My current thought is to used a trackedIntArray to store a copy of the current energy level and pass that (through the container) to the client's screen. Is this the best way to do this kind of syncing, or is there a more efficient way that is recommended?

  3. 39 minutes ago, diesieben07 said:

    Yes, that is indeed what it does. If you use Minecraft#enqueue you schedule something to run on the client main thread, MinecraftServer#enqueue runs it on the server main thread. Both Minecraft as well as MinecraftServer also implement the Executor interface, as such you can use e.g. CompletableFuture.supplyAsync with it.

     

    Switching to enqueueing it on the server (vs client) fixed it. Thanks for your help!

     

    For anyone else looking for the solution, I used something like this:

    var server = ServerLifecycleHooks.getCurrentServer();
    server.enqueue(TickDelayedTask(server.getTicketCounter(), () -> { [YOUR TASK HERE] }));

     

    (See below for better solution)

  4.   

    6 hours ago, diesieben07 said:

    You cannot.

    Minecraft's data structures are not threadsafe. You cannot access them from other threads.

     

    No, it did not work. It might appear to work, most of the time. But as is the issue with threading issues, it will randomly fail with strange error messages every now and then - and then appear to work again the next time you try.

    Hrm... I hadn't considered thread safety on MC's end... (derp!) Thanks for the clarification!

     

    Is there a built-in mechanism to schedule a task to occur inside the main thread? I thought that's what Minecraft.getInstance().enqueue(...) was supposed to do, but maybe I'm misunderstanding the correct uses of that method (since it appears to run things inside a rendering thread).

  5. I need to retrieve a TileEntity from another thread. I have the BlockPos of the entity, as well as the appropriate ServerWorld. However, I keep running afoul of this line in net.minecraft.world.World (line 639):

    } else if (!this.isRemote && Thread.currentThread() != this.mainThread) {
        return null;
    } 

    (Specifically, it's detecting that the current thread isn't the main thread)

     

    I've also tried variations of this with no luck (Kotlin code):

    val queue = SynchronousQueue<TileEntity>()
    Minecraft.getInstance().enqueue {
        val tileEntity = dimension.getTileEntity(BlockPos(destination.x, destination.y, destination.z))
        queue.put(tileEntity)
    }
    val tileEntity = queue.take()

     

    However, this seems to run on a rendering thread rather than the "main" thread. Is there any way to get a TileEntity from another thread? (FYI, the part of TileEntity in that I'm planning to access uses thread safe code, so I'm not concerned about that part of the equation.)

     

    (Side note: Just getting the TileEntity from the ServerWorld worked in 1.12, so I'm guessing that "safety check" is new...)

  6.   

    2 hours ago, diesieben07 said:

    MinecraftServer#getWorld

     

    Thanks for the info!

     

    What's the correct way to get the MinecraftServer instance? I see a lot of references online to FMLCommonHandler.instance().getMinecraftServerInstance(), but that doesn't seem to exist anymore.

  7. I'm currently trying to pick up my mostly-completed 1.12 mod and update  it to 1.16. As part of the mod, you can send a package to a destination using coordinates (dimension name + x/y/z). In 1.12, I retrieved the target world via this code:

    var dimension = DimensionManager.getWorld(destination.dimension)

     

    And then retrieved the tile entity at the target location via:

    var tileEntity = dimension.getTileEntity(BlockPos(destination.x, destination.y, destination.z))

     

    However, so far I have been unable to find a replacement in the 1.16 API for the  DimensionManager.getWorld call. Can anyone suggest a way to look up a world via its name?

  8. I'm trying to build an inventory that has an inventory where one slot can only be emptied via the GUI, but it can be inserted into by the GUI or other process (e.g. hopper). There is also a second slot that can be interacted with normally. Is there a preferred way to do this? The only solution I've come up with so far is to have two ItemStackHandlers that share the same backing NonNullList<ItemStack>, but that seems to cause strange client/server desync issues.

×
×
  • Create New...

Important Information

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