Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mixin Extra's, cleanup and redo some mixins #7056

Open
wants to merge 4 commits into
base: mc1.20.1/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ minecraft {
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"

property "mixin.debug.export", "true"

//jvmArgs '-XX:+IgnoreUnrecognizedVMOptions', '-XX:+AllowEnhancedClassRedefinition' // uncomment with jbr

mods {
Expand Down Expand Up @@ -167,6 +169,11 @@ dependencies {
jarJar.ranged(it, '[1.0,2.0)')
}

compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.4.1")) {
jarJar.ranged(it, "[0.4.1,)")
}

implementation fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}")

compileOnly fg.deobf("dev.engine_room.flywheel:flywheel-forge-api-${flywheel_minecraft_version}:${flywheel_version}")
Expand All @@ -192,12 +199,12 @@ dependencies {
// implementation fg.deobf("curse.maven:ic2-classic-242942:5555152")
// implementation fg.deobf("curse.maven:druidcraft-340991:3101903")
// implementation fg.deobf("com.railwayteam.railways:railways-1.19.2-1.6.4:all") { transitive = false }

implementation fg.deobf("dev.architectury:architectury-forge:9.1.12")
implementation fg.deobf("dev.ftb.mods:ftb-chunks-forge:2001.3.1")
implementation fg.deobf("dev.ftb.mods:ftb-teams-forge:2001.3.0")
implementation fg.deobf("dev.ftb.mods:ftb-library-forge:2001.2.4")

implementation fg.deobf("curse.maven:journeymap-32274:5457831")
// implementation fg.deobf("ignored:journeymap-1.20.1-5.10.1-forge")

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/simibubi/create/api/TriState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.simibubi.create.api;

public enum TriState {
TRUE,
DEFAULT,
FALSE;

public boolean isTrue() {
return this == TRUE;
}

public boolean isDefault() {
return this == DEFAULT;
}

public boolean isFalse() {
return this == FALSE;
}

public boolean getValue() {
return switch (this) {
case TRUE -> true;
case DEFAULT -> throw new IllegalArgumentException("Default does not have a value");
case FALSE -> false;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.annotation.ParametersAreNonnullByDefault;

import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.api.TriState;
import com.simibubi.create.foundation.item.CustomUseEffectsItem;
import com.simibubi.create.foundation.item.render.SimpleCustomRenderer;
import com.simibubi.create.foundation.mixin.accessor.LivingEntityAccessor;
Expand Down Expand Up @@ -208,9 +209,9 @@ public boolean canPerformAction(ItemStack stack, ToolAction toolAction) {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public BlockState updateShape(BlockState pState, Direction pDirection, BlockStat
updateWater(pLevel, pState, pCurrentPos);
return pState;
}

@Override
public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, LivingEntity pPlacer, ItemStack pStack) {
super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack);
Expand Down Expand Up @@ -123,7 +123,7 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla
if (!(savedData instanceof StationMapData stationMapData))
return InteractionResult.FAIL;

if (!stationMapData.toggleStation(pLevel, pPos, station))
if (!stationMapData.create$toggleStation(pLevel, pPos, station))
return InteractionResult.FAIL;

return InteractionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

public interface StationMapData {

boolean toggleStation(LevelAccessor level, BlockPos pos, StationBlockEntity stationBlockEntity);
boolean create$toggleStation(LevelAccessor level, BlockPos pos, StationBlockEntity stationBlockEntity);

void addStationMarker(StationMarker marker);
void create$addStationMarker(StationMarker marker);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface BlockDestructionProgressExtension {
@Nullable
Set<BlockPos> getExtraPositions();
Set<BlockPos> create$getExtraPositions();

void setExtraPositions(@Nullable Set<BlockPos> positions);
void create$setExtraPositions(@Nullable Set<BlockPos> positions);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.simibubi.create.foundation.item;

import com.simibubi.create.api.TriState;

import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
Expand All @@ -10,10 +12,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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class BlockItemMixin {
@Inject(method = "place", at = @At("HEAD"), cancellable = true)
private void create$fixDeployerPlacement(BlockPlaceContext pContext, CallbackInfoReturnable<InteractionResult> cir) {
BlockState state = pContext.getLevel().getBlockState(((UseOnContextAccessor) pContext).create$getHitResult().getBlockPos());
if (!state.canBeReplaced() && pContext.getPlayer() instanceof DeployerFakePlayer) {
if (!state.canBeReplaced() && pContext.getPlayer() instanceof DeployerFakePlayer)
cir.setReturnValue(InteractionResult.PASS);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
package com.simibubi.create.foundation.mixin;

import javax.annotation.Nullable;

import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.minecraftforge.common.capabilities.CapabilityProvider;
import net.minecraftforge.common.extensions.IForgeEntity;
import net.minecraft.world.entity.projectile.ProjectileUtil;

@Mixin(Entity.class)
@Implements(@Interface(iface = IForgeEntity.class, prefix = "iForgeEntity$"))
public abstract class ContraptionDriverInteractMixin extends CapabilityProvider<Entity> {
private ContraptionDriverInteractMixin(Class<Entity> baseClass) {
super(baseClass);
}

@Shadow
public abstract Entity getRootVehicle();
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Nullable
@Intrinsic
public boolean iForgeEntity$canRiderInteract() {
return getRootVehicle() instanceof AbstractContraptionEntity;
@Mixin(ProjectileUtil.class)
public class ContraptionDriverInteractMixin {
@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$contraptionDriverCanInteract(Entity instance, Operation<Boolean> original) {
if (instance.getRootVehicle() instanceof AbstractContraptionEntity)
return true;
return original.call(instance);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.simibubi.create.foundation.mixin;

import com.simibubi.create.api.TriState;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -30,10 +32,9 @@ private CustomItemUseEffectsMixin(EntityType<?> entityType, Level level) {
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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

@Mixin(value = Entity.class, priority = 900)
public class EntityMixin {

@Inject(method = "fireImmune()Z", at = @At("RETURN"), cancellable = true)
public void create$onFireImmune(CallbackInfoReturnable<Boolean> cir) {
private 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);
cir.setReturnValue(true);
}
}

}
50 changes: 0 additions & 50 deletions src/main/java/com/simibubi/create/foundation/mixin/MainMixin.java

This file was deleted.

Loading