Skip to content

Commit

Permalink
Switch to more compatible injectors x2
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 18, 2024
1 parent c9aded2 commit eb09d1f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package com.railwayteam.railways.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.railwayteam.railways.content.conductor.ConductorEntity;
import com.railwayteam.railways.mixin_interfaces.CarriageBogeyUtils;
import com.railwayteam.railways.mixin_interfaces.ICarriageBufferDistanceTracker;
Expand Down Expand Up @@ -46,7 +48,6 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand Down Expand Up @@ -99,8 +100,8 @@ public abstract class MixinCarriage implements ICarriageConductors, ICarriageBuf
railways$trailingBufferDistance = distance;
}

@Redirect(method = "updateConductors", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/trains/entity/CarriageContraptionEntity;checkConductors()Lcom/simibubi/create/foundation/utility/Couple;"))
private Couple<Boolean> addControllingConductors(CarriageContraptionEntity instance) {
@WrapOperation(method = "updateConductors", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/trains/entity/CarriageContraptionEntity;checkConductors()Lcom/simibubi/create/foundation/utility/Couple;"))
private Couple<Boolean> addControllingConductors(CarriageContraptionEntity instance, Operation<Couple<Boolean>> original) {
railways$controllingConductors.clear();
if (instance.getContraption() instanceof CarriageContraption cc) {
for (Entity passenger : instance.getPassengers()) {
Expand All @@ -116,7 +117,7 @@ private Couple<Boolean> addControllingConductors(CarriageContraptionEntity insta
railways$controllingConductors.add(passenger.getUUID());
}
}
return instance.checkConductors();
return original.call(instance);
}

@Inject(method = "write", at = @At("RETURN"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.railwayteam.railways.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.railwayteam.railways.Railways;
Expand Down Expand Up @@ -52,7 +53,6 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
Expand Down Expand Up @@ -119,11 +119,9 @@ private void clearDropTrain(ServerPlayer sender, CallbackInfoReturnable<Boolean>
dropScheduleTrain = null;
}

@Redirect(method = "dropSchedule", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/trains/station/GlobalStation;getPresentTrain()Lcom/simibubi/create/content/trains/entity/Train;"), require = 0)
private Train returnOverridenTrain(GlobalStation instance) {
Train train = instance.getPresentTrain();
if (train == null)
train = dropScheduleTrain;
@ModifyExpressionValue(method = "dropSchedule", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/trains/station/GlobalStation;getPresentTrain()Lcom/simibubi/create/content/trains/entity/Train;"), require = 0)
private Train returnOverridenTrain(Train original) {
Train train = original != null ? original : dropScheduleTrain;
dropScheduleTrain = null;
return train;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
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.Redirect;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand Down Expand Up @@ -102,11 +102,9 @@ private void placeCustomStyle(BlockGetter world, BlockPos pos, BlockState state,
);
}

@Redirect(method = "onPlace", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;scheduleTick(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;I)V", remap = true), remap = true)
private void maybeMakeTickInstant(Level instance, BlockPos blockPos, Block block, int i) {
if (TrackReplacePaver.tickInstantly)
i = 0;
instance.scheduleTick(blockPos, block, i);
@ModifyArg(method = "onPlace", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;scheduleTick(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;I)V"), index = 2, remap = true)
private int maybeMakeTickInstant(int original) {
return TrackReplacePaver.tickInstantly ? 0 : original;
}

@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true, remap = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@

package com.railwayteam.railways.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.railwayteam.railways.Railways;
import com.simibubi.create.content.trains.track.TrackMaterial;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = TrackMaterial.class, remap = false)
public class MixinTrackMaterial {
/*
Properly deserialize pre-resourcelocation tracks
*/
@Redirect(method = "deserialize", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourceLocation;tryParse(Ljava/lang/String;)Lnet/minecraft/resources/ResourceLocation;", remap = true))
private static ResourceLocation railways$deserializeLegacyTracks(String location) {
ResourceLocation parsed = ResourceLocation.tryParse(location);
if (parsed.getNamespace().equals("minecraft")) {
ResourceLocation alternate = Railways.asResource(parsed.getPath());
// Properly deserialize pre-resourcelocation tracks
@ModifyExpressionValue(method = "deserialize", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/ResourceLocation;tryParse(Ljava/lang/String;)Lnet/minecraft/resources/ResourceLocation;", remap = true))
private static ResourceLocation railways$deserializeLegacyTracks(ResourceLocation original) {
if (original.getNamespace().equals("minecraft")) {
ResourceLocation alternate = Railways.asResource(original.getPath());
if (TrackMaterial.ALL.containsKey(alternate))
return alternate;
}
return parsed;
return original;
}
}

0 comments on commit eb09d1f

Please sign in to comment.