Skip to content

Commit

Permalink
Port GuiAPI, ModLoader, ModOptionsAPI, PlayerAPI and Reforged mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Jan 1, 2025
1 parent 6f41441 commit e51b941
Show file tree
Hide file tree
Showing 31 changed files with 316 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.menu.OptionsScreen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;

@Mixin(OptionsScreen.class)
public class OptionsScreenMixin extends Screen {
@Inject(method = "initVanillaScreen", at = @At("RETURN"))
@Inject(method = "init", at = @At("RETURN"))
private void guiapi$init(CallbackInfo ci) {
// TODO: This string needs to be localized, eventually.
if (!SettingWidget.all.isEmpty()) this.buttons.add(new ButtonWidget(300, this.width / 2 - 200, this.height / 6 + 192, "GuiAPI's Global Mod Settings"));
Expand All @@ -24,7 +24,7 @@ public class OptionsScreenMixin extends Screen {
@Inject(method = "buttonClicked", at = @At("RETURN"))
private void guiapi$buttonClicked(ButtonWidget par1, CallbackInfo ci) {
if (par1.active && par1.id == 300) {
this.client.options.saveOptions();
this.minecraft.options.save();
ModSettingScreen.guiContext = "";
SettingWidget.updateAll();
ModScreen.show(new ModSelect(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public abstract class DispenserBlockMixin {
* @reason Implements {@link ModLoader#DispenseEntity(World, double, double, double, int, int, ItemStack)
* ModLoader's dispense entity callback}
*/
@Inject(method = "dispense", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/item/ItemStack;itemId:I", ordinal = 0))
@Inject(method = "method_1774", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/item/ItemStack;itemId:I", ordinal = 0))
private void handleDispense(World i, int x, int y, int z, Random random, CallbackInfo ci,
@Local(ordinal = 0) World world, @Local(ordinal = 0) double posX, @Local(ordinal = 1) double posY,
@Local(ordinal = 2) double posZ, @Local(ordinal = 4) int j, @Local(ordinal = 5) int k, @Local(ordinal = 0) ItemStack itemStack) {
if (ModLoader.DispenseEntity(world, posX, posY, posZ, j, k, itemStack)) {
world.playWorldEvent(2000, x, y, z, j + 1 + (k + 1) * 3);
world.method_230(2000, x, y, z, j + 1 + (k + 1) * 3);
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package io.github.betterthanupdates.modloader.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import modloader.ModLoader;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
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.CallbackInfoReturnable;

import net.minecraft.block.FurnaceBlock;
import net.minecraft.entity.BlockEntity;
import net.minecraft.entity.block.FurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.FurnaceBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;

Expand All @@ -23,21 +19,23 @@ public abstract class FurnaceBlockEntityMixin extends BlockEntity implements Inv
@Shadow
private ItemStack[] inventory;

@WrapWithCondition(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/item/ItemStack;count:I", opcode = Opcodes.PUTFIELD))
@WrapWithCondition(method = "method_1076", at = @At(value = "FIELD", target = "Lnet/minecraft/item/ItemStack;count:I", opcode = Opcodes.PUTFIELD))
private boolean modloader$tick(ItemStack instance, int value) {
if (this.inventory[1].getItem().hasContainerItemType()) {
this.inventory[1] = new ItemStack(this.inventory[1].getItem().getContainerItemType());
if (this.inventory[1].getItem().hasCraftingReturnItem()) {
this.inventory[1] = new ItemStack(this.inventory[1].getItem().getCraftingReturnItem());
return false;
}

return true;
}

@Inject(method = "getFuelTime", cancellable = true, at = @At("RETURN"))
private void modloader$getFuelTime(ItemStack par1, CallbackInfoReturnable<Integer> cir) {
if (par1 != null && cir.getReturnValue() == 0) {
@ModifyReturnValue(method = "getFuelTime", at = @At("RETURN"))
private int modloader$getFuelTime(int original, @Local(ordinal = 0, argsOnly = true) ItemStack par1) {
if (par1 != null && original == 0) {
int j = par1.getItem().id;
cir.setReturnValue(ModLoader.AddAllFuel(j));
return ModLoader.AddAllFuel(j);
}

return original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
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.container.slot.FurnaceOutputSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.FurnaceOutputSlot;

@Mixin(FurnaceOutputSlot.class)
public abstract class FurnaceOutputSlotMixin {
@Shadow
private PlayerEntity player;

@Inject(method = "onCrafted", at = @At(value = "INVOKE", target = "Lnet/minecraft/container/slot/Slot;onCrafted(Lnet/minecraft/item/ItemStack;)V"))
@Inject(method = "onCrafted", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;onCrafted(Lnet/minecraft/item/ItemStack;)V"))
private void modloader$onCrafted(ItemStack par1, CallbackInfo ci) {
ModLoader.TakenFromFurnace(this.player, par1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@
import modloadermp.NetClientHandlerEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_454;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.network.ClientNetworkHandler;
import net.minecraft.entity.Entity;
import net.minecraft.network.ClientPlayPacketHandler;
import net.minecraft.network.PacketHandler;
import net.minecraft.packet.play.EntitySpawnS2CPacket;
import net.minecraft.packet.play.OpenContainerS2CPacket;
import net.minecraft.network.NetworkHandler;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket;
import net.minecraft.world.World;

@Environment(EnvType.CLIENT)
@Mixin(ClientPlayPacketHandler.class)
public abstract class ClientPlayPacketHandlerMixin extends PacketHandler {
@Mixin(ClientNetworkHandler.class)
public abstract class ClientPlayPacketHandlerMixin extends NetworkHandler {
@Shadow
private ClientWorld world;
private class_454 field_1973;

@Shadow
protected abstract Entity getEntity(int i);
protected abstract Entity method_1645(int i);

/**
* @author StationAPI
Expand All @@ -47,13 +46,13 @@ public abstract class ClientPlayPacketHandlerMixin extends PacketHandler {
double d1 = (double) packet.y / 32.0;
double d2 = (double) packet.z / 32.0;

NetClientHandlerEntity netclienthandlerentity = ModLoaderMp.HandleNetClientHandlerEntities(packet.type);
NetClientHandlerEntity netclienthandlerentity = ModLoaderMp.HandleNetClientHandlerEntities(packet.entityType);

if (netclienthandlerentity != null) {
try {
entity = netclienthandlerentity.entityClass
.getConstructor(World.class, Double.TYPE, Double.TYPE, Double.TYPE)
.newInstance(this.world, d, d1, d2);
.newInstance(this.field_1973, d, d1, d2);

if (netclienthandlerentity.entityHasOwner) {
Field field = netclienthandlerentity.entityClass.getField("owner");
Expand All @@ -62,7 +61,7 @@ public abstract class ClientPlayPacketHandlerMixin extends PacketHandler {
throw new Exception(String.format("Entity's owner field must be of type Entity, but it is of type %s.", field.getType()));
}

Entity entity1 = this.getEntity(packet.flag);
Entity entity1 = this.method_1645(packet.entityData);

if (entity1 == null) {
ModLoaderMp.Log("Received spawn packet for entity with owner, but owner was not found.");
Expand All @@ -78,7 +77,7 @@ public abstract class ClientPlayPacketHandlerMixin extends PacketHandler {
}
} catch (Exception e) {
ModLoader.getLogger().throwing("NetClientHandler", "handleVehicleSpawn", e);
ModLoader.ThrowException(String.format("Error initializing entity of type %s.", packet.type), e);
ModLoader.ThrowException(String.format("Error initializing entity of type %s.", packet.entityType), e);
}
}

Expand All @@ -89,9 +88,9 @@ public abstract class ClientPlayPacketHandlerMixin extends PacketHandler {
* @author Risugami
* @reason ModLoaderMP can handle custom container GUIs
*/
@Inject(method = "onOpenContainer", at = @At("TAIL"))
private void modloader$openContainer(OpenContainerS2CPacket packet, CallbackInfo ci) {
int type = packet.inventoryType;
@Inject(method = "onOpenScreen", at = @At("TAIL"))
private void modloader$openContainer(OpenScreenS2CPacket packet, CallbackInfo ci) {
int type = packet.screenHandlerId;
switch (type) {
case 0:
case 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.github.betterthanupdates.modloader.mixin.client;

import net.minecraft.network.packet.play.DisconnectPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import net.minecraft.packet.misc.DisconnectPacket;

@Mixin(DisconnectPacket.class)
public abstract class DisconnectPacketMixin {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@
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.gui.screen.DisconnectingScreen;
import net.minecraft.client.gui.screen.DisconnectedScreen;
import net.minecraft.client.gui.screen.Screen;

@Environment(EnvType.CLIENT)
@Mixin(DisconnectingScreen.class)
@Mixin(DisconnectedScreen.class)
public abstract class DisconnectingScreenMixin extends Screen {
@Shadow
private String line2;
private String reason;

/**
* @author Risugami
* @reason ModLoaderMP expects multi-line disconnect messages,
* and they need to be displayed correctly.
*/
@Inject(method = "render", cancellable = true, at = @At(value = "INVOKE", ordinal = 0,
target = "Lnet/minecraft/client/gui/screen/DisconnectingScreen;drawTextWithShadowCentred(Lnet/minecraft/client/render/TextRenderer;Ljava/lang/String;III)V"))
target = "Lnet/minecraft/client/gui/screen/DisconnectedScreen;drawCenteredTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Ljava/lang/String;III)V"))
private void modloader$render(int j, int f, float delta, CallbackInfo ci) {
String[] descriptionSplit = this.line2.split("\n");
String[] descriptionSplit = this.reason.split("\n");

for (int k = 0; k < descriptionSplit.length; k++) {
this.drawTextWithShadowCentred(this.textRenderer, descriptionSplit[k],
this.drawCenteredTextWithShadow(this.textRenderer, descriptionSplit[k],
this.width / 2, this.height / 2 - 10 + k * 10, 16777215);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
import modloader.ModLoader;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_622;
import org.lwjgl.Sys;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import net.minecraft.applet.GameStartupErrorPanel;

@Environment(EnvType.CLIENT)
@Mixin(GameStartupErrorPanel.class)
@Mixin(class_622.class)
public abstract class GameStartupErrorPanelMixin extends Panel {
private static StringWriter stringWriter = new StringWriter();

Expand Down Expand Up @@ -110,6 +109,6 @@ public abstract class GameStartupErrorPanelMixin extends Panel {
str4 = str4 + "\n";
str4 = str4 + "\n";

return str1;
return str4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ItemEntityMixin(World arg) {
super(arg);
}

@Inject(method = "onPlayerCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/Entity;Ljava/lang/String;FF)V"))
@Inject(method = "onPlayerInteraction", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/Entity;Ljava/lang/String;FF)V"))
private void modloader$onPlayerCollision(PlayerEntity par1, CallbackInfo ci) {
ModLoader.OnItemPickup(par1, this.stack);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package io.github.betterthanupdates.modloader.mixin.client;

import modloader.ModLoader;
import net.minecraft.class_326;
import net.minecraft.class_51;
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.world.World;
import net.minecraft.world.chunk.ServerChunkCache;
import net.minecraft.world.source.WorldSource;

@Mixin(ServerChunkCache.class)
public abstract class ServerChunkCacheMixin implements WorldSource {
@Mixin(class_326.class)
public abstract class ServerChunkCacheMixin implements class_51 {
@Shadow
private WorldSource worldSource;
private class_51 field_1227;

@Shadow
private World world;
private World field_1231;

@Inject(method = "decorate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;method_885()V"))
private void modloader$decorate(WorldSource i, int j, int par3, CallbackInfo ci) {
ModLoader.PopulateChunk(this.worldSource, j, par3, this.world);
@Inject(method = "method_1803", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;method_885()V"))
private void modloader$decorate(class_51 i, int j, int par3, CallbackInfo ci) {
ModLoader.PopulateChunk(this.field_1227, j, par3, this.field_1231);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Inject;

import net.minecraft.entity.BlockEntity;
import net.minecraft.entity.block.FurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.FurnaceBlockEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.SmeltingRecipeRegistry;

import net.minecraft.recipe.SmeltingRecipeManager;
import io.github.betterthanupdates.reforged.recipe.ReforgedSmeltingRecipeRegistry;

@Mixin(FurnaceBlockEntity.class)
public abstract class VanillaFurnaceBlockEntityMixin extends BlockEntity implements Inventory {
@Shadow
protected abstract boolean canAcceptRecipeOutput();
protected abstract boolean method_1283();

@Shadow
private ItemStack[] inventory;
Expand All @@ -31,18 +29,18 @@ public abstract class VanillaFurnaceBlockEntityMixin extends BlockEntity impleme
*/
@Environment(EnvType.CLIENT)
@Overwrite
public void craftRecipe() {
if (this.canAcceptRecipeOutput()) {
ItemStack itemstack = ((ReforgedSmeltingRecipeRegistry) SmeltingRecipeRegistry.getInstance()).getSmeltingResult(this.inventory[0]);
public void method_1282() {
if (this.method_1283()) {
ItemStack itemstack = ((ReforgedSmeltingRecipeRegistry) SmeltingRecipeManager.getInstance()).getSmeltingResult(this.inventory[0]);

if (this.inventory[2] == null) {
this.inventory[2] = itemstack.copy();
} else if (this.inventory[2].isDamageAndIDIdentical(itemstack)) {
} else if (this.inventory[2].isItemEqual(itemstack)) {
this.inventory[2].count += itemstack.count;
}

if (this.inventory[0].getItem().hasContainerItemType()) {
this.inventory[0] = new ItemStack(this.inventory[0].getItem().getContainerItemType());
if (this.inventory[0].getItem().hasCraftingReturnItem()) {
this.inventory[0] = new ItemStack(this.inventory[0].getItem().getCraftingReturnItem());
} else {
--this.inventory[0].count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_426;
import net.minecraft.class_73;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.server.command.CommandManager;
import net.minecraft.server.world.ServerWorld;

@Environment(EnvType.SERVER)
@Mixin(CommandManager.class)
@Mixin(class_426.class)
public abstract class CommandManagerMixin {
@Redirect(method = "processCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;method_204(J)V"))
private void makeClientCompatibleIGuess(ServerWorld instance, long l) {
instance.setWorldTime(l);
@Redirect(method = "method_1411", at = @At(value = "INVOKE", target = "Lnet/minecraft/class_73;method_204(J)V"))
private void makeClientCompatibleIGuess(class_73 instance, long l) {
instance.setTime(l);
}
}
Loading

0 comments on commit e51b941

Please sign in to comment.