Skip to content

Commit

Permalink
Support for any version >=1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Dec 29, 2024
1 parent 0e24b4c commit ca2e84c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 63 deletions.
18 changes: 3 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ repositories {
// for more information about repositories.
}

loom {
splitEnvironmentSourceSets()

mods {
"rail-placement-fix" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}

}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -50,7 +38,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.release = 16
}

java {
Expand All @@ -59,8 +47,8 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}

jar {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.4
minecraft_version=1.17
loader_version=0.16.9

# Mod Properties
Expand Down
10 changes: 0 additions & 10 deletions src/client/java/no2/railplacementfix/RailPlacementFixClient.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/client/resources/rail-placement-fix.client.mixins.json

This file was deleted.

40 changes: 23 additions & 17 deletions src/main/java/no2/railplacementfix/mixin/BaseRailBlockMixin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package no2.railplacementfix.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
Expand All @@ -14,6 +11,7 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.properties.RailShape;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -22,7 +20,9 @@
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.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import static no2.railplacementfix.common.RailPlacementHelper.NO_CONNECT_POS;

Expand All @@ -40,12 +40,14 @@ public BaseRailBlockMixin(Properties properties) {

@Shadow public abstract Property<RailShape> getShapeProperty();

@Shadow protected abstract BlockState updateDir(Level level, BlockPos blockPos, BlockState blockState, boolean bl);

@Inject(method = "getStateForPlacement", at = @At(
value = "INVOKE_ASSIGN", shift = At.Shift.AFTER,
target = "Lnet/minecraft/world/item/context/BlockPlaceContext;getHorizontalDirection()Lnet/minecraft/core/Direction;"
), cancellable = true
), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD
)
private void getSmartPlacementState(BlockPlaceContext blockPlaceContext, CallbackInfoReturnable<BlockState> cir, @Local boolean shouldWaterlog, @Local BlockState defaultRailState, @Local Direction placementDirection) {
private void getSmartPlacementState(BlockPlaceContext blockPlaceContext, CallbackInfoReturnable<BlockState> cir, boolean shouldWaterlog, BlockState defaultRailState, Direction placementDirection) {
if (blockPlaceContext.getPlayer() != null && blockPlaceContext.getPlayer().isShiftKeyDown()) {
BlockPos blockPos = blockPlaceContext.getClickedPos();
Direction clickSide = blockPlaceContext.getClickedFace();
Expand All @@ -64,7 +66,7 @@ private void getSmartPlacementState(BlockPlaceContext blockPlaceContext, Callbac
betterRailShape = getCurvedRailShape(clickLocation, blockPos);
}
if (betterRailShape != null) {
cir.setReturnValue(defaultRailState.trySetValue(WATERLOGGED, shouldWaterlog).trySetValue(this.getShapeProperty(), betterRailShape));
cir.setReturnValue(defaultRailState.setValue(WATERLOGGED, shouldWaterlog).setValue(this.getShapeProperty(), betterRailShape));
}
NO_CONNECT_POS.set(blockPos);
}
Expand Down Expand Up @@ -105,28 +107,32 @@ private void getSmartPlacementState(BlockPlaceContext blockPlaceContext, Callbac

@Unique
private static @Nullable RailShape getSlopedRailShape(Direction uphillDirection) {
return switch (uphillDirection) {
case NORTH -> RailShape.ASCENDING_NORTH;
case SOUTH -> RailShape.ASCENDING_SOUTH;
case WEST -> RailShape.ASCENDING_WEST;
case EAST -> RailShape.ASCENDING_EAST;
case null, default -> null;
};
if (uphillDirection == Direction.NORTH) {
return RailShape.ASCENDING_NORTH;
} else if (uphillDirection == Direction.SOUTH) {
return RailShape.ASCENDING_SOUTH;
} else if (uphillDirection == Direction.WEST) {
return RailShape.ASCENDING_WEST;
} else if (uphillDirection == Direction.EAST) {
return RailShape.ASCENDING_EAST;
}
return null;
}

@WrapOperation(
@Redirect(
method = "updateState(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Z)Lnet/minecraft/world/level/block/state/BlockState;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/BaseRailBlock;updateDir(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Z)Lnet/minecraft/world/level/block/state/BlockState;")
)
private BlockState cancelUpdates(BaseRailBlock instance, Level level, BlockPos blockPos, BlockState blockState, boolean bl, Operation<BlockState> original) {
private BlockState cancelUpdates(BaseRailBlock instance, Level level, BlockPos blockPos, BlockState blockState, boolean bl) {
BlockPos noUpdatePos = NO_CONNECT_POS.get();

if (noUpdatePos != null) {
NO_CONNECT_POS.set(null);
}

if (!blockPos.equals(noUpdatePos))
return original.call(instance, level, blockPos, blockState, bl);
if (!blockPos.equals(noUpdatePos)) {
return this.updateDir(level, blockPos, blockState, bl);
}
return blockState;
}
}
11 changes: 2 additions & 9 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@
"entrypoints": {
"main": [
"no2.railplacementfix.RailPlacementFix"
],
"client": [
"no2.railplacementfix.RailPlacementFixClient"
]
},
"mixins": [
"rail-placement-fix.mixins.json",
{
"config": "rail-placement-fix.client.mixins.json",
"environment": "client"
}
"rail-placement-fix.mixins.json"
],
"depends": {
"minecraft": "*"
"minecraft": ">=1.17"
}
}
1 change: 0 additions & 1 deletion src/main/resources/rail-placement-fix.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"required": true,
"package": "no2.railplacementfix.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"BaseRailBlockMixin"
],
Expand Down

0 comments on commit ca2e84c

Please sign in to comment.