Skip to content

Commit

Permalink
Fixing freaking Mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
tyra314 committed Jan 27, 2021
1 parent f2ed083 commit a5614b5
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ yarn_mappings = 1.16.5+build.1
loader_version = 0.11.1

# Mod Properties
mod_version = 5.4.3-fabric
mod_version = 5.4.4-fabric
maven_group = hunternif.mc.atlas
archives_base_name = antiqueatlas

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@

import javax.annotation.Nullable;

@Mixin(targets = "net.minecraft.screen.CartographyTableScreenHandler$4")
class MixinCartographyTableScreenHandlerSlot {

@Inject(method = "canInsert", at = @At("RETURN"), cancellable = true)
void antiqueatlas_canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> info) {
info.setReturnValue(stack.getItem() == AtlasAPI.getAtlasItem() || info.getReturnValueZ());
}
}

@Mixin(CartographyTableScreenHandler.class)
public abstract class MixinCartographyTableScreenHandler extends ScreenHandler {
@Shadow
Expand Down Expand Up @@ -72,23 +63,3 @@ void antiqueatlas_transferSlot(PlayerEntity player, int index, CallbackInfoRetur
}

}

@Mixin(targets = "net.minecraft.screen.CartographyTableScreenHandler$5")
class MixinCartographyTableScreenHandlerResultSlot {

CartographyTableScreenHandler antiqueatlas_handler;

@Inject(method = "<init>", at = @At("TAIL"))
void antiqueatlas_init(CartographyTableScreenHandler handler, Inventory inv, int a, int b, int c, ScreenHandlerContext context, CallbackInfo info) {
antiqueatlas_handler = handler;
}

@Inject(method = "onTakeItem", at = @At("HEAD"))
void antiqueatlas_onTakeItem(PlayerEntity player, ItemStack atlas, CallbackInfoReturnable<ItemStack> info) {
if (atlas.getItem() == AtlasAPI.getAtlasItem()) {
ItemStack map = antiqueatlas_handler.slots.get(0).getStack();

CartographyTableHooks.onTakeItem(player, map, atlas);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package hunternif.mc.impl.atlas.mixin;

/**
* This file was copied from https://github.com/Hephaestus-Dev/TinyTweaks/blob/master/src/main/java/dev/hephaestus/tweaks/mixin/VolatileMixinPlugin.java
*
* Copyright: https://github.com/Hephaestus-Dev
* License: MIT
*/

import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

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

public class VolatileMixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
boolean isDevelopmentEnvironment = FabricLoader.getInstance().isDevelopmentEnvironment();
if (mixinClassName.contains("mixin.dev") && !isDevelopmentEnvironment)
return false;
else return !mixinClassName.contains("mixin.prod") || !isDevelopmentEnvironment;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hunternif.mc.impl.atlas.mixin.dev;

import hunternif.mc.impl.atlas.api.AtlasAPI;
import hunternif.mc.impl.atlas.mixinhooks.CartographyTableHooks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.CartographyTableScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(targets = "net.minecraft.screen.CartographyTableScreenHandler$4")
class MixinCartographyTableScreenHandlerSlot {

@Inject(method = "canInsert", at = @At("RETURN"), cancellable = true)
void antiqueatlas_canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> info) {
info.setReturnValue(stack.getItem() == AtlasAPI.getAtlasItem() || info.getReturnValueZ());
}
}

@Mixin(targets = "net.minecraft.screen.CartographyTableScreenHandler$5")
class MixinCartographyTableScreenHandlerResultSlot {

CartographyTableScreenHandler antiqueatlas_handler;

@Inject(method = "<init>", at = @At("TAIL"))
void antiqueatlas_init(CartographyTableScreenHandler handler, Inventory inv, int a, int b, int c, ScreenHandlerContext context, CallbackInfo info) {
antiqueatlas_handler = handler;
}

@Inject(method = "onTakeItem", at = @At("HEAD"))
void antiqueatlas_onTakeItem(PlayerEntity player, ItemStack atlas, CallbackInfoReturnable<ItemStack> info) {
if (atlas.getItem() == AtlasAPI.getAtlasItem()) {
ItemStack map = antiqueatlas_handler.slots.get(0).getStack();

CartographyTableHooks.onTakeItem(player, map, atlas);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hunternif.mc.impl.atlas.mixin.prod;

import hunternif.mc.impl.atlas.api.AtlasAPI;
import hunternif.mc.impl.atlas.mixinhooks.CartographyTableHooks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.CartographyTableScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(targets = "net.minecraft.screen.CartographyTableScreenHandler$4")
class MixinCartographyTableScreenHandlerSlot {

@Inject(method = "method_7680", at = @At("RETURN"), cancellable = true)
void antiqueatlas_canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> info) {
info.setReturnValue(stack.getItem() == AtlasAPI.getAtlasItem() || info.getReturnValueZ());
}
}

@Mixin(targets = "net.minecraft.screen.CartographyTableScreenHandler$5")
class MixinCartographyTableScreenHandlerResultSlot {

CartographyTableScreenHandler antiqueatlas_handler;

@Inject(method = "<init>", at = @At("TAIL"))
void antiqueatlas_init(CartographyTableScreenHandler handler, Inventory inv, int a, int b, int c, ScreenHandlerContext context, CallbackInfo info) {
antiqueatlas_handler = handler;
}

@Inject(method = "method_7667", at = @At("HEAD"))
void antiqueatlas_onTakeItem(PlayerEntity player, ItemStack atlas, CallbackInfoReturnable<ItemStack> info) {
if (atlas.getItem() == AtlasAPI.getAtlasItem()) {
ItemStack map = antiqueatlas_handler.slots.get(0).getStack();

CartographyTableHooks.onTakeItem(player, map, atlas);
}
}
}
7 changes: 5 additions & 2 deletions src/main/resources/antiqueatlas.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
"required": true,
"package": "hunternif.mc.impl.atlas.mixin",
"compatibilityLevel": "JAVA_8",
"plugin": "hunternif.mc.impl.atlas.mixin.VolatileMixinPlugin",
"mixins": [
"MixinCraftingResultSlot",
"MixinEntity",
"MixinPlayerEntity",
"MixinPlayerEntityDeath",
"MixinPlayerManager",
"MixinCartographyTableScreenHandler",
"MixinCartographyTableScreenHandlerSlot",
"MixinCartographyTableScreenHandlerResultSlot",
"dev.MixinCartographyTableScreenHandlerSlot",
"prod.MixinCartographyTableScreenHandlerSlot",
"dev.MixinCartographyTableScreenHandlerResultSlot",
"prod.MixinCartographyTableScreenHandlerResultSlot",
"structure.StructureStartMixin"
],
"client": [
Expand Down

0 comments on commit a5614b5

Please sign in to comment.