From 6770e4a1b675cdc42820f98b3a37c91ac6e5c292 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 31 Mar 2024 17:23:15 -0400 Subject: [PATCH] Fixes and general great things --- README.md | 8 ++ build.gradle | 15 +++- gradle.properties | 6 +- .../railwaystweaks/RailwaysTweaks.java | 7 +- .../mixin/LivingEntityMixin.java | 50 +++++++++++ .../createdeco/CatwalkRailingBlockMixin.java | 87 +++++++++++++++++++ .../createdeco/CatwalkStairBlockMixin.java | 68 +++++++++++++++ src/main/resources/railwaystweaks.mixins.json | 3 + 8 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 README.md create mode 100644 src/main/java/dev/ithundxr/railwaystweaks/mixin/LivingEntityMixin.java create mode 100644 src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkRailingBlockMixin.java create mode 100644 src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkStairBlockMixin.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..94dca87 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Railways Tweaks + +A mod made to assist in the Steam 'n' Rails modpack by fixing bugs, lag from unneeded things and small tweaks or game additions. + +## License +Railways Tweaks is licensed under the MIT license. See [LICENSE](LICENSE) for more information. + +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. \ No newline at end of file diff --git a/build.gradle b/build.gradle index ccfecb6..ccd0395 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,13 @@ base { repositories { maven { url = "https://maven.quiltmc.org/repository/release" } // Quilt Mappings maven { url = "https://maven.parchmentmc.org" } // Parchment mappings + maven { url = "https://api.modrinth.com/maven" } // Create Deco + maven { url = "https://mvn.devos.one/snapshots/" } // Create, Porting Lib, Forge Tags, Milk Lib, Registrate + maven { url = "https://mvn.devos.one/releases/" } // Porting Lib Releases + maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" } // Forge Config API Port + maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes + maven { url = "https://jitpack.io/" } // Fabric ASM + maven { url = "https://maven.tterrag.com/" } // Flywheel } dependencies { @@ -25,8 +32,12 @@ dependencies { it.officialMojangMappings { nameSyntheticMembers = false } }) - modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}" + modImplementation("net.fabricmc:fabric-loader:${fabric_loader_version}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${fabric_api_version}") + + modImplementation("com.simibubi.create:create-fabric-${minecraft_version}:${create_version}") + + modImplementation("maven.modrinth:create-deco:2.0.1-1.20.1-fabric") } processResources { diff --git a/gradle.properties b/gradle.properties index 9bea4ea..156c531 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,8 @@ parchment_version = 2023.09.03 # Fabric Properties # check these on https://modmuss50.me/fabric.html fabric_loader_version=0.15.7 -fabric_api_version=0.92.0+1.20.1 \ No newline at end of file +fabric_api_version=0.92.0+1.20.1 + +# Create +# https://modrinth.com/mod/create-fabric/versions +create_version = 0.5.1-f-build.1335+mc1.20.1 \ No newline at end of file diff --git a/src/main/java/dev/ithundxr/railwaystweaks/RailwaysTweaks.java b/src/main/java/dev/ithundxr/railwaystweaks/RailwaysTweaks.java index 83fd1e3..7a3031e 100644 --- a/src/main/java/dev/ithundxr/railwaystweaks/RailwaysTweaks.java +++ b/src/main/java/dev/ithundxr/railwaystweaks/RailwaysTweaks.java @@ -1,10 +1,15 @@ package dev.ithundxr.railwaystweaks; import net.fabricmc.api.ModInitializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class RailwaysTweaks implements ModInitializer { + public static final String MODID = "railwaystweaks"; + public static final String NAME = "RailwaysTweaks"; + public static final Logger LOGGER = LoggerFactory.getLogger(MODID); @Override public void onInitialize() { - + LOGGER.info("Railways Tweaks is loading..."); } } diff --git a/src/main/java/dev/ithundxr/railwaystweaks/mixin/LivingEntityMixin.java b/src/main/java/dev/ithundxr/railwaystweaks/mixin/LivingEntityMixin.java new file mode 100644 index 0000000..bbf2842 --- /dev/null +++ b/src/main/java/dev/ithundxr/railwaystweaks/mixin/LivingEntityMixin.java @@ -0,0 +1,50 @@ +/** + * Copied from Elytra-Bounce which is licensed under Apache 2.0 + *

+ * https://github.com/infernalstudios/Elytra-Bounce/blob/1d5374837a9fc426cb620deaf86925a2f0fc93ef/LICENSE + */ + +package dev.ithundxr.railwaystweaks.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +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.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LivingEntity.class) +public abstract class LivingEntityMixin extends Entity { + public LivingEntityMixin(EntityType entityType, Level level) { + super(entityType, level); + } + + @Unique private int elytraBounce$ticksOnGround = 0; + @Unique private boolean elytraBounce$wasGoodBefore = false; + + @ModifyArg(method = "travel(Lnet/minecraft/world/phys/Vec3;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setSharedFlag(IZ)V"), index = 1) + private boolean elytraBounce$travel(boolean in) { + if (elytraBounce$ticksOnGround <= 5) { + return true; + } + + return in; + } + + @Inject(method = "updateFallFlying()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setSharedFlag(IZ)V", shift = At.Shift.AFTER)) + private void elytraBounce$updateFallFlying(CallbackInfo ci, @Local boolean flag) { + if (elytraBounce$wasGoodBefore && !flag && onGround()) { + elytraBounce$ticksOnGround++; + elytraBounce$wasGoodBefore = true; + setSharedFlag(Entity.FLAG_FALL_FLYING, true); + return; + } + + elytraBounce$ticksOnGround = 0; + } +} diff --git a/src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkRailingBlockMixin.java b/src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkRailingBlockMixin.java new file mode 100644 index 0000000..be73bec --- /dev/null +++ b/src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkRailingBlockMixin.java @@ -0,0 +1,87 @@ +package dev.ithundxr.railwaystweaks.mixin.createdeco; + +import com.github.talrey.createdeco.blocks.CatwalkRailingBlock; +import com.simibubi.create.content.equipment.wrench.IWrenchable; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CatwalkRailingBlock.class) +public abstract class CatwalkRailingBlockMixin implements IWrenchable { + @Shadow public static BooleanProperty fromDirection(Direction face) { throw new AssertionError(); } + + @Shadow @Final public static BooleanProperty EAST_FENCE; + @Shadow @Final public static BooleanProperty WEST_FENCE; + @Shadow @Final public static BooleanProperty NORTH_FENCE; + @Shadow @Final public static BooleanProperty SOUTH_FENCE; + + /** + * @author IThundxr + * @reason Create deco load's client classes on the server; + */ + @Overwrite + public InteractionResult onSneakWrenched(BlockState state, UseOnContext context) { + BlockPos pos = context.getClickedPos(); + Vec3 subbox = context.getClickLocation().subtract(pos.getCenter()); + Direction face = context.getClickedFace(); + Level level = context.getLevel(); + Player player = context.getPlayer(); + var x = subbox.x; + var z = subbox.z; + + if (level.isClientSide) + return InteractionResult.PASS; + + //check if the top face is wrenched, remove side + if (face == Direction.UP) { + boolean bottomleft = x < -z; + boolean topleft = x < z; + var dir = Direction.WEST; + if (!bottomleft && topleft) dir = Direction.SOUTH; + if (!bottomleft && !topleft) dir = Direction.EAST; + if (bottomleft && !topleft) dir = Direction.NORTH; + if (bottomleft && topleft) dir = Direction.WEST; + + //obscure edge case where a corner of the top face cannot be wrenched + if (state.getValue(fromDirection(dir))) { + state = state.setValue(fromDirection(dir), false); + level.setBlock(pos, state, 3); + playRemoveSound(level, pos); + if (!player.getAbilities().instabuild) player.addItem(new ItemStack(state.getBlock().asItem())); + return InteractionResult.SUCCESS; + } + else return InteractionResult.PASS; + } + + //check for wrenching the inside faces + if (x == 0.375 || x == -0.375 || z == 0.375 || z == -0.375) state = state.setValue(fromDirection(face.getOpposite()), false); + + //check for wrenching the outside faces + if (x == 0.5 || x == -0.5 || z == 0.5 || z == -0.5) { + if (!state.getValue(fromDirection(face))) { + if (x >= 0.375) state = state.setValue(EAST_FENCE, false); + if (x <= -0.375) state = state.setValue(WEST_FENCE, false); + if (z <= -0.375) state = state.setValue(NORTH_FENCE, false); + if (z >= 0.375) state = state.setValue(SOUTH_FENCE, false); + } + else state = state.setValue(fromDirection(face), false); + } + + level.setBlock(pos, state, 3); + playRemoveSound(level, pos); + if (!player.getAbilities().instabuild) player.addItem(new ItemStack(state.getBlock().asItem())); + return InteractionResult.SUCCESS; + } +} diff --git a/src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkStairBlockMixin.java b/src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkStairBlockMixin.java new file mode 100644 index 0000000..aaf62f0 --- /dev/null +++ b/src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkStairBlockMixin.java @@ -0,0 +1,68 @@ +package dev.ithundxr.railwaystweaks.mixin.createdeco; + +import com.github.talrey.createdeco.BlockRegistry; +import com.github.talrey.createdeco.blocks.CatwalkStairBlock; +import com.simibubi.create.content.equipment.wrench.IWrenchable; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CatwalkStairBlock.class) +public class CatwalkStairBlockMixin implements IWrenchable { + @Shadow @Final public static BooleanProperty RAILING_RIGHT; + @Shadow @Final public static BooleanProperty RAILING_LEFT; + @Shadow @Final public String metal; + + /** + * @author IThundxr + * @reason Create deco load's client classes on the server; + */ + @Overwrite + public InteractionResult onSneakWrenched(BlockState state, UseOnContext context) { + BlockPos pos = context.getClickedPos(); + Vec3 subbox = context.getClickLocation().subtract(pos.getCenter()); + Level level = context.getLevel(); + Player player = context.getPlayer(); + + if (state.getValue(RAILING_RIGHT) || state.getValue(RAILING_LEFT)) { + var xPos = subbox.x; + var zPos = subbox.z; + + var dir = state.getValue(BlockStateProperties.HORIZONTAL_FACING); + boolean left = false; + + if (dir == Direction.NORTH) left = xPos > 0; + if (dir == Direction.SOUTH) left = xPos < 0; + if (dir == Direction.EAST) left = zPos > 0; + if (dir == Direction.WEST) left = zPos < 0; + + if (level.isClientSide || !state.getValue(left ? CatwalkStairBlock.RAILING_LEFT : CatwalkStairBlock.RAILING_RIGHT)) + return InteractionResult.PASS; + + level.setBlock(pos, state.setValue(left ? CatwalkStairBlock.RAILING_LEFT : CatwalkStairBlock.RAILING_RIGHT, false), 3); + + if (!player.getAbilities().instabuild) player.addItem(new ItemStack( + BlockRegistry.CATWALK_RAILINGS.get(metal) + )); + playRemoveSound(level, pos); + return InteractionResult.SUCCESS; + } + + level.removeBlock(pos, false); + if (!player.getAbilities().instabuild) player.addItem(new ItemStack(state.getBlock().asItem())); + playRemoveSound(level, pos); + return InteractionResult.SUCCESS; + } +} diff --git a/src/main/resources/railwaystweaks.mixins.json b/src/main/resources/railwaystweaks.mixins.json index 75cb4ec..d80fcd9 100644 --- a/src/main/resources/railwaystweaks.mixins.json +++ b/src/main/resources/railwaystweaks.mixins.json @@ -4,6 +4,9 @@ "package": "dev.ithundxr.railwaystweaks.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "LivingEntityMixin", + "createdeco.CatwalkRailingBlockMixin", + "createdeco.CatwalkStairBlockMixin" ], "client": [ ],