Mixed Mixins

- Rewrite mixins, for the third and hopefully final time
This commit is contained in:
IThundxr 2025-01-12 13:36:06 -05:00
parent c67b0536bc
commit e9eec088ce
Failed to generate hash of commit
24 changed files with 90 additions and 113 deletions

View file

@ -9,6 +9,7 @@ import com.simibubi.create.foundation.item.CustomUseEffectsItem;
import com.simibubi.create.foundation.item.render.SimpleCustomRenderer;
import com.simibubi.create.foundation.mixin.accessor.LivingEntityAccessor;
import net.createmod.catnip.data.TriState;
import net.createmod.catnip.math.VecHelper;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
@ -206,9 +207,9 @@ public class SandPaperItem extends Item implements CustomUseEffectsItem {
}
@Override
public Boolean shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) {
public TriState shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) {
// Trigger every tick so that we have more fine grain control over the animation
return true;
return TriState.TRUE;
}
@Override

View file

@ -3,17 +3,17 @@ package com.simibubi.create.content.logistics.item.filter.attribute;
import java.util.ArrayList;
import java.util.List;
import com.simibubi.create.foundation.utility.CreateLang;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.foundation.utility.CreateLang;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -43,9 +43,9 @@ public interface ItemAttribute {
return null;
ItemAttributeType type = AllRegistries.ITEM_ATTRIBUTE_TYPES.get().getValue(id);
if (type == null) {
if (type == null)
return null;
}
ItemAttribute attribute = type.createAttribute();
attribute.load(nbt);
return attribute;

View file

@ -8,7 +8,7 @@ import net.minecraft.core.BlockPos;
public interface BlockDestructionProgressExtension {
@Nullable
Set<BlockPos> getExtraPositions();
Set<BlockPos> create$getExtraPositions();
void setExtraPositions(@Nullable Set<BlockPos> positions);
void create$setExtraPositions(@Nullable Set<BlockPos> positions);
}

View file

@ -1,5 +1,6 @@
package com.simibubi.create.foundation.item;
import net.createmod.catnip.data.TriState;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
@ -10,10 +11,10 @@ public interface CustomUseEffectsItem {
*
* @param stack The ItemStack being used.
* @param entity The LivingEntity using the item.
* @return null for default behavior, or boolean to override default behavior
* @return {@link TriState#DEFAULT} for default behavior, or {@link TriState#TRUE}/{@link TriState#FALSE} to override default behavior
*/
default Boolean shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) {
return null;
default TriState shouldTriggerUseEffects(ItemStack stack, LivingEntity entity) {
return TriState.DEFAULT;
}
/**

View file

@ -2,8 +2,6 @@ package com.simibubi.create.foundation.mixin;
import java.util.function.BiFunction;
import com.simibubi.create.Create;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -12,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.simibubi.create.Create;
import com.simibubi.create.content.equipment.armor.AllArmorMaterials;
import net.minecraft.Util;

View file

@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.Shadow;
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.common.capabilities.CapabilityProvider;
import net.minecraftforge.common.extensions.IForgeEntity;

View file

@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.simibubi.create.foundation.item.CustomUseEffectsItem;
import net.createmod.catnip.data.TriState;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
@ -30,9 +31,9 @@ public abstract class CustomItemUseEffectsMixin extends Entity {
ItemStack using = getUseItem();
Item item = using.getItem();
if (item instanceof CustomUseEffectsItem handler) {
Boolean result = handler.shouldTriggerUseEffects(using, (LivingEntity) (Object) this);
if (result != null) {
cir.setReturnValue(result);
TriState result = handler.shouldTriggerUseEffects(using, (LivingEntity) (Object) this);
if (result != TriState.DEFAULT) {
cir.setReturnValue(result.getValue());
}
}
}

View file

@ -1,35 +1,26 @@
package com.simibubi.create.foundation.mixin;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.simibubi.create.content.equipment.armor.CardboardArmorHandler;
import net.minecraft.world.entity.Pose;
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.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.simibubi.create.content.equipment.armor.CardboardArmorHandler;
import com.simibubi.create.content.equipment.armor.NetheriteDivingHandler;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Pose;
@Mixin(value = Entity.class, priority = 900)
@Mixin(Entity.class)
public class EntityMixin {
@ModifyExpressionValue(method = "canEnterPose", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;noCollision(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;)Z"))
public boolean create$playerHidingAsBoxIsCrouchingNotSwimming(boolean original, @Local(argsOnly = true) Pose pose) {
return original || (pose == Pose.CROUCHING && CardboardArmorHandler.testForStealth((Entity) (Object) this));
}
@Inject(method = "fireImmune()Z", at = @At("RETURN"), cancellable = true)
public void create$onFireImmune(CallbackInfoReturnable<Boolean> cir) {
if (!cir.getReturnValueZ()) {
Entity self = (Entity) (Object) this;
boolean immune = self.getPersistentData().getBoolean(NetheriteDivingHandler.FIRE_IMMUNE_KEY);
if (immune)
cir.setReturnValue(immune);
}
@ModifyReturnValue(method = "fireImmune()Z", at = @At("RETURN"))
public boolean create$onFireImmune(boolean original) {
return ((Entity) (Object) this).getPersistentData().getBoolean(NetheriteDivingHandler.FIRE_IMMUNE_KEY) || original;
}
}

View file

@ -0,0 +1,19 @@
package com.simibubi.create.foundation.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.ProjectileUtil;
@Mixin(ProjectileUtil.class)
public class ProjectileUtilMixin {
@WrapOperation(method = "getEntityHitResult(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;D)Lnet/minecraft/world/phys/EntityHitResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;canRiderInteract()Z"))
private static boolean create$interactWithEntitiesOnContraptions(Entity instance, Operation<Boolean> original) {
return original.call(instance) || instance.getRootVehicle() instanceof AbstractContraptionEntity;
}
}

View file

@ -1,15 +1,14 @@
package com.simibubi.create.foundation.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.world.Container;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(ShulkerBoxBlock.class)
public class ShulkerBoxBlockMixin {
@ModifyExpressionValue(method = "getAnalogOutputSignal", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getBlockEntity(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/entity/BlockEntity;"))

View file

@ -26,5 +26,4 @@ public interface HumanoidArmorLayerAccessor {
@Invoker("setPartVisibility")
void create$callSetPartVisibility(HumanoidModel<?> model, EquipmentSlot slot);
}

View file

@ -1,12 +1,11 @@
package com.simibubi.create.foundation.mixin.accessor;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.culling.Frustum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.culling.Frustum;
@Mixin(LevelRenderer.class)
public interface LevelRendererAccessor {
@Accessor("cullingFrustum")

View file

@ -7,7 +7,6 @@ import net.minecraft.client.MouseHandler;
@Mixin(MouseHandler.class)
public interface MouseHandlerAccessor {
@Accessor("xpos")
void create$setXPos(double xPos);

View file

@ -16,12 +16,12 @@ public class BlockDestructionProgressMixin implements BlockDestructionProgressEx
private Set<BlockPos> create$extraPositions;
@Override
public Set<BlockPos> getExtraPositions() {
public Set<BlockPos> create$getExtraPositions() {
return create$extraPositions;
}
@Override
public void setExtraPositions(Set<BlockPos> positions) {
public void create$setExtraPositions(Set<BlockPos> positions) {
create$extraPositions = positions;
}
}

View file

@ -11,11 +11,11 @@ import net.minecraft.client.Camera;
@Mixin(Camera.class)
public abstract class CameraMixin {
@ModifyArg(
method = "Lnet/minecraft/client/Camera;setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V",
method = "setup(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/world/entity/Entity;ZZF)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;getMaxZoom(D)D"),
index = 0
)
public double create$modifyCameraOffset(double originalValue) {
private double create$modifyCameraOffset(double originalValue) {
return originalValue * CameraDistanceModifier.getMultiplier();
}
}

View file

@ -32,6 +32,7 @@ import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.capabilities.CapabilityProvider;
@Mixin(Entity.class)
@ -41,7 +42,7 @@ public abstract class EntityContraptionInteractionMixin extends CapabilityProvid
}
@Shadow
public Level level;
private Level level;
@Shadow
private Vec3 position;
@ -98,7 +99,8 @@ public abstract class EntityContraptionInteractionMixin extends CapabilityProvid
}
// involves block step sounds on contraptions
// IFNE line 661 injecting before `!blockstate.isAir(this.world, blockpos)`
// injecting before `!blockstate1.isAir(this.world, blockpos)`
// `if (this.moveDist > this.nextStep && !blockstate1.isAir())
@Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;isAir()Z", ordinal = 0))
private void create$contraptionStepSounds(MoverType mover, Vec3 movement, CallbackInfo ci) {
Vec3 worldPos = position.add(0, -0.2, 0);

View file

@ -2,27 +2,22 @@ package com.simibubi.create.foundation.mixin.client;
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.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
@Mixin(LocalPlayer.class)
public abstract class HeavyBootsOnPlayerMixin extends AbstractClientPlayer {
private HeavyBootsOnPlayerMixin(ClientLevel level, GameProfile profile) {
super(level, profile);
}
@Inject(method = "isUnderWater()Z", at = @At("HEAD"), cancellable = true)
public void create$noSwimmingWithHeavyBootsOn(CallbackInfoReturnable<Boolean> cir) {
CompoundTag persistentData = getPersistentData();
if (persistentData.contains("HeavyBoots"))
cir.setReturnValue(false);
@ModifyReturnValue(method = "isUnderWater()Z", at = @At("RETURN"))
private boolean create$noSwimmingWithHeavyBootsOn(boolean original) {
return getPersistentData().contains("HeavyBoots") || original;
}
}

View file

@ -4,8 +4,8 @@ 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.LocalCapture;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.foundation.item.CustomRenderedArmorItem;
@ -18,8 +18,15 @@ import net.minecraft.world.item.ItemStack;
@Mixin(HumanoidArmorLayer.class)
public class HumanoidArmorLayerMixin {
@Inject(method = "renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;)V", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/entity/LivingEntity;getItemBySlot(Lnet/minecraft/world/entity/EquipmentSlot;)Lnet/minecraft/world/item/ItemStack;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void create$onRenderArmorPiece(PoseStack poseStack, MultiBufferSource bufferSource, LivingEntity entity, EquipmentSlot slot, int light, HumanoidModel<?> model, CallbackInfo ci, ItemStack stack) {
@Inject(
method = "renderArmorPiece(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;ILnet/minecraft/client/model/HumanoidModel;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;"
),
cancellable = true
)
private void create$onRenderArmorPiece(PoseStack poseStack, MultiBufferSource bufferSource, LivingEntity entity, EquipmentSlot slot, int light, HumanoidModel<?> model, CallbackInfo ci, @Local ItemStack stack) {
if (stack.getItem() instanceof CustomRenderedArmorItem renderer) {
renderer.renderArmorPiece((HumanoidArmorLayer<?, ?, ?>) (Object) this, poseStack, bufferSource, entity, slot, light, model, stack);
ci.cancel();

View file

@ -16,7 +16,6 @@ import net.minecraft.world.entity.LivingEntity;
@Mixin(HumanoidModel.class)
public class HumanoidModelMixin<T extends LivingEntity> {
@Shadow
@Final
public ModelPart body;
@ -36,5 +35,4 @@ public class HumanoidModelMixin<T extends LivingEntity> {
PlayerSkyhookRenderer.beforeSetupAnim(player, (HumanoidModel<?>) (Object) this);
}
}

View file

@ -22,6 +22,7 @@ import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.BlockDestructionProgress;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.extensions.common.IClientBlockExtensions;
@Mixin(LevelRenderer.class)
@ -41,7 +42,7 @@ public class LevelRendererMixin {
Set<BlockPos> extraPositions = handler.getExtraPositions(level, pos, state, progress);
if (extraPositions != null) {
extraPositions.remove(pos);
((BlockDestructionProgressExtension) progressObj).setExtraPositions(extraPositions);
((BlockDestructionProgressExtension) progressObj).create$setExtraPositions(extraPositions);
for (BlockPos extraPos : extraPositions) {
destructionProgress.computeIfAbsent(extraPos.asLong(), l -> Sets.newTreeSet()).add(progressObj);
}
@ -51,7 +52,7 @@ public class LevelRendererMixin {
@Inject(method = "removeProgress(Lnet/minecraft/server/level/BlockDestructionProgress;)V", at = @At("RETURN"))
private void create$onRemoveProgress(BlockDestructionProgress progress, CallbackInfo ci) {
Set<BlockPos> extraPositions = ((BlockDestructionProgressExtension) progress).getExtraPositions();
Set<BlockPos> extraPositions = ((BlockDestructionProgressExtension) progress).create$getExtraPositions();
if (extraPositions != null) {
for (BlockPos extraPos : extraPositions) {
long l = extraPos.asLong();

View file

@ -1,33 +0,0 @@
package com.simibubi.create.foundation.mixin.client;
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.createmod.catnip.levelWrappers.SchematicLevel;
import net.minecraft.client.Minecraft;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.data.ModelDataManager;
@OnlyIn(Dist.CLIENT)
@Mixin(ModelDataManager.class)
public class ModelDataRefreshMixin {
/**
* Normally ModelDataManager will throw an exception if a block entity tries
* to refresh its model data from a world the client isn't currently in,
* but we need that to not happen for block entities in fake schematic
* worlds, so in those cases just do nothing instead.
*/
@Inject(method = "requestModelDataRefresh", at = @At("HEAD"), cancellable = true, remap = false)
private static void create$requestModelDataRefresh(BlockEntity be, CallbackInfo ci) {
if (be != null) {
Level world = be.getLevel();
if (world != Minecraft.getInstance().level && world instanceof SchematicLevel)
ci.cancel();
}
}
}

View file

@ -4,7 +4,6 @@ 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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import com.simibubi.create.foundation.item.CustomArmPoseItem;
@ -16,8 +15,9 @@ import net.minecraft.world.item.ItemStack;
@Mixin(PlayerRenderer.class)
public class PlayerRendererMixin {
@Inject(method = "getArmPose(Lnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/client/model/HumanoidModel$ArmPose;", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/player/AbstractClientPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private static void create$onGetArmPose(AbstractClientPlayer player, InteractionHand hand, CallbackInfoReturnable<ArmPose> cir, ItemStack stack) {
@Inject(method = "getArmPose(Lnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/client/model/HumanoidModel$ArmPose;", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/player/AbstractClientPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;"), cancellable = true)
private static void create$onGetArmPose(AbstractClientPlayer player, InteractionHand hand, CallbackInfoReturnable<ArmPose> cir) {
ItemStack stack = player.getItemInHand(hand);
if (stack.getItem() instanceof CustomArmPoseItem armPoseProvider) {
ArmPose pose = armPoseProvider.getArmPose(stack, player, hand);
if (pose != null) {
@ -25,6 +25,4 @@ public class PlayerRendererMixin {
}
}
}
}

View file

@ -37,5 +37,4 @@ public abstract class JourneyFullscreenMapMixin {
double z = gridRenderer.getCenterBlockZ() - (dragging ? mouseDrag.y : 0);
JourneyTrainMap.onRender(graphics, (Fullscreen) (Object) this, x, z, mouseX, mouseY, pt);
}
}

View file

@ -15,6 +15,7 @@
"EntityMixin",
"LavaSwimmingMixin",
"MapItemSavedDataMixin",
"ProjectileUtilMixin",
"ShulkerBoxBlockMixin",
"SmithingMenuMixin",
"TestCommandMixin",