Skip to content

Commit

Permalink
Fixes and general great things
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Mar 31, 2024
1 parent 3fbc692 commit 6770e4a
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 13 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Original file line number Diff line number Diff line change
@@ -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...");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copied from Elytra-Bounce which is licensed under Apache 2.0
* <p>
* 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/railwaystweaks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"package": "dev.ithundxr.railwaystweaks.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"LivingEntityMixin",
"createdeco.CatwalkRailingBlockMixin",
"createdeco.CatwalkStairBlockMixin"
],
"client": [
],
Expand Down

0 comments on commit 6770e4a

Please sign in to comment.