-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
240 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..."); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/dev/ithundxr/railwaystweaks/mixin/LivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkRailingBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/dev/ithundxr/railwaystweaks/mixin/createdeco/CatwalkStairBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters