Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions patchwork-god-classes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies {
implementation project(path: ':patchwork-events-rendering', configuration: 'dev')
implementation project(path: ':patchwork-events-world', configuration: 'dev')
implementation project(path: ':patchwork-loot', configuration: 'dev')
implementation project(path: ':patchwork-networking', configuration: 'dev')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.fml.client;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.network.ClientConnection;

import net.patchworkmc.impl.networking.ClientNetworkingEvents;

public class ClientHooks {
public static void firePlayerLogin(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity player, final ClientConnection clientConnection) {
ClientNetworkingEvents.firePlayerLogin(interactionManager, player, clientConnection);
}

public static void firePlayerLogout(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity player) {
ClientNetworkingEvents.firePlayerLogout(interactionManager, player);
}

public static void firePlayerRespawn(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity oldPlayer, final ClientPlayerEntity newPlayer, final ClientConnection clientConnection) {
ClientNetworkingEvents.firePlayerRespawn(interactionManager, oldPlayer, newPlayer, clientConnection);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.minecraftforge.client.event;

import net.minecraftforge.eventbus.api.Event;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.network.ClientConnection;

/**
* Client-side events fired on changes to player connectivity.
*/
public class ClientPlayerNetworkEvent extends Event {
private final ClientPlayerInteractionManager playerInteractionManager;
private final ClientPlayerEntity player;
private final ClientConnection clientConnection;

ClientPlayerNetworkEvent(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity player, final ClientConnection clientConnection) {
this.playerInteractionManager = interactionManager;
this.player = player;
this.clientConnection = clientConnection;
}

/**
* @return The ClientPlayerInteractionManager instance for the client side.
*/
public ClientPlayerInteractionManager getController() {
return this.playerInteractionManager;
}

/**
* @return The player instance, if present (otherwise, returns null).
*/
public ClientPlayerEntity getPlayer() {
return this.player;
}

/**
* @return The network connection, if present (otherwise, returns null).
*/
public ClientConnection getNetworkManager() {
return this.clientConnection;
}

/**
* Fired when the player logs out.
*
* <p>Note: This might also be fired when a new integrated server is being created.</p>
*/
public static class LoggedInEvent extends ClientPlayerNetworkEvent {
public LoggedInEvent(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity player, final ClientConnection clientConnection) {
super(interactionManager, player, clientConnection);
}
}

/**
* Fired when the player logs out.
*
* <p>Note: This might also fire when a new integrated server is being created.</p>
*/
public static class LoggedOutEvent extends ClientPlayerNetworkEvent {
public LoggedOutEvent(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity player, final ClientConnection clientConnection) {
super(interactionManager, player, clientConnection);
}
}

/**
* Fired when the player object respawns, such as dimension changes.
*/
public static class RespawnEvent extends ClientPlayerNetworkEvent {
private final ClientPlayerEntity oldPlayer;

public RespawnEvent(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity oldPlayer, final ClientPlayerEntity newPlayer, final ClientConnection clientConnection) {
super(interactionManager, newPlayer, clientConnection);
this.oldPlayer = oldPlayer;
}

public ClientPlayerEntity getOldPlayer() {
return this.oldPlayer;
}

public ClientPlayerEntity getNewPlayer() {
return super.getPlayer();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.impl.networking;

import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.network.ClientConnection;

public class ClientNetworkingEvents {
public static void firePlayerLogin(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity player, final ClientConnection clientConnection) {
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.LoggedInEvent(interactionManager, player, clientConnection));
}

public static void firePlayerLogout(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity player) {
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.LoggedOutEvent(interactionManager, player, player != null ? player.networkHandler != null ? player.networkHandler.getConnection() : null : null));
}

public static void firePlayerRespawn(final ClientPlayerInteractionManager interactionManager, final ClientPlayerEntity oldPlayer, final ClientPlayerEntity newPlayer, final ClientConnection clientConnection) {
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.RespawnEvent(interactionManager, oldPlayer, newPlayer, clientConnection));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

package net.patchworkmc.mixin.networking.client;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;

import net.patchworkmc.impl.networking.ClientNetworkingEvents;

@Mixin(MinecraftClient.class)
public class MixinMinecraftClient {
@Shadow
public ClientPlayerInteractionManager interactionManager;

@Shadow
public ClientPlayerEntity player;

@Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;reset()V", shift = At.Shift.AFTER))
public void patchwork$hookDisconnect(CallbackInfo ci) {
ClientNetworkingEvents.firePlayerLogout(this.interactionManager, this.player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;
import net.minecraft.world.dimension.DimensionType;

import net.patchworkmc.impl.networking.ClientNetworkingEvents;

@Mixin(ClientPlayNetworkHandler.class)
public abstract class MixinClientPlayNetworkHandler {
@Shadow
private MinecraftClient client;

@Shadow
public abstract ClientConnection getConnection();

Expand All @@ -42,4 +52,16 @@ public abstract class MixinClientPlayNetworkHandler {
callback.cancel();
}
}

@Inject(method = "onGameJoin", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;getEntityId()I"))
public void patchwork$hookGameJoin(CallbackInfo ci) {
ClientNetworkingEvents.firePlayerLogin(this.client.interactionManager, this.client.player, this.client.getNetworkHandler().getConnection());
}

@Inject(method = "onPlayerRespawn",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;addPlayer(ILnet/minecraft/client/network/AbstractClientPlayerEntity;)V"),
locals = LocalCapture.CAPTURE_FAILHARD)
public void patchwork$hookPlayerRespawn(PlayerRespawnS2CPacket packet, CallbackInfo ci, DimensionType dimensionType, ClientPlayerEntity clientPlayerEntity, int i, String string, ClientPlayerEntity clientPlayerEntity2) {
ClientNetworkingEvents.firePlayerRespawn(this.client.interactionManager, clientPlayerEntity, clientPlayerEntity2, clientPlayerEntity2.networkHandler.getConnection());
}
}
1 change: 1 addition & 0 deletions patchwork-networking/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"mixins": [
"patchwork-networking.accessor.mixins.json",
"patchwork-networking.client.mixins.json",
"patchwork-networking.handler.mixins.json",
"patchwork-networking.packet.mixins.json"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"package": "net.patchworkmc.mixin.networking.client",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinMinecraftClient"
],
"injectors": {
"defaultRequire": 1
}
}