Adjust NetworkEvent#enqueueWork to match vanilla logic
In singleplayer our packet work could get delayed until the next tick, breaking the expectation of packet read order. Fixes that using NetworkHooks.openGui would result in missing inventory data on the client
This commit is contained in:
parent
1434419e47
commit
da22fd40bf
2 changed files with 14 additions and 9 deletions
|
@ -21,8 +21,6 @@ package net.minecraftforge.fml.network;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListenableFutureTask;
|
||||
import io.netty.util.Attribute;
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
|
@ -37,6 +35,7 @@ import net.minecraftforge.eventbus.api.Event;
|
|||
import net.minecraftforge.fml.LogicalSidedProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class NetworkEvent extends Event
|
||||
|
@ -176,13 +175,16 @@ public class NetworkEvent extends Event
|
|||
return packetHandled;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> ListenableFuture<V> enqueueWork(Runnable runnable) {
|
||||
ListenableFutureTask<V> f = ListenableFutureTask.create(runnable, null);
|
||||
|
||||
LogicalSidedProvider.WORKQUEUE.<ThreadTaskExecutor<?> >get(getDirection().getReceptionSide()).execute(f);
|
||||
|
||||
return f;
|
||||
public CompletableFuture<Void> enqueueWork(Runnable runnable) {
|
||||
ThreadTaskExecutor<?> executor = LogicalSidedProvider.WORKQUEUE.get(getDirection().getReceptionSide());
|
||||
// Must check ourselves as Minecraft will sometimes delay tasks even when they are received on the client thread
|
||||
// Same logic as ThreadTaskExecutor#runImmediately without the join
|
||||
if (!executor.isOnExecutionThread()) {
|
||||
return executor.func_213165_a(runnable); // Use the internal method so thread check isn't done twice
|
||||
} else {
|
||||
runnable.run();
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -331,6 +331,9 @@ protected net.minecraft.tileentity.HopperTileEntity func_145887_i()Z # updateHop
|
|||
# DataFixer
|
||||
public net.minecraft.util.datafix.DataFixer field_188262_d # version
|
||||
|
||||
# ThreadTaskExecutor
|
||||
public net.minecraft.util.concurrent.ThreadTaskExecutor func_213165_a(Ljava/lang/Runnable;)Ljava/util/concurrent/CompletableFuture; # func_213165_a
|
||||
|
||||
# AbstractSkeletonEntity
|
||||
protected net.minecraft.entity.monster.AbstractSkeletonEntity func_190727_o()Lnet/minecraft/util/SoundEvent; # getStepSound - make AbstractSkeletonEntity implementable
|
||||
|
||||
|
|
Loading…
Reference in a new issue