Skip to content

Commit

Permalink
Added falling block rules and updated gradle and loom
Browse files Browse the repository at this point in the history
  • Loading branch information
RLLD576 committed Nov 2, 2023
1 parent 417faa3 commit e8cf801
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 9 additions & 0 deletions src/main/java/net/rober/robercarpet/RoberCarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ 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;
}
43 changes: 43 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,43 @@
package net.rober.robercarpet.mixin;

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",ordinal = 1))
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))
public 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",
"FarmableClayMixin",
"SleepingDelayMixin",
"ThunderWarnMixin"
Expand Down

0 comments on commit e8cf801

Please sign in to comment.