Skip to content

Commit 6770e4a

Browse files
committed
Fixes and general great things
1 parent 3fbc692 commit 6770e4a

8 files changed

+240
-4
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Railways Tweaks
2+
3+
A mod made to assist in the Steam 'n' Rails modpack by fixing bugs, lag from unneeded things and small tweaks or game additions.
4+
5+
## License
6+
Railways Tweaks is licensed under the MIT license. See [LICENSE](LICENSE) for more information.
7+
8+
Most of the code for bouncing with elytra's is from Elytra-Bounce, which is licensed under the Apache 2.0 license. See [Elytra-Bounce's license](https://github.com/infernalstudios/Elytra-Bounce/blob/1d5374837a9fc426cb620deaf86925a2f0fc93ef/LICENSE) for more information.

build.gradle

+13-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ base {
1313
repositories {
1414
maven { url = "https://maven.quiltmc.org/repository/release" } // Quilt Mappings
1515
maven { url = "https://maven.parchmentmc.org" } // Parchment mappings
16+
maven { url = "https://api.modrinth.com/maven" } // Create Deco
17+
maven { url = "https://mvn.devos.one/snapshots/" } // Create, Porting Lib, Forge Tags, Milk Lib, Registrate
18+
maven { url = "https://mvn.devos.one/releases/" } // Porting Lib Releases
19+
maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" } // Forge Config API Port
20+
maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes
21+
maven { url = "https://jitpack.io/" } // Fabric ASM
22+
maven { url = "https://maven.tterrag.com/" } // Flywheel
1623
}
1724

1825
dependencies {
@@ -25,8 +32,12 @@ dependencies {
2532
it.officialMojangMappings { nameSyntheticMembers = false }
2633
})
2734

28-
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
29-
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
35+
modImplementation("net.fabricmc:fabric-loader:${fabric_loader_version}")
36+
modImplementation("net.fabricmc.fabric-api:fabric-api:${fabric_api_version}")
37+
38+
modImplementation("com.simibubi.create:create-fabric-${minecraft_version}:${create_version}")
39+
40+
modImplementation("maven.modrinth:create-deco:2.0.1-1.20.1-fabric")
3041
}
3142

3243
processResources {

gradle.properties

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ parchment_version = 2023.09.03
1717
# Fabric Properties
1818
# check these on https://modmuss50.me/fabric.html
1919
fabric_loader_version=0.15.7
20-
fabric_api_version=0.92.0+1.20.1
20+
fabric_api_version=0.92.0+1.20.1
21+
22+
# Create
23+
# https://modrinth.com/mod/create-fabric/versions
24+
create_version = 0.5.1-f-build.1335+mc1.20.1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package dev.ithundxr.railwaystweaks;
22

33
import net.fabricmc.api.ModInitializer;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46

57
public class RailwaysTweaks implements ModInitializer {
8+
public static final String MODID = "railwaystweaks";
9+
public static final String NAME = "RailwaysTweaks";
10+
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);
611
@Override
712
public void onInitialize() {
8-
13+
LOGGER.info("Railways Tweaks is loading...");
914
}
1015
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copied from Elytra-Bounce which is licensed under Apache 2.0
3+
* <p>
4+
* https://github.com/infernalstudios/Elytra-Bounce/blob/1d5374837a9fc426cb620deaf86925a2f0fc93ef/LICENSE
5+
*/
6+
7+
package dev.ithundxr.railwaystweaks.mixin;
8+
9+
import com.llamalad7.mixinextras.sugar.Local;
10+
import net.minecraft.world.entity.Entity;
11+
import net.minecraft.world.entity.EntityType;
12+
import net.minecraft.world.entity.LivingEntity;
13+
import net.minecraft.world.level.Level;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Unique;
16+
import org.spongepowered.asm.mixin.injection.At;
17+
import org.spongepowered.asm.mixin.injection.Inject;
18+
import org.spongepowered.asm.mixin.injection.ModifyArg;
19+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
20+
21+
@Mixin(LivingEntity.class)
22+
public abstract class LivingEntityMixin extends Entity {
23+
public LivingEntityMixin(EntityType<?> entityType, Level level) {
24+
super(entityType, level);
25+
}
26+
27+
@Unique private int elytraBounce$ticksOnGround = 0;
28+
@Unique private boolean elytraBounce$wasGoodBefore = false;
29+
30+
@ModifyArg(method = "travel(Lnet/minecraft/world/phys/Vec3;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setSharedFlag(IZ)V"), index = 1)
31+
private boolean elytraBounce$travel(boolean in) {
32+
if (elytraBounce$ticksOnGround <= 5) {
33+
return true;
34+
}
35+
36+
return in;
37+
}
38+
39+
@Inject(method = "updateFallFlying()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setSharedFlag(IZ)V", shift = At.Shift.AFTER))
40+
private void elytraBounce$updateFallFlying(CallbackInfo ci, @Local boolean flag) {
41+
if (elytraBounce$wasGoodBefore && !flag && onGround()) {
42+
elytraBounce$ticksOnGround++;
43+
elytraBounce$wasGoodBefore = true;
44+
setSharedFlag(Entity.FLAG_FALL_FLYING, true);
45+
return;
46+
}
47+
48+
elytraBounce$ticksOnGround = 0;
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package dev.ithundxr.railwaystweaks.mixin.createdeco;
2+
3+
import com.github.talrey.createdeco.blocks.CatwalkRailingBlock;
4+
import com.simibubi.create.content.equipment.wrench.IWrenchable;
5+
import net.minecraft.core.BlockPos;
6+
import net.minecraft.core.Direction;
7+
import net.minecraft.world.InteractionResult;
8+
import net.minecraft.world.entity.player.Player;
9+
import net.minecraft.world.item.ItemStack;
10+
import net.minecraft.world.item.context.UseOnContext;
11+
import net.minecraft.world.level.Level;
12+
import net.minecraft.world.level.block.Block;
13+
import net.minecraft.world.level.block.state.BlockState;
14+
import net.minecraft.world.level.block.state.properties.BooleanProperty;
15+
import net.minecraft.world.phys.Vec3;
16+
import org.spongepowered.asm.mixin.Final;
17+
import org.spongepowered.asm.mixin.Mixin;
18+
import org.spongepowered.asm.mixin.Overwrite;
19+
import org.spongepowered.asm.mixin.Shadow;
20+
21+
@Mixin(CatwalkRailingBlock.class)
22+
public abstract class CatwalkRailingBlockMixin implements IWrenchable {
23+
@Shadow public static BooleanProperty fromDirection(Direction face) { throw new AssertionError(); }
24+
25+
@Shadow @Final public static BooleanProperty EAST_FENCE;
26+
@Shadow @Final public static BooleanProperty WEST_FENCE;
27+
@Shadow @Final public static BooleanProperty NORTH_FENCE;
28+
@Shadow @Final public static BooleanProperty SOUTH_FENCE;
29+
30+
/**
31+
* @author IThundxr
32+
* @reason Create deco load's client classes on the server;
33+
*/
34+
@Overwrite
35+
public InteractionResult onSneakWrenched(BlockState state, UseOnContext context) {
36+
BlockPos pos = context.getClickedPos();
37+
Vec3 subbox = context.getClickLocation().subtract(pos.getCenter());
38+
Direction face = context.getClickedFace();
39+
Level level = context.getLevel();
40+
Player player = context.getPlayer();
41+
var x = subbox.x;
42+
var z = subbox.z;
43+
44+
if (level.isClientSide)
45+
return InteractionResult.PASS;
46+
47+
//check if the top face is wrenched, remove side
48+
if (face == Direction.UP) {
49+
boolean bottomleft = x < -z;
50+
boolean topleft = x < z;
51+
var dir = Direction.WEST;
52+
if (!bottomleft && topleft) dir = Direction.SOUTH;
53+
if (!bottomleft && !topleft) dir = Direction.EAST;
54+
if (bottomleft && !topleft) dir = Direction.NORTH;
55+
if (bottomleft && topleft) dir = Direction.WEST;
56+
57+
//obscure edge case where a corner of the top face cannot be wrenched
58+
if (state.getValue(fromDirection(dir))) {
59+
state = state.setValue(fromDirection(dir), false);
60+
level.setBlock(pos, state, 3);
61+
playRemoveSound(level, pos);
62+
if (!player.getAbilities().instabuild) player.addItem(new ItemStack(state.getBlock().asItem()));
63+
return InteractionResult.SUCCESS;
64+
}
65+
else return InteractionResult.PASS;
66+
}
67+
68+
//check for wrenching the inside faces
69+
if (x == 0.375 || x == -0.375 || z == 0.375 || z == -0.375) state = state.setValue(fromDirection(face.getOpposite()), false);
70+
71+
//check for wrenching the outside faces
72+
if (x == 0.5 || x == -0.5 || z == 0.5 || z == -0.5) {
73+
if (!state.getValue(fromDirection(face))) {
74+
if (x >= 0.375) state = state.setValue(EAST_FENCE, false);
75+
if (x <= -0.375) state = state.setValue(WEST_FENCE, false);
76+
if (z <= -0.375) state = state.setValue(NORTH_FENCE, false);
77+
if (z >= 0.375) state = state.setValue(SOUTH_FENCE, false);
78+
}
79+
else state = state.setValue(fromDirection(face), false);
80+
}
81+
82+
level.setBlock(pos, state, 3);
83+
playRemoveSound(level, pos);
84+
if (!player.getAbilities().instabuild) player.addItem(new ItemStack(state.getBlock().asItem()));
85+
return InteractionResult.SUCCESS;
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package dev.ithundxr.railwaystweaks.mixin.createdeco;
2+
3+
import com.github.talrey.createdeco.BlockRegistry;
4+
import com.github.talrey.createdeco.blocks.CatwalkStairBlock;
5+
import com.simibubi.create.content.equipment.wrench.IWrenchable;
6+
import net.minecraft.core.BlockPos;
7+
import net.minecraft.core.Direction;
8+
import net.minecraft.world.InteractionResult;
9+
import net.minecraft.world.entity.player.Player;
10+
import net.minecraft.world.item.ItemStack;
11+
import net.minecraft.world.item.context.UseOnContext;
12+
import net.minecraft.world.level.Level;
13+
import net.minecraft.world.level.block.state.BlockState;
14+
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
15+
import net.minecraft.world.level.block.state.properties.BooleanProperty;
16+
import net.minecraft.world.phys.Vec3;
17+
import org.spongepowered.asm.mixin.Final;
18+
import org.spongepowered.asm.mixin.Mixin;
19+
import org.spongepowered.asm.mixin.Overwrite;
20+
import org.spongepowered.asm.mixin.Shadow;
21+
22+
@Mixin(CatwalkStairBlock.class)
23+
public class CatwalkStairBlockMixin implements IWrenchable {
24+
@Shadow @Final public static BooleanProperty RAILING_RIGHT;
25+
@Shadow @Final public static BooleanProperty RAILING_LEFT;
26+
@Shadow @Final public String metal;
27+
28+
/**
29+
* @author IThundxr
30+
* @reason Create deco load's client classes on the server;
31+
*/
32+
@Overwrite
33+
public InteractionResult onSneakWrenched(BlockState state, UseOnContext context) {
34+
BlockPos pos = context.getClickedPos();
35+
Vec3 subbox = context.getClickLocation().subtract(pos.getCenter());
36+
Level level = context.getLevel();
37+
Player player = context.getPlayer();
38+
39+
if (state.getValue(RAILING_RIGHT) || state.getValue(RAILING_LEFT)) {
40+
var xPos = subbox.x;
41+
var zPos = subbox.z;
42+
43+
var dir = state.getValue(BlockStateProperties.HORIZONTAL_FACING);
44+
boolean left = false;
45+
46+
if (dir == Direction.NORTH) left = xPos > 0;
47+
if (dir == Direction.SOUTH) left = xPos < 0;
48+
if (dir == Direction.EAST) left = zPos > 0;
49+
if (dir == Direction.WEST) left = zPos < 0;
50+
51+
if (level.isClientSide || !state.getValue(left ? CatwalkStairBlock.RAILING_LEFT : CatwalkStairBlock.RAILING_RIGHT))
52+
return InteractionResult.PASS;
53+
54+
level.setBlock(pos, state.setValue(left ? CatwalkStairBlock.RAILING_LEFT : CatwalkStairBlock.RAILING_RIGHT, false), 3);
55+
56+
if (!player.getAbilities().instabuild) player.addItem(new ItemStack(
57+
BlockRegistry.CATWALK_RAILINGS.get(metal)
58+
));
59+
playRemoveSound(level, pos);
60+
return InteractionResult.SUCCESS;
61+
}
62+
63+
level.removeBlock(pos, false);
64+
if (!player.getAbilities().instabuild) player.addItem(new ItemStack(state.getBlock().asItem()));
65+
playRemoveSound(level, pos);
66+
return InteractionResult.SUCCESS;
67+
}
68+
}

src/main/resources/railwaystweaks.mixins.json

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"package": "dev.ithundxr.railwaystweaks.mixin",
55
"compatibilityLevel": "JAVA_17",
66
"mixins": [
7+
"LivingEntityMixin",
8+
"createdeco.CatwalkRailingBlockMixin",
9+
"createdeco.CatwalkStairBlockMixin"
710
],
811
"client": [
912
],

0 commit comments

Comments
 (0)