Skip to content

Commit

Permalink
Added falling block rules
Browse files Browse the repository at this point in the history
  • Loading branch information
RLLD576 committed Nov 2, 2023
1 parent 24c5072 commit 8872a9d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G
carpet_core_version=1.4.84+v221018

# Mod Properties
mod_version = 1.19.2-1.0.0
mod_version = 1.19.2-1.1.0
maven_group = net.rober
archives_base_name = rober-carpet

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/net/rober/robercarpet/RoberCarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ public class RoberCarpetSettings {

@Rule(desc="The amount of ticks before thunderstorm that are needed for the mod to warn you about it",category = "rober")
public static int ThunderWarn = 0;
}
@Rule(desc="Reintroduce the 1.12 falling block behavior",category={"rober","falling-block"})
public static boolean OldFallingBehavior = false;

@Rule(desc="Age in gameticks at which falling blocks die, -1 for infinity. (Vanilla is 600)",category = {"rober","falling-block"})
public static int FallingBlockDieAge = 600;

@Rule(desc="Falling blocks over walls would not have friction with the floor as in 1.12",category = {"rober","falling-block"})
public static boolean FallingBlockNoFrictionWithWalls = false;
}
44 changes: 44 additions & 0 deletions src/main/java/net/rober/robercarpet/mixin/FallingBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.rober.robercarpet.mixin;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.rober.robercarpet.RoberCarpetSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(FallingBlockEntity.class)
public abstract class FallingBlockMixin {
@Redirect(method = "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z"))
private boolean FallingBlockBehaviorMixin(BlockState blockHitResult, Block arg){
FallingBlockEntity self = (FallingBlockEntity) (Object) this;
BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down();
Block underneath = self.world.getBlockState(pos).getBlock();
return blockHitResult.isOf(arg)||(underneath==Blocks.AIR&& RoberCarpetSettings.OldFallingBehavior);
}
@Redirect(method="tick()V",at=@At(value="INVOKE",target = "Lnet/minecraft/util/math/Vec3d;multiply(DDD)Lnet/minecraft/util/math/Vec3d;",ordinal = 0))
private Vec3d FrictionMixin(Vec3d vec,double x,double y,double z){
FallingBlockEntity self = (FallingBlockEntity) (Object) this;
BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down();
Block underneath = self.world.getBlockState(pos).getBlock();
return underneath==Blocks.AIR&&RoberCarpetSettings.FallingBlockNoFrictionWithWalls?vec:vec.multiply(x,y,z);
}

@ModifyConstant(method = "tick()V",constant = @Constant(intValue = 600))
private int AgeMixin(int a){
if(RoberCarpetSettings.FallingBlockDieAge==-1) {
return (int) Double.POSITIVE_INFINITY;
} else if (RoberCarpetSettings.FallingBlockDieAge>0) {
return RoberCarpetSettings.FallingBlockDieAge;
}
return 600;
}

}
1 change: 1 addition & 0 deletions src/main/resources/robercarpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "net.rober.robercarpet.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"FallingBlockMixin",
"SleepingDelayMixin",
"ThunderWarnMixin"
],
Expand Down

0 comments on commit 8872a9d

Please sign in to comment.