Remove a mixin.

This commit is contained in:
modmuss50 2022-11-19 18:01:22 +00:00
parent d84eec20cb
commit 193be50df8
6 changed files with 65 additions and 32 deletions

View file

@ -55,6 +55,7 @@ import reborncore.common.network.ServerBoundPackets;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.recipes.PaddedShapedRecipe;
import reborncore.common.screen.ServerPlayerEntityScreenHandlerHelper;
import reborncore.common.util.CalenderUtils;
import reborncore.common.util.GenericWrenchHelper;
import team.reborn.energy.api.EnergyStorage;
@ -135,6 +136,8 @@ public class RebornCore implements ModInitializer {
}
return null;
});
ServerPlayerEntityScreenHandlerHelper.class.getName();
}
public static EnvType getSide() {

View file

@ -44,7 +44,6 @@ import reborncore.common.network.ClientBoundPackets;
import reborncore.common.network.NetworkManager;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.RangeUtil;
import reborncore.mixin.ifaces.ServerPlayerEntityScreenHandler;
import java.util.HashMap;
import java.util.List;
@ -161,9 +160,8 @@ public class BuiltScreenHandler extends ScreenHandler {
return;
}
if (screenHandlerListener instanceof ServerPlayerEntityScreenHandler serverPlayerEntityScreenHandler) {
NetworkManager.sendToPlayer(ClientBoundPackets.createPacketSendObject(screenHandler, updatedValues), serverPlayerEntityScreenHandler.rc_getServerPlayerEntity());
}
ServerPlayerEntityScreenHandlerHelper.getServerPlayerEntity(screenHandlerListener)
.ifPresent(serverPlayerEntity -> NetworkManager.sendToPlayer(ClientBoundPackets.createPacketSendObject(screenHandler, updatedValues), serverPlayerEntity));
}
@Override

View file

@ -0,0 +1,59 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.common.screen;
import net.minecraft.screen.ScreenHandlerListener;
import net.minecraft.server.network.ServerPlayerEntity;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.Optional;
// Helper to access the ServerPlayerEntity instance from a ScreenHandlerListener
public class ServerPlayerEntityScreenHandlerHelper {
private static final String CLASS_NAME = ServerPlayerEntity.class.getName() + "$2";
private static final String FIELD_NAME = "field_29183";
private static final Class<?> CLAZZ;
private static final VarHandle VAR_HANDLE;
static {
try {
CLAZZ = Class.forName(CLASS_NAME);
VAR_HANDLE = MethodHandles.privateLookupIn(CLAZZ, MethodHandles.lookup())
.findVarHandle(CLAZZ, FIELD_NAME, ServerPlayerEntity.class);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
throw new ExceptionInInitializerError(e);
}
}
public static Optional<ServerPlayerEntity> getServerPlayerEntity(ScreenHandlerListener screenHandlerListener) {
if (screenHandlerListener.getClass() == CLAZZ) {
return Optional.of((ServerPlayerEntity) VAR_HANDLE.get(screenHandlerListener));
}
return Optional.empty();
}
}

View file

@ -1,18 +0,0 @@
package reborncore.mixin.common;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import reborncore.mixin.ifaces.ServerPlayerEntityScreenHandler;
@Mixin(targets = "net.minecraft.server.network.ServerPlayerEntity$2")
public class MixinServerPlayerEntity implements ServerPlayerEntityScreenHandler {
@Shadow
ServerPlayerEntity field_29183;
@Override
public ServerPlayerEntity rc_getServerPlayerEntity() {
return field_29183;
}
}

View file

@ -1,8 +0,0 @@
package reborncore.mixin.ifaces;
import net.minecraft.server.network.ServerPlayerEntity;
public interface ServerPlayerEntityScreenHandler {
ServerPlayerEntity rc_getServerPlayerEntity();
}

View file

@ -7,8 +7,7 @@
"MixinCraftingResultSlot",
"MixinItemEntity",
"MixinLivingEntity",
"MixinPlayerEntity",
"MixinServerPlayerEntity"
"MixinPlayerEntity"
],
"injectors": {
"defaultRequire": 1