Skip to content

Commit

Permalink
add first working mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilzinsel64 committed Feb 9, 2024
1 parent a1787a2 commit 3e8f7eb
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 3 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
dependencies {
api(project.files("libs/mystcraft-dev.jar"))
api("com.github.GTNewHorizons:GTNHLib:0.2.3:dev")
implementation("com.github.GTNewHorizons:TinkersConstruct:1.11.11-GTNH:dev")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package de.pilz.mystcraftextras;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
import com.gtnewhorizon.gtnhmixins.LateMixin;

@LateMixin
public class MystcraftExtrasLateMixins implements ILateMixinLoader {

@Override
public String getMixinConfig() {
return "mixins.mystcraftextras.late.json";
}

@Override
public List<String> getMixins(Set<String> loadedMods) {
List<String> list = new ArrayList<String>();

// Mystcraft
if (loadedMods.contains("Mystcraft")) {
list.add("MixinLinkingAPIDelegate");
}

// Tinkers Construct
if (loadedMods.contains("TConstruct")) {
list.add("MixinToolStationLogic");
}

return list;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.pilz.mystcraftextras.compat.tc;

public class RenameOnTinkerTable {

public RenameOnTinkerTable(){

}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package de.pilz.mystcraftextras.configuration;

import com.gtnewhorizon.gtnhlib.config.Config;
import com.gtnewhorizon.gtnhlib.config.Config.Comment;
import com.gtnewhorizon.gtnhlib.config.Config.DefaultBoolean;
import com.gtnewhorizon.gtnhlib.config.Config.RequiresMcRestart;

import de.pilz.mystcraftextras.MystcraftExtras;

@Config(modid = MystcraftExtras.MODID, category = "blocksAndItems")
public class BlocksAndItemsConfig {

@Comment("Enables some different textured variants of book stands.")
@DefaultBoolean(true)
@RequiresMcRestart
public static boolean enableAdditionalBookStands;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gtnewhorizon.gtnhlib.config.Config;
import com.gtnewhorizon.gtnhlib.config.Config.Comment;
import com.gtnewhorizon.gtnhlib.config.Config.DefaultBoolean;
import com.gtnewhorizon.gtnhlib.config.Config.RequiresMcRestart;

import de.pilz.mystcraftextras.MystcraftExtras;

Expand All @@ -12,4 +13,9 @@ public class TweaksConfig {
@Comment("Enables Intra Linking on newly created linking books by default.")
@DefaultBoolean(true)
public static boolean enableIntraLinkingByDefault;

@Comment("Enables the ability to rename Linking Books on a Tool Station from Tinkers Construct.")
@DefaultBoolean(true)
@RequiresMcRestart
public static boolean enableRenameOnTinkerToolStation;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.pilz.mystcraftextras.mixins;

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.CallbackInfoReturnable;

import com.xcompwiz.mystcraft.item.ItemLinkbook;
import com.xcompwiz.mystcraft.linking.LinkOptions;

import mantle.blocks.abstracts.InventoryLogic;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.tools.logic.ToolStationLogic;

@Mixin(ToolStationLogic.class)
public abstract class MixinToolStationLogic extends InventoryLogic {

public MixinToolStationLogic(int invSize) {
super(invSize);
}

@Inject(method = "canRename(Lnet/minecraft/nbt/NBTTagCompound;Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true, remap = false)
private static void canRename$mystcraftextras$canRenameLinkingBook(NBTTagCompound tags, ItemStack tool, CallbackInfoReturnable<Boolean> callback) {
if (tool != null && tool.getItem() instanceof ItemLinkbook) {
callback.setReturnValue(true);
}
}

@Inject(method = "tryRenameTool(Lnet/minecraft/item/ItemStack;Ljava/lang/String;)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), cancellable = true, remap = false)
protected void tryRenameTool$mystcraftextras$renameLinkingBook(ItemStack output, String name, CallbackInfoReturnable<ItemStack> callback) {
var temp = output != null ? output : this.inventory[1].copy();

if (temp != null && temp.getItem() instanceof ItemLinkbook && name != null && !name.equals("")) {
LinkOptions.setDisplayName(temp.stackTagCompound, name);
output = temp;
callback.setReturnValue(output);
callback.cancel();
}
}
}
4 changes: 1 addition & 3 deletions src/main/resources/mixins.mystcraftextras.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"refmap": "mixins.mystcraftextras.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinLinkingAPIDelegate"
],
"mixins": [],
"client": [],
"server": []
}
14 changes: 14 additions & 0 deletions src/main/resources/mixins.mystcraftextras.late.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"package": "de.pilz.mystcraftextras.mixins",
"refmap": "mixins.mystcraftextras.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinLinkingAPIDelegate",
"MixinToolStationLogic"
],
"client": [],
"server": []
}

0 comments on commit 3e8f7eb

Please sign in to comment.