-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tick fake players in network updating phase #1847
base: master
Are you sure you want to change the base?
Changes from 5 commits
bdad60b
943c5fb
54f88ba
8147282
303e099
9fc4731
b95a05e
b3ce054
426f493
a37c9d9
e18c7d8
82e0eb5
0d8d6f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package carpet.mixins; | ||
|
||
import carpet.CarpetSettings; | ||
import carpet.fakes.ServerPlayerInterface; | ||
import carpet.patches.FakePlayerManager; | ||
import net.minecraft.server.network.ServerConnectionListener; | ||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ServerConnectionListener.class) | ||
public class ServerConnectionListener_fakePlayersMixin { | ||
@Inject( | ||
method = "tick", | ||
at = @At("RETURN") | ||
) | ||
private void tickFakePlayers(CallbackInfo ci) { | ||
if (!CarpetSettings.fakePlayerTicksInEU) { | ||
for (ServerGamePacketListenerImpl connection : FakePlayerManager.connections) { | ||
// from ServerGamePacketListenerImpl#tick | ||
|
||
connection.player.xo = connection.player.getX(); | ||
connection.player.yo = connection.player.getY(); | ||
connection.player.zo = connection.player.getZ(); | ||
|
||
// action packet update | ||
((ServerPlayerInterface) connection.player).getActionPack().onUpdate(); | ||
zly2006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
connection.player.doTick(); | ||
// connection.player.absMoveTo(connection.firstGoodX, connection.firstGoodY, connection.firstGoodZ, connection.player.getYRot(), connection.player.getXRot()); | ||
|
||
// todo: vehicle? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll suggest to mark the PR as a draft, if it's not completed yet |
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,4 +143,4 @@ private void endRandomTicks(CallbackInfo ci) { | |
} | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package carpet.mixins; | ||
|
||
import carpet.CarpetSettings; | ||
import carpet.fakes.ServerPlayerInterface; | ||
import carpet.helpers.EntityPlayerActionPack; | ||
import carpet.patches.EntityPlayerMPFake; | ||
import com.mojang.authlib.GameProfile; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ClientInformation; | ||
|
@@ -18,6 +20,7 @@ public abstract class ServerPlayer_actionPackMixin implements ServerPlayerInterf | |
{ | ||
@Unique | ||
public EntityPlayerActionPack actionPack; | ||
|
||
@Override | ||
public EntityPlayerActionPack getActionPack() | ||
{ | ||
|
@@ -33,6 +36,16 @@ private void onServerPlayerEntityContructor(MinecraftServer minecraftServer, Ser | |
@Inject(method = "tick", at = @At(value = "HEAD")) | ||
private void onTick(CallbackInfo ci) | ||
{ | ||
actionPack.onUpdate(); | ||
if (CarpetSettings.fakePlayerTicksInEU) { | ||
actionPack.onUpdate(); | ||
} | ||
} | ||
|
||
@Inject(method = "doTick", at = @At(value = "HEAD")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are alternating where real player's action pack gets ticked right? then the same as https://github.com/gnembon/fabric-carpet/pull/1847/files#r1412213260 |
||
private void tickActionPack(CallbackInfo ci) | ||
{ | ||
if (!((Object) this instanceof EntityPlayerMPFake)) { | ||
actionPack.onUpdate(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package carpet.patches; | ||
|
||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FakePlayerManager { | ||
public static List<ServerGamePacketListenerImpl> connections = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: use concurrency-proof containers to handle potential concurrent access in certain situations (e.g. using mods) |
||
|
||
public static void reset() { | ||
connections.clear(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package carpet.patches; | ||
|
||
import net.minecraft.Util; | ||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.contents.TranslatableContents; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.game.ClientboundBlockChangedAckPacket; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.network.CommonListenerCookie; | ||
|
@@ -23,6 +25,11 @@ public void send(final Packet<?> packetIn) | |
{ | ||
} | ||
|
||
@Override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any explanations for the changes in these files? they don't seem related |
||
protected void keepConnectionAlive() | ||
{ | ||
} | ||
|
||
@Override | ||
public void disconnect(Component message) | ||
{ | ||
|
@@ -42,6 +49,11 @@ public void teleport(double d, double e, double f, float g, float h, Set<Relativ | |
} | ||
} | ||
|
||
@Override | ||
public void tick() | ||
{ | ||
System.out.println("NetHandlerPlayServerFake tick -- not implemented yet"); | ||
} | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a default value that changes the existing behavior is BAD. It breaks people's contraptions that rely on the old behavior sliently