Skip to content

Commit

Permalink
Cleanup and convert BlockPillar fix into a Mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCodex6824 committed Sep 22, 2024
1 parent 63b8ac1 commit 9a782bc
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 161 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ mixin {
checks = true
debug.countInjections = true
debug.strict = true
debug.verbose = true
env.remapRefMap = true
overwriteErrorLevel = 'error'
quiet
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public void injectData(Map<String, Object> data) {

@Override
public List<String> getMixinConfigs() {
return ImmutableList.of("mixin/event.json", "mixin/item.json", "mixin/render.json", "mixin/vanilla.json");
return ImmutableList.of("mixin/block.json", "mixin/event.json", "mixin/item.json",
"mixin/render.json", "mixin/vanilla.json");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ private void initTransformers() {
transformers = new ArrayList<>();
if (!ThaumcraftFixCore.isOldThaumicAugmentationDetected()) {
transformers.add(EntityTransformers.ELDRITCH_GUARDIAN_FOG);
transformers.add(EntityTransformers.ELYTRA_ROBE_FLAPPING);
transformers.add(EntityTransformers.FLUX_RIFT_DESTROY_BLOCK_EVENT);
transformers.add(EntityTransformers.VOID_ROBE_ARMOR_DISPLAY);
transformers.add(ItemTransformers.CYCLE_ITEM_NON_DAMAGEABLE);
Expand Down Expand Up @@ -84,7 +83,6 @@ private void initTransformers() {
transformers.add(BlockTransformers.FOCAL_MANIPULATOR_XP_COST_GUI);
transformers.add(BlockTransformers.INFERNAL_FURNACE_DESTROY_EFFECTS.get());
transformers.add(BlockTransformers.INFERNAL_FURNACE_ITEM_CHECKS.get());
transformers.add(BlockTransformers.PILLAR_DROP_FIX.get());
transformers.add(BlockTransformers.PLANT_CINDERPEARL_OFFSET.get());
transformers.add(BlockTransformers.PLANT_SHIMMERLEAF_OFFSET.get());
transformers.add(BlockTransformers.TABLE_TOP_SOLID.get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* 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.block;

import java.util.Random;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import thaumcraft.api.blocks.BlocksTC;
import thaumcraft.common.blocks.basic.BlockPillar;

@Mixin(BlockPillar.class)
public abstract class BlockPillarMixin extends Block {

private BlockPillarMixin(Material material) {
super(material);
}

private static final int DROP_QUANTITY = 2;

@Redirect(
method = "Lthaumcraft/common/blocks/basic/BlockPillar;breakBlock(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)V",
at = @At(value = "INVOKE", target = "Lthaumcraft/common/blocks/basic/BlockPillar;spawnAsEntity(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/item/ItemStack;)V")
)
private void doNotSpawnItemsInBreakBlock(World world, BlockPos pos, ItemStack stack) {
// nope
}

// these 3 all don't exist in BlockPillar
@Override
public int quantityDropped(Random random) {
return DROP_QUANTITY;
}

@Override
public int quantityDropped(IBlockState state, int fortune, Random random) {
return DROP_QUANTITY;
}

@Override
public int quantityDroppedWithBonus(int fortune, Random random) {
return DROP_QUANTITY;
}

@ModifyReturnValue(
method = "getItemDropped(Lnet/minecraft/block/state/IBlockState;Ljava/util/Random;I)Lnet/minecraft/item/Item;",
at = @At("RETURN")
)
private Item setDroppedItem(Item original, IBlockState state) {
if (original == Items.AIR) {
if (state.getBlock() == BlocksTC.pillarAncient) {
original = Item.getItemFromBlock(BlocksTC.stoneAncient);
}
else if (state.getBlock() == BlocksTC.pillarEldritch) {
original = Item.getItemFromBlock(BlocksTC.stoneEldritchTile);
}
else {
original = Item.getItemFromBlock(BlocksTC.stoneArcane);
}
}

return original;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ModelCustomArmorMixin extends ModelBiped {
/**
* @author TheCodex6824
* @reason TC's implementation of this method is a copy-paste that has bugs,
* and also prevents any other mixins / ASM into ModelBiped from working
* and also prevents any other mixins / ASM into ModelBiped from working on TC armor
*/
@Override
@Overwrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import thecodex6824.coremodlib.PatchStateMachine;
import thecodex6824.thaumcraftfix.ThaumcraftFix;
import thecodex6824.thaumcraftfix.core.transformer.custom.BlockApplyOffsetTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.BlockPillarDropFixTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.ThrowingTransformerWrapper;

public class BlockTransformers {
Expand Down Expand Up @@ -762,9 +761,6 @@ public static boolean modifyFocalManipulatorCraftValid(boolean origResult, int t
);
};

public static final Supplier<ITransformer> PILLAR_DROP_FIX = () -> new ThrowingTransformerWrapper(
new BlockPillarDropFixTransformer());

public static final Supplier<ITransformer> PLANT_CINDERPEARL_OFFSET = () -> new ThrowingTransformerWrapper(
new BlockApplyOffsetTransformer("thaumcraft/common/blocks/world/plants/BlockPlantCinderpearl"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,6 @@ public static double getFixedDistanceSq(EntityArcaneBore bore, BlockPos target,
@SideOnly(Side.CLIENT)
public static final class HooksClient {

public static float getRobeRotationDivisor(Entity entity) {
float f = 1.0F;
if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).getTicksElytraFlying() > 4) {
f = (float) (entity.motionX * entity.motionX + entity.motionY * entity.motionY + entity.motionZ * entity.motionZ);
f /= 0.2F;
f = Math.max(f * f * f, 1.0F);
}

return f;
}

public static TextureAtlasSprite getBlockParticleTexture(TextureAtlasSprite old, IBlockState state) {
return Minecraft.getMinecraft().getBlockRendererDispatcher()
.getModelForState(state).getParticleTexture();
Expand Down Expand Up @@ -306,38 +295,6 @@ public static int drawLamplightText(EntityArcaneBore bore, int position) {
@SideOnly(Side.CLIENT)
private static final String HOOKS_CLIENT = Type.getInternalName(HooksClient.class);

// fixes annoying robe legging flapping (as if the player is walking) while elytra flying
public static final ITransformer ELYTRA_ROBE_FLAPPING = new GenericStateMachineTransformer(
PatchStateMachine.builder(
TransformUtil.remapMethod(new MethodDefinition(
"thaumcraft/client/renderers/models/gear/ModelRobe",
false,
"func_78088_a",
Type.VOID_TYPE,
Types.ENTITY, Type.FLOAT_TYPE, Type.FLOAT_TYPE, Type.FLOAT_TYPE, Type.FLOAT_TYPE,
Type.FLOAT_TYPE, Type.FLOAT_TYPE
)
))
.findNextMethodCall(new MethodDefinition(
"java/lang/Math",
false,
"min",
Type.FLOAT_TYPE,
Type.FLOAT_TYPE, Type.FLOAT_TYPE
))
.insertInstructionsAfter(
new VarInsnNode(Opcodes.ALOAD, 1),
new MethodInsnNode(Opcodes.INVOKESTATIC,
HOOKS_CLIENT,
"getRobeRotationDivisor",
Type.getMethodDescriptor(Type.FLOAT_TYPE, Types.ENTITY),
false
),
new InsnNode(Opcodes.FDIV)
)
.build(), true, 1
);

// required because TC always creates fog near eldritch guardians if not in the outer lands
// but since the outer lands don't exist they always do it
// even if it did exist its hardcodedness is problematic
Expand Down

This file was deleted.

9 changes: 9 additions & 0 deletions src/main/resources/mixin/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"package": "thecodex6824.thaumcraftfix.core.mixin.block",
"refmap": "${refmap}",
"minVersion": "${mixinbooterminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"BlockPillarMixin"
]
}

0 comments on commit 9a782bc

Please sign in to comment.