cleanup, gamerule for lightning rod range

This commit is contained in:
2022-11-13 18:25:58 +01:00
parent ff1cbb8644
commit dfefed1286
7 changed files with 57 additions and 19 deletions
@@ -0,0 +1,25 @@
package me.youhavetrouble.moregamerules;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.minecraft.world.GameRules;
public class ExtraGameRule {
public static GameRules.Key<GameRules.BooleanRule> MAGMA_BLOCK_DAMAGE;
public static GameRules.Key<GameRules.IntRule> LIGHTNING_ROD_RANGE;
protected static void init() {
MAGMA_BLOCK_DAMAGE = GameRuleRegistry.register(
"magmaBlockDamage",
GameRules.Category.MISC,
GameRuleFactory.createBooleanRule(true)
);
LIGHTNING_ROD_RANGE = GameRuleRegistry.register(
"lightningRodRange",
GameRules.Category.MISC,
GameRuleFactory.createIntRule(128, 0, Integer.MAX_VALUE)
);
}
}
@@ -1,26 +1,15 @@
package me.youhavetrouble.moregamerules;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.minecraft.world.GameRules;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MoreGameRules implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("moregamerules");
public static GameRules.Key<GameRules.BooleanRule> MAGMA_BLOCK_DAMAGE;
public static final Logger LOGGER = LoggerFactory.getLogger("MoreGameRules");
@Override
public void onInitialize() {
MAGMA_BLOCK_DAMAGE = GameRuleRegistry.register(
"magmaBlockDamage",
GameRules.Category.MISC,
GameRuleFactory.createBooleanRule(true)
);
ExtraGameRule.init();
LOGGER.info("Finished loading up!");
}
}
@@ -1,6 +1,6 @@
package me.youhavetrouble.moregamerules.mixin;
import me.youhavetrouble.moregamerules.MoreGameRules;
import me.youhavetrouble.moregamerules.ExtraGameRule;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.MagmaBlock;
@@ -21,6 +21,6 @@ public class MagmaBlockMixin extends Block {
@Inject(at = @At("HEAD"), method = "onSteppedOn", cancellable = true)
private void injectedOnSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo info) {
if (!world.getGameRules().getBoolean(MoreGameRules.MAGMA_BLOCK_DAMAGE)) info.cancel();
if (!world.getGameRules().getBoolean(ExtraGameRule.MAGMA_BLOCK_DAMAGE)) info.cancel();
}
}
@@ -0,0 +1,18 @@
package me.youhavetrouble.moregamerules.mixin;
import me.youhavetrouble.moregamerules.ExtraGameRule;
import net.minecraft.server.world.ServerWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(ServerWorld.class)
public class ServerWorldMixin {
@ModifyArg(method = "getLightningRodPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/poi/PointOfInterestStorage;getNearestPosition(Ljava/util/function/Predicate;Ljava/util/function/Predicate;Lnet/minecraft/util/math/BlockPos;ILnet/minecraft/world/poi/PointOfInterestStorage$OccupationStatus;)Ljava/util/Optional;"), index = 3)
private int injectedGetLightningRodPos(int range) {
ServerWorld serverWorld = (ServerWorld)(Object) this;
return serverWorld.getGameRules().getInt(ExtraGameRule.LIGHTNING_ROD_RANGE);
}
}
@@ -1,4 +1,6 @@
{
"gamerule.magmaBlockDamage": "Magma block damage",
"gamerule.magmaBlockDamage.description": "Controls if magma blocks should do damage when stepped on"
"gamerule.magmaBlockDamage.description": "Controls if magma blocks should do damage when stepped on",
"gamerule.lightningRodRange": "Lightning rod range",
"gamerule.lightningRodRange.description": "Sets the range in which lightning rod will redirect lightning"
}
+1 -1
View File
@@ -14,7 +14,7 @@
},
"license": "CC0-1.0",
"icon": "assets/modid/icon.png",
"icon": "assets/moregamerules/icon.png",
"environment": "*",
"entrypoints": {
+6 -2
View File
@@ -3,10 +3,14 @@
"minVersion": "0.8",
"package": "me.youhavetrouble.moregamerules.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [],
"client": [],
"mixins": [
"ServerWorldMixin"
],
"client": [
],
"server": [
"MagmaBlockMixin"
],
"injectors": {
"defaultRequire": 1