diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..823aca8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# gradle + +.gradle/ +out/ +classes/ +build/ + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# fabric + +run/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ea9ed68 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 MidnightDust + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..590713a --- /dev/null +++ b/build.gradle @@ -0,0 +1,76 @@ +plugins { + id 'fabric-loom' version '0.5-SNAPSHOT' + id 'maven-publish' +} + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + +archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group + +minecraft { +} + +dependencies { + //to change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modCompile "net.fabricmc:fabric-loader:${project.loader_version}" + + modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" +} + +processResources { + inputs.property "version", project.version + + from(sourceSets.main.resources.srcDirs) { + include "fabric.mod.json" + expand "version": project.version + } + + from(sourceSets.main.resources.srcDirs) { + exclude "fabric.mod.json" + } +} + +// ensure that the encoding is set to UTF-8, no matter what the system default is +// this fixes some edge cases with special characters not displaying correctly +// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + +// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task +// if it is present. +// If you remove this task, sources will not be generated. +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = "sources" + from sourceSets.main.allSource +} + +jar { + from "LICENSE" +} + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + // add all the jars that should be included when publishing to maven + artifact(remapJar) { + builtBy remapJar + } + artifact(sourcesJar) { + builtBy remapSourcesJar + } + } + } + + // select the repositories you want to publish to + repositories { + // uncomment to publish to the local maven + // mavenLocal() + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..f6bab1c --- /dev/null +++ b/gradle.properties @@ -0,0 +1,17 @@ +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx1G + +# Fabric Properties + # check these on https://fabricmc.net/use + minecraft_version=1.16.5 + yarn_mappings=1.16.5+build.3 + loader_version=0.11.1 + +# Mod Properties + mod_version = 1.0.0 + maven_group = eu.midnightdust + archives_base_name = puddles + +# Dependencies + # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api + fabric_version=0.29.4+1.16 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..5c2d1cf Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..4b7e1f3 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..8e25e6c --- /dev/null +++ b/gradlew @@ -0,0 +1,188 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..9618d8d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..5b60df3 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + jcenter() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/eu/midnightdust/puddles/Puddles.java b/src/main/java/eu/midnightdust/puddles/Puddles.java new file mode 100644 index 0000000..4027979 --- /dev/null +++ b/src/main/java/eu/midnightdust/puddles/Puddles.java @@ -0,0 +1,29 @@ +package eu.midnightdust.puddles; + +import eu.midnightdust.puddles.block.PuddleBlock; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; +import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.Block; +import net.minecraft.block.Material; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +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 PUDDLE_SPAWN_RATE; + public static GameRules.Key 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)); + 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())); + } +} diff --git a/src/main/java/eu/midnightdust/puddles/PuddlesClient.java b/src/main/java/eu/midnightdust/puddles/PuddlesClient.java new file mode 100644 index 0000000..a47209f --- /dev/null +++ b/src/main/java/eu/midnightdust/puddles/PuddlesClient.java @@ -0,0 +1,33 @@ +package eu.midnightdust.puddles; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; +import net.fabricmc.fabric.impl.client.rendering.ColorProviderRegistryImpl; +import net.minecraft.block.Blocks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BuiltinBiomes; + +import java.util.Objects; + +import static eu.midnightdust.puddles.Puddles.*; + +@SuppressWarnings("deprecation") +public class PuddlesClient implements ClientModInitializer { + + @Override + public void onInitializeClient() { + // Colored Puddle Items & Blocks + ClientTickEvents.END_CLIENT_TICK.register(client -> { + int waterColor; + if (client.world != null) { + Biome biome = client.world.getBiome(client.player.getBlockPos()); + waterColor = biome.getWaterColor(); + } else waterColor = BuiltinBiomes.PLAINS.getWaterColor(); + + ColorProviderRegistry.ITEM.register((stack, tintIndex) -> waterColor, Puddles.Puddle); + }); + + ColorProviderRegistry.BLOCK.register((state, view, pos, tintIndex) -> Objects.requireNonNull(ColorProviderRegistryImpl.BLOCK.get(Blocks.WATER)).getColor(state, view, pos, tintIndex), Puddle); + } +} diff --git a/src/main/java/eu/midnightdust/puddles/block/PuddleBlock.java b/src/main/java/eu/midnightdust/puddles/block/PuddleBlock.java new file mode 100644 index 0000000..ea98240 --- /dev/null +++ b/src/main/java/eu/midnightdust/puddles/block/PuddleBlock.java @@ -0,0 +1,166 @@ +package eu.midnightdust.puddles.block; + +import eu.midnightdust.puddles.Puddles; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.*; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.*; +import net.minecraft.item.*; +import net.minecraft.loot.context.LootContext; +import net.minecraft.potion.PotionUtil; +import net.minecraft.potion.Potions; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.stat.Stats; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; + +import java.util.Collections; +import java.util.List; +import java.util.Random; + +@SuppressWarnings("deprecation") +public class PuddleBlock extends Block { + + protected final FlowableFluid fluid; + public static final VoxelShape COLLISION_SHAPE; + + public PuddleBlock(FlowableFluid fluid, AbstractBlock.Settings settings) { + super(settings); + this.fluid = fluid; + } + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + ItemStack itemStack = player.getStackInHand(hand); + if (itemStack.isEmpty()) { + return ActionResult.PASS; + } else { + Item item = itemStack.getItem(); + ItemStack waterBottleStack; + if (item == Items.GLASS_BOTTLE) { + if (!world.isClient) { + if (!player.abilities.creativeMode) { + 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)) { + player.dropItem(waterBottleStack, false); + } else if (player instanceof ServerPlayerEntity) { + ((ServerPlayerEntity)player).refreshScreenHandler(player.playerScreenHandler); + } + } + + world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.setBlockState(pos, Blocks.AIR.getDefaultState()); + } + return ActionResult.success(world.isClient); + } + else return ActionResult.FAIL; + } + + } + @Override + public boolean hasRandomTicks(BlockState state) { + return true; + } + @Override + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (!world.isRaining() && random.nextInt(2000) == 0) { + world.setBlockState(pos, Blocks.AIR.getDefaultState()); + } + + this.scheduledTick(state, world, pos, random); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return context.isAbove(COLLISION_SHAPE, pos, true) ? COLLISION_SHAPE : VoxelShapes.empty(); + } + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return COLLISION_SHAPE; + } + @Override + public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) { + return VoxelShapes.empty(); + } + + public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { + return true; + } + + public FluidState getFluidState(BlockState state) { + return fluid.getFlowing(1,false); + } + + @Environment(EnvType.CLIENT) + public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + return stateFrom.getFluidState().getFluid().matchesType(this.fluid); + } + + public BlockRenderType getRenderType(BlockState state) { + return BlockRenderType.INVISIBLE; + } + + public List getDroppedStacks(BlockState state, LootContext.Builder builder) { + return Collections.emptyList(); + } + + public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + if (world.getBlockState(pos) == Blocks.AIR.getDefaultState() || world.getBlockState(pos) == Puddles.Puddle.getDefaultState()) { + int i; + // Check if there are fluids on the sides or corners of the block above + for (i = 2; i < 6; ++i) { + BlockPos pos1 = pos.up(); + BlockPos pos2 = pos1.offset(Direction.byId(i)); + if (!world.getFluidState(pos1.offset(Direction.byId(i))).isEmpty()) { + // When sides of the block above have water don't place the puddle + return false; + } + if (!world.getFluidState(pos2.offset(Direction.byId(i).rotateYClockwise())).isEmpty()) { + // When corners of the block above have water don't place the puddle + return false; + } + } + // Check if there are fluids on the sides or corners of the block below + for (i = 2; i < 6; ++i) { + BlockPos pos1 = pos.down(); + BlockPos pos2 = pos1.offset(Direction.byId(i)); + if (!world.getFluidState(pos1.offset(Direction.byId(i))).isEmpty()) { + // When sides of the block below have water don't place the puddle + return false; + } + if (!world.getFluidState(pos2.offset(Direction.byId(i).rotateYClockwise())).isEmpty()) { + // When corners of the block below have water don't place the puddle + return false; + } + } + return world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos, Direction.UP); + } + // When there's already another block at the position don't place the puddle + else return false; + } + public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) { + return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom); + } + + static { + COLLISION_SHAPE = net.minecraft.block.Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 0.5D, 16.0D); + } +} + diff --git a/src/main/java/eu/midnightdust/puddles/mixin/MixinServerWorld.java b/src/main/java/eu/midnightdust/puddles/mixin/MixinServerWorld.java new file mode 100644 index 0000000..d1bd884 --- /dev/null +++ b/src/main/java/eu/midnightdust/puddles/mixin/MixinServerWorld.java @@ -0,0 +1,63 @@ +package eu.midnightdust.puddles.mixin; + +import eu.midnightdust.puddles.Puddles; +import net.minecraft.block.Blocks; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.profiler.Profiler; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.*; +import net.minecraft.world.chunk.WorldChunk; +import net.minecraft.world.dimension.DimensionType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.Supplier; + +@Mixin(ServerWorld.class) +public abstract class MixinServerWorld extends World { + protected MixinServerWorld(MutableWorldProperties properties, RegistryKey registryRef, DimensionType dimensionType, Supplier profiler, boolean isClient, boolean debugWorld, long seed) { + super(properties, registryRef, dimensionType, profiler, isClient, debugWorld, seed); + } + + @Shadow protected abstract BlockPos getSurface(BlockPos pos); + + @Inject(at = @At("TAIL"),method = "tickChunk") + public void tickChunk(WorldChunk chunk, int randomTickSpeed, CallbackInfo ci) { + ChunkPos chunkPos = chunk.getPos(); + boolean bl = this.isRaining(); + int x = chunkPos.getStartX(); + int z = chunkPos.getStartZ(); + Profiler profiler = this.getProfiler(); + BlockPos pos; + + if (this.getGameRules().getInt(Puddles.PUDDLE_SPAWN_RATE) != 0) { + profiler.push("puddles"); + if (bl && random.nextInt(10000 / this.getGameRules().getInt(Puddles.PUDDLE_SPAWN_RATE)) == 0) { + pos = this.getSurface(getRandomPosInChunk(x, 0, z, 15)); + if (this.hasRain(pos) && getBlockState(pos.down()).isSideSolidFullSquare(this, pos, Direction.UP)) { + setBlockState(pos, Puddles.Puddle.getDefaultState()); + } + } + profiler.pop(); + } + + if (this.getGameRules().getInt(Puddles.SNOW_STACK_CHANCE) != 0) { + profiler.push("extra_snow"); + if (bl && random.nextInt(10000 / this.getGameRules().getInt(Puddles.SNOW_STACK_CHANCE)) == 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); + setBlockState(pos, Blocks.SNOW.getDefaultState().with(Properties.LAYERS, layer + 1)); + } + } + profiler.pop(); + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/puddles/blockstates/puddle.json b/src/main/resources/assets/puddles/blockstates/puddle.json new file mode 100644 index 0000000..42ee27c --- /dev/null +++ b/src/main/resources/assets/puddles/blockstates/puddle.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "puddles:block/puddle" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/puddles/icon.png b/src/main/resources/assets/puddles/icon.png new file mode 100644 index 0000000..e7a155c Binary files /dev/null and b/src/main/resources/assets/puddles/icon.png differ diff --git a/src/main/resources/assets/puddles/lang/en_us.json b/src/main/resources/assets/puddles/lang/en_us.json new file mode 100644 index 0000000..ee95555 --- /dev/null +++ b/src/main/resources/assets/puddles/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "block.puddles.puddle":"Puddle" +} \ No newline at end of file diff --git a/src/main/resources/assets/puddles/models/block/puddle.json b/src/main/resources/assets/puddles/models/block/puddle.json new file mode 100644 index 0000000..2df7f06 --- /dev/null +++ b/src/main/resources/assets/puddles/models/block/puddle.json @@ -0,0 +1,7 @@ +{ + "credit": "made by Motschen", + "parent": "block/block", + "textures": { + "particle": "block/water_still" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/puddles/models/item/puddle.json b/src/main/resources/assets/puddles/models/item/puddle.json new file mode 100644 index 0000000..ad258f4 --- /dev/null +++ b/src/main/resources/assets/puddles/models/item/puddle.json @@ -0,0 +1,22 @@ +{ + "credit": "made by Motschen", + "parent": "block/block", + "textures": { + "0": "block/water_still", + "particle": "block/water_still" + }, + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 1, 16], + "faces": { + "north": {"uv": [0, 0, 16, 1], "texture": "#0", "tintindex": 0}, + "east": {"uv": [0, 0, 16, 1], "texture": "#0", "tintindex": 0}, + "south": {"uv": [0, 0, 16, 1], "texture": "#0", "tintindex": 0}, + "west": {"uv": [0, 0, 16, 1], "texture": "#0", "tintindex": 0}, + "up": {"uv": [0, 0, 16, 16], "texture": "#0", "tintindex": 0}, + "down": {"uv": [0, 0, 16, 16], "texture": "#0", "tintindex": 0} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..210b1ef --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,34 @@ +{ + "schemaVersion": 1, + "id": "puddles", + "version": "${version}", + + "name": "Puddles", + "description": "Adds puddles. Compatible with your favorite shaderpacks & mods!", + "authors": [ + "Motschen", + "TeamMidnightDust" + ], + "contact": { + "homepage": "https://www.midnightdust.eu/", + "sources": "https://github.com/TeamMidnightDust/Puddles", + "issues": "https://github.com/TeamMidnightDust/Puddles/issues" + }, + + "license": "MIT", + "icon": "assets/puddles/icon.png", + + "environment": "*", + "entrypoints": { + "main": [ + "eu.midnightdust.puddles.Puddles" + ], + "client": [ + "eu.midnightdust.puddles.PuddlesClient" + ] + }, + + "mixins": [ + "puddles.mixins.json" + ] +} diff --git a/src/main/resources/puddles.mixins.json b/src/main/resources/puddles.mixins.json new file mode 100644 index 0000000..f9ba2b7 --- /dev/null +++ b/src/main/resources/puddles.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "eu.midnightdust.puddles.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "MixinServerWorld" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file