Skip to content

Commit

Permalink
Refmaps hopefully actually work now
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCodex6824 committed Sep 17, 2024
1 parent 2a7643a commit a4c5b65
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 151 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bin
.metadata
.classpath
.project
.factorypath

# idea
out
Expand Down
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
id 'eclipse'
id 'idea'
id 'net.minecraftforge.gradle' version '6.0.+'
id 'com.diffplug.eclipse.apt' version '4.0.+'
id 'org.spongepowered.mixin' version '0.7.+'
}

repositories {
Expand Down Expand Up @@ -102,6 +104,13 @@ minecraft {
}
}

mixin {
add sourceSets.main, 'thaumcraftfix.refmap.json'

debug.strict = true
checks = true
}

configurations {
testCompile.extendsFrom compile
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name 'MinecraftForge'
url 'https://maven.minecraftforge.net/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ private void initTransformers() {
transformers.add(ItemTransformers.HAND_MIRROR_STACK_GUI.get());
transformers.add(ItemTransformers.INFUSION_ENCHANTMENT_DROPS_PRIORITY.get());
transformers.add(ItemTransformers.PHIAL_CONSUMPTION_CREATIVE.get());
transformers.add(ItemTransformers.PRIMORDIAL_PEARL_ANVIL_DUPE_DURABILITY_BAR.get());
transformers.add(ItemTransformers.PRIMORDIAL_PEARL_ANVIL_DUPE_EVENT.get());
transformers.add(ItemTransformers.PRIMORDIAL_PEARL_ANVIL_DUPE_PROPS.get());
transformers.add(ItemTransformers.SANITY_SOAP_CREATIVE.get());
transformers.add(MiscTransformers.ARCANE_WORKBENCH_RECIPE_COMPAT.get());
transformers.add(MiscTransformers.ASPECT_REGISTRY_LOOKUP.get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Thaumcraft Fix
* Copyright (c) 2024 TheCodex6824.
*
* This file is part of Thaumcraft Fix.
*
* Thaumcraft Fix 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, either version 3 of the License, or
* (at your option) any later version.
*
* Thaumcraft Fix 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 Thaumcraft Fix. If not, see <https://www.gnu.org/licenses/>.
*/

package thecodex6824.thaumcraftfix.core.mixin.item;

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 net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistrySimple;
import thaumcraft.common.items.curios.ItemPrimordialPearl;

@Mixin(ItemPrimordialPearl.class)
public class ItemPrimordialPearlMixin extends Item {

// overwrite reason: method doesn't exist in the original class
@Override
public boolean showDurabilityBar(ItemStack stack) {
return stack.getItemDamage() > 0;
}

// overwrite reason: method doesn't exist in the original class,
// and the super implementation is dangerous (divide by zero risk)
@Override
public double getDurabilityForDisplay(ItemStack stack) {
return stack.getItemDamage() / 8.0;
}

@Inject(method = "<init>()V", at = @At("RETURN"))
private void construct(CallbackInfo info) {
setMaxDamage(0);
((RegistrySimple<?, ?>) properties).registryObjects.remove(new ResourceLocation("damage"));
((RegistrySimple<?, ?>) properties).registryObjects.remove(new ResourceLocation("damaged"));
setHasSubtypes(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistrySimple;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
Expand All @@ -61,7 +59,6 @@
import thecodex6824.coremodlib.PatchStateMachine;
import thecodex6824.thaumcraftfix.core.transformer.custom.ChangeEventPriorityTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.PrimordialPearlAnvilEventTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.PrimordialPearlDurabilityBarTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.ThrowingTransformerWrapper;

public class ItemTransformers {
Expand Down Expand Up @@ -126,13 +123,6 @@ else if (other == null) {
return result;
}

public static void fixPrimordialPearlItem(Item pearl) {
pearl.setMaxDamage(0);
((RegistrySimple<?, ?>) pearl.properties).registryObjects.remove(new ResourceLocation("damage"));
((RegistrySimple<?, ?>) pearl.properties).registryObjects.remove(new ResourceLocation("damaged"));
pearl.setHasSubtypes(true);
}

public static ItemStack getHandMirrorStack(ItemStack original, InventoryPlayer playerInv) {
EntityPlayer player = playerInv.player;
ItemStack mirror = player.getHeldItemMainhand();
Expand Down Expand Up @@ -403,36 +393,9 @@ public static int fixupXSlot(int original, InventoryPlayer playerInv) {
);
};

public static final Supplier<ITransformer> PRIMORDIAL_PEARL_ANVIL_DUPE_DURABILITY_BAR = () -> new ThrowingTransformerWrapper(
new PrimordialPearlDurabilityBarTransformer());

public static final Supplier<ITransformer> PRIMORDIAL_PEARL_ANVIL_DUPE_EVENT = () -> new ThrowingTransformerWrapper(
new PrimordialPearlAnvilEventTransformer());

public static final Supplier<ITransformer> PRIMORDIAL_PEARL_ANVIL_DUPE_PROPS = () -> {
return new GenericStateMachineTransformer(
PatchStateMachine.builder(
new MethodDefinition(
"thaumcraft/common/items/curios/ItemPrimordialPearl",
false,
"<init>",
Type.VOID_TYPE
)
)
.findNextOpcode(Opcodes.RETURN)
.insertInstructionsBefore(
new VarInsnNode(Opcodes.ALOAD, 0),
new MethodInsnNode(Opcodes.INVOKESTATIC,
HOOKS_COMMON,
"fixPrimordialPearlItem",
Type.getMethodDescriptor(Type.VOID_TYPE, Types.ITEM),
false
)
)
.build()
);
};

// makes runic shielding infusion work on items with baubles capability
// TC only checks for the interface on the item...
public static final ITransformer RUNIC_SHIELD_INFUSION_BAUBLE_CAP = new GenericStateMachineTransformer(
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/resources/mixin/item.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"minVersion": "${mixinbooterminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ItemGenericEssentiaContainerMixin"
"ItemGenericEssentiaContainerMixin",
"ItemPrimordialPearlMixin"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package thecodex6824.thaumcraftfix.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import net.minecraft.init.Bootstrap;
import net.minecraft.item.ItemStack;
import thaumcraft.common.items.curios.ItemPrimordialPearl;

public class TestPrimordialPearl {

@BeforeAll
static void setup() {
Bootstrap.register();
}

static Stream<? extends Arguments> testPearlDurabilityProperties() {
// we are in the normal classloader so this has to be repeated
Bootstrap.register();
int maxMeta = new ItemStack(new ItemPrimordialPearl()).getMaxDamage();
return IntStream.rangeClosed(0, maxMeta)
.mapToObj(i -> Arguments.of(i, (double) i / maxMeta));
}

@ParameterizedTest
@MethodSource
void testPearlDurabilityProperties(int metadata, double damageRatio) {
ItemPrimordialPearl pearl = new ItemPrimordialPearl();
ItemStack stack = new ItemStack(pearl, 1, metadata);
assertEquals(metadata != 0, stack.getItem().showDurabilityBar(stack));
assertEquals(damageRatio, stack.getItem().getDurabilityForDisplay(stack));
}

@Test
void testPearlNotDamageable() {
ItemStack pearl = new ItemStack(new ItemPrimordialPearl());
assertFalse(pearl.isItemStackDamageable());
assertTrue(pearl.getHasSubtypes());
}

}
Loading

0 comments on commit a4c5b65

Please sign in to comment.