mirror of
https://github.com/TeamMidnightDust/Puddles.git
synced 2025-12-16 20:15:10 +01:00
Puddles 1.2.0 - Update to 1.17, MidnightLib and configurable evaporation chance
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package eu.midnightdust.puddles;
|
||||
|
||||
import eu.midnightdust.puddles.block.PuddleBlock;
|
||||
import eu.midnightdust.puddles.config.PuddlesConfig;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
|
||||
@@ -17,12 +18,9 @@ import net.minecraft.world.GameRules;
|
||||
public class Puddles implements ModInitializer {
|
||||
public static final String MOD_ID = "puddles";
|
||||
public static final Block Puddle = new PuddleBlock(Fluids.WATER, FabricBlockSettings.of(Material.WATER));
|
||||
public static GameRules.Key<GameRules.IntRule> PUDDLE_SPAWN_RATE;
|
||||
public static GameRules.Key<GameRules.IntRule> SNOW_STACK_CHANCE;
|
||||
|
||||
public void onInitialize() {
|
||||
PUDDLE_SPAWN_RATE = GameRuleRegistry.register("puddleSpawnRate", GameRules.Category.SPAWNING, GameRuleFactory.createIntRule(1));
|
||||
SNOW_STACK_CHANCE = GameRuleRegistry.register("snowStackChance", GameRules.Category.SPAWNING, GameRuleFactory.createIntRule(1));
|
||||
PuddlesConfig.init(MOD_ID, PuddlesConfig.class);
|
||||
Registry.register(Registry.BLOCK, new Identifier(MOD_ID,"puddle"), Puddle);
|
||||
Registry.register(Registry.ITEM, new Identifier(MOD_ID,"puddle"), new BlockItem(Puddle, new Item.Settings()));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Objects;
|
||||
|
||||
import static eu.midnightdust.puddles.Puddles.*;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PuddlesClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +19,7 @@ public class PuddlesClient implements ClientModInitializer {
|
||||
// Colored Puddle Items & Blocks
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
int waterColor;
|
||||
if (client.world != null) {
|
||||
if (client.world != null && client.player != null) {
|
||||
Biome biome = client.world.getBiome(client.player.getBlockPos());
|
||||
waterColor = biome.getWaterColor();
|
||||
} else waterColor = BuiltinBiomes.PLAINS.getWaterColor();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.midnightdust.puddles.block;
|
||||
|
||||
import eu.midnightdust.puddles.Puddles;
|
||||
import eu.midnightdust.puddles.config.PuddlesConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.*;
|
||||
@@ -52,16 +53,16 @@ public class PuddleBlock extends Block {
|
||||
ItemStack waterBottleStack;
|
||||
if (item == Items.GLASS_BOTTLE) {
|
||||
if (!world.isClient) {
|
||||
if (!player.abilities.creativeMode) {
|
||||
if (!player.isCreative()) {
|
||||
waterBottleStack = PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER);
|
||||
player.incrementStat(Stats.USE_CAULDRON);
|
||||
itemStack.decrement(1);
|
||||
if (itemStack.isEmpty()) {
|
||||
player.setStackInHand(hand, waterBottleStack);
|
||||
} else if (!player.inventory.insertStack(waterBottleStack)) {
|
||||
} else if (!player.getInventory().insertStack(waterBottleStack)) {
|
||||
player.dropItem(waterBottleStack, false);
|
||||
} else if (player instanceof ServerPlayerEntity) {
|
||||
((ServerPlayerEntity)player).refreshScreenHandler(player.playerScreenHandler);
|
||||
player.currentScreenHandler.sendContentUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ public class PuddleBlock extends Block {
|
||||
}
|
||||
@Override
|
||||
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||
if (!world.isRaining() && random.nextInt(2000) == 0) {
|
||||
if (!world.isRaining() && random.nextInt(10000 / PuddlesConfig.evaporationChance) == 0) {
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ public class PuddleBlock extends Block {
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return context.isAbove(COLLISION_SHAPE, pos, true) ? COLLISION_SHAPE : VoxelShapes.empty();
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
|
||||
12
src/main/java/eu/midnightdust/puddles/config/PuddlesConfig.java
Executable file
12
src/main/java/eu/midnightdust/puddles/config/PuddlesConfig.java
Executable file
@@ -0,0 +1,12 @@
|
||||
package eu.midnightdust.puddles.config;
|
||||
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
|
||||
public class PuddlesConfig extends MidnightConfig {
|
||||
@Entry // Enable or disable hats for contributors, friends and donors.
|
||||
public static int puddleSpawnRate = 1;
|
||||
@Entry
|
||||
public static int snowStackChance = 1;
|
||||
@Entry
|
||||
public static int evaporationChance = 5;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.midnightdust.puddles.mixin;
|
||||
|
||||
import eu.midnightdust.puddles.Puddles;
|
||||
import eu.midnightdust.puddles.config.PuddlesConfig;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.property.Properties;
|
||||
@@ -20,6 +21,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class MixinServerWorld extends World {
|
||||
protected MixinServerWorld(MutableWorldProperties properties, RegistryKey<World> registryRef, DimensionType dimensionType, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long seed) {
|
||||
@@ -37,9 +39,9 @@ public abstract class MixinServerWorld extends World {
|
||||
Profiler profiler = this.getProfiler();
|
||||
BlockPos pos;
|
||||
|
||||
if (this.getGameRules().getInt(Puddles.PUDDLE_SPAWN_RATE) != 0) {
|
||||
if (PuddlesConfig.puddleSpawnRate != 0) {
|
||||
profiler.push("puddles");
|
||||
if (bl && random.nextInt(10000 / this.getGameRules().getInt(Puddles.PUDDLE_SPAWN_RATE)) == 0) {
|
||||
if (bl && random.nextInt(10000 / PuddlesConfig.puddleSpawnRate) == 0) {
|
||||
pos = this.getSurface(getRandomPosInChunk(x, 0, z, 15));
|
||||
if (this.hasRain(pos) && getBlockState(pos.down()).isSideSolidFullSquare(this, pos, Direction.UP) && Puddles.Puddle.canPlaceAt(null,this,pos)) {
|
||||
setBlockState(pos, Puddles.Puddle.getDefaultState());
|
||||
@@ -48,9 +50,9 @@ public abstract class MixinServerWorld extends World {
|
||||
profiler.pop();
|
||||
}
|
||||
|
||||
if (this.getGameRules().getInt(Puddles.SNOW_STACK_CHANCE) != 0) {
|
||||
if (PuddlesConfig.snowStackChance != 0) {
|
||||
profiler.push("extra_snow");
|
||||
if (bl && random.nextInt(10000 / this.getGameRules().getInt(Puddles.SNOW_STACK_CHANCE)) == 0) {
|
||||
if (bl && random.nextInt(10000 / PuddlesConfig.snowStackChance) == 0) {
|
||||
pos = this.getSurface(getRandomPosInChunk(x, 0, z, 15));
|
||||
if (this.getBlockState(pos).getBlock() == Blocks.SNOW && getBlockState(pos.down()).isSideSolidFullSquare(this, pos, Direction.UP)) {
|
||||
int layer = getBlockState(pos).get(Properties.LAYERS);
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
{
|
||||
"block.puddles.puddle":"Puddle"
|
||||
"block.puddles.puddle":"Puddle",
|
||||
"puddles.midnightconfig.title": "Puddles Config",
|
||||
"puddles.midnightconfig.puddleSpawnRate": "Puddle Spawn Rate",
|
||||
"puddles.midnightconfig.snowStackChance": "Snow Stack Chance",
|
||||
"puddles.midnightconfig.evaporationChance": "Evaporation Chance"
|
||||
}
|
||||
Reference in New Issue
Block a user