Compare commits

..

No commits in common. "1880bf785d93138df111cca8c3e10e0b6d20a873" and "d079f5aa97b96c95158e01b4d5ce8f66fb9cc8dd" have entirely different histories.

215 changed files with 3807 additions and 3855 deletions

View file

@ -1,7 +1,7 @@
# NaturesAura # NaturesAura
Nature's Aura is a mod about collecting, using and replenishing the Aura Nature's Aura is a mod about collecting, using and replenishing the Aura
naturally present in the level to create useful devices and unique mechanics. naturally present in the world to create useful devices and unique mechanics.
## Maven ## Maven

View file

@ -1,11 +1,11 @@
buildscript { buildscript {
repositories { repositories {
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below maven { url = 'https://files.minecraftforge.net/maven' }
maven { url = 'https://maven.minecraftforge.net' } jcenter()
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
} }
} }
apply plugin: 'net.minecraftforge.gradle' apply plugin: 'net.minecraftforge.gradle'
@ -20,11 +20,10 @@ archivesBaseName = 'NaturesAura'
if (System.getenv('BUILD_NUMBER') != null) { if (System.getenv('BUILD_NUMBER') != null) {
version += "." + System.getenv('BUILD_NUMBER') version += "." + System.getenv('BUILD_NUMBER')
} }
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
minecraft { minecraft {
mappings channel: 'official', version: '1.18' mappings channel: 'snapshot', version: '20200723-1.16.1'
runs { runs {
client { client {
@ -102,22 +101,18 @@ repositories {
} }
dependencies { dependencies {
minecraft 'net.minecraftforge:forge:1.18-38.0.14' minecraft 'net.minecraftforge:forge:1.16.5-36.1.3'
// TODO JEI compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api")
/* compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api") runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75")
runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75")*/
// TDOO Patchouli compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api")
/* compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api") runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50")
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50")*/
// TODO Curios runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0")
/* runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0") compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0:api")
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0:api")*/
// TODO Enchantability compile fg.deobf("quarris.enchantability:Enchantability:11.0.48")
/* compile fg.deobf("quarris.enchantability:Enchantability:11.0.48")*/
} }
// Example for how to get properties into the manifest for reading by the runtime.. // Example for how to get properties into the manifest for reading by the runtime..

Binary file not shown.

View file

@ -1,5 +1,6 @@
#Sun Oct 20 21:47:13 CEST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip

286
gradlew vendored
View file

@ -1,129 +1,78 @@
#!/bin/sh #!/usr/bin/env sh
#
# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. ## Gradle start up script for UN*X
# ##
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
############################################################################## ##############################################################################
# Attempt to set APP_HOME # Attempt to set APP_HOME
# Resolve links: $0 may be a link # Resolve links: $0 may be a link
app_path=$0 PRG="$0"
# Need this for relative symlinks.
# Need this for daisy-chained symlinks. while [ -h "$PRG" ] ; do
while ls=`ls -ld "$PRG"`
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path link=`expr "$ls" : '.*-> \(.*\)$'`
[ -h "$app_path" ] if expr "$link" : '/.*' > /dev/null; then
do PRG="$link"
ls=$( ls -ld "$app_path" ) else
link=${ls#*' -> '} PRG=`dirname "$PRG"`"/$link"
case $link in #( fi
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done done
SAVED="`pwd`"
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle" APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} 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. # 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"' DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD="maximum"
warn () { warn () {
echo "$*" echo "$*"
} >&2 }
die () { die () {
echo echo
echo "$*" echo "$*"
echo echo
exit 1 exit 1
} >&2 }
# OS specific support (must be 'true' or 'false'). # OS specific support (must be 'true' or 'false').
cygwin=false cygwin=false
msys=false msys=false
darwin=false darwin=false
nonstop=false nonstop=false
case "$( uname )" in #( case "`uname`" in
CYGWIN* ) cygwin=true ;; #( CYGWIN* )
Darwin* ) darwin=true ;; #( cygwin=true
MSYS* | MINGW* ) msys=true ;; #( ;;
NONSTOP* ) nonstop=true ;; Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables # IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java JAVACMD="$JAVA_HOME/jre/sh/java"
else else
JAVACMD=$JAVA_HOME/bin/java JAVACMD="$JAVA_HOME/bin/java"
fi fi
if [ ! -x "$JAVACMD" ] ; then if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@ -132,7 +81,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi fi
else else
JAVACMD=java 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. 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 Please set the JAVA_HOME variable in your environment to match the
@ -140,95 +89,84 @@ location of your Java installation."
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
case $MAX_FD in #( MAX_FD_LIMIT=`ulimit -H -n`
max*) if [ $? -eq 0 ] ; then
MAX_FD=$( ulimit -H -n ) || if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
warn "Could not query maximum file descriptor limit" MAX_FD="$MAX_FD_LIMIT"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi fi
# Roll the args list around exactly as many times as the number of ulimit -n $MAX_FD
# args, so each arg winds up back in the position where it started, but if [ $? -ne 0 ] ; then
# possibly modified. warn "Could not set maximum file descriptor limit: $MAX_FD"
# fi
# NB: a `for` loop captures its iteration list before it begins, so else
# changing the positional parameters here affects neither the number of warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
# iterations, nor the values presented in `arg`. fi
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi fi
# Collect all arguments for the java command; # For Darwin, add options to specify how the application appears in the dock
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of if $darwin; then
# shell script including quotes and variable substitutions, so put them in GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
# double quotes to make sure that they get re-expanded; and fi
# * put everything else in single quotes, so that it's not re-expanded.
set -- \ # For Cygwin, switch paths to Windows format before running java
"-Dorg.gradle.appname=$APP_BASE_NAME" \ if $cygwin ; then
-classpath "$CLASSPATH" \ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
org.gradle.wrapper.GradleWrapperMain \ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
"$@" JAVACMD=`cygpath --unix "$JAVACMD"`
# Use "xargs" to parse quoted args. # We build the pattern for arguments to be converted via cygpath
# ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
# With -n1 it outputs one arg per line, with the quotes and backslashes removed. SEP=""
# for dir in $ROOTDIRSRAW ; do
# In Bash we could simply go: ROOTDIRS="$ROOTDIRS$SEP$dir"
# SEP="|"
# readarray ARGS < <( xargs -n1 <<<"$var" ) && done
# set -- "${ARGS[@]}" "$@" OURCYGPATTERN="(^($ROOTDIRS))"
# # Add a user-defined pattern to the cygpath arguments
# but POSIX shell has neither arrays nor command substitution, so instead we if [ "$GRADLE_CYGPATTERN" != "" ] ; then
# post-process each arg (as a line of input to sed) to backslash-escape any OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
# character that might be a shell metacharacter, then use eval to reverse fi
# that process (while maintaining the separation between arguments), and wrap # Now convert the arguments - kludge to limit ourselves to /bin/sh
# the whole thing up as a single "set" statement. i=0
# for arg in "$@" ; do
# This will of course break if any of these variables contains a newline or CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
# an unmatched quote. CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
#
eval "set -- $( if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
xargs -n1 | else
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | eval `echo args$i`="\"$arg\""
tr '\n' ' ' 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" "$@" exec "$JAVACMD" "$@"

43
gradlew.bat vendored
View file

@ -1,19 +1,3 @@
@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 @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@ -29,18 +13,15 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @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" set DEFAULT_JVM_OPTS=
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if "%ERRORLEVEL%" == "0" goto init
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -54,7 +35,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto init
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@ -64,14 +45,28 @@ echo location of your Java installation.
goto fail 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 :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* "%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 :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell

View file

@ -1,64 +1,74 @@
package de.ellpeck.naturesaura; package de.ellpeck.naturesaura;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
import de.ellpeck.naturesaura.chunk.AuraChunk; import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.compat.Compat;
import net.minecraft.core.BlockPos; import de.ellpeck.naturesaura.misc.WorldData;
import net.minecraft.core.Direction; import net.minecraft.advancements.Advancement;
import net.minecraft.resources.ResourceLocation; import net.minecraft.block.Block;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.block.BlockState;
import net.minecraft.sounds.SoundEvents; import net.minecraft.client.Minecraft;
import net.minecraft.sounds.SoundSource; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.world.InteractionHand; import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.world.InteractionResult; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.item.Item;
import net.minecraft.world.entity.player.Player; import net.minecraft.item.ItemStack;
import net.minecraft.world.item.Item; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.world.item.ItemStack; import net.minecraft.nbt.INBT;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.state.Property;
import net.minecraft.world.level.ChunkPos; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.level.Level; import net.minecraft.util.*;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.phys.AABB; import net.minecraft.world.IWorld;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.World;
import net.minecraft.world.chunk.AbstractChunkProvider;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import top.theillusivec4.curios.api.CuriosApi;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
public final class Helper { public final class Helper {
public static boolean getBlockEntitiesInArea(Level level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) { public static boolean getTileEntitiesInArea(IWorld world, BlockPos pos, int radius, Function<TileEntity, Boolean> consumer) {
for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) { for (int x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) { for (int z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
var chunk = getLoadedChunk(level, x, z); Chunk chunk = getLoadedChunk(world, x, z);
if (chunk != null) { if (chunk != null) {
for (var tilePos : chunk.getBlockEntitiesPos()) { for (BlockPos tilePos : chunk.getTileEntitiesPos()) {
if (tilePos.distSqr(pos) <= radius * radius) if (tilePos.distanceSq(pos) <= radius * radius)
if (consumer.apply(chunk.getBlockEntity(tilePos))) if (consumer.apply(chunk.getTileEntity(tilePos)))
return true; return true;
} }
} }
@ -67,86 +77,99 @@ public final class Helper {
return false; return false;
} }
public static void getAuraChunksWithSpotsInArea(Level level, BlockPos pos, int radius, Consumer<AuraChunk> consumer) { public static void getAuraChunksWithSpotsInArea(World world, BlockPos pos, int radius, Consumer<AuraChunk> consumer) {
var data = (LevelData) ILevelData.getLevelData(level); WorldData data = (WorldData) IWorldData.getWorldData(world);
for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) { for (int x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) { for (int z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
var chunk = data.auraChunksWithSpots.get(ChunkPos.asLong(x, z)); AuraChunk chunk = data.auraChunksWithSpots.get(ChunkPos.asLong(x, z));
if (chunk != null) if (chunk != null)
consumer.accept(chunk); consumer.accept(chunk);
} }
} }
} }
public static List<ItemFrame> getAttachedItemFrames(Level level, BlockPos pos) { public static List<ItemFrameEntity> getAttachedItemFrames(World world, BlockPos pos) {
var frames = level.getEntitiesOfClass(ItemFrame.class, new AABB(pos).inflate(0.25)); List<ItemFrameEntity> frames = world.getEntitiesWithinAABB(ItemFrameEntity.class, new AxisAlignedBB(pos).grow(0.25));
for (var i = frames.size() - 1; i >= 0; i--) { for (int i = frames.size() - 1; i >= 0; i--) {
var frame = frames.get(i); ItemFrameEntity frame = frames.get(i);
var framePos = frame.getPos().relative(frame.getDirection().getOpposite()); BlockPos framePos = frame.getHangingPosition().offset(frame.getHorizontalFacing().getOpposite());
if (!pos.equals(framePos)) if (!pos.equals(framePos))
frames.remove(i); frames.remove(i);
} }
return frames; return frames;
} }
public static LevelChunk getLoadedChunk(Level level, int x, int z) { public static Chunk getLoadedChunk(IWorld world, int x, int z) {
// DO NOT EDIT PLEASE FOR THE LOVE OF GOD // DO NOT EDIT PLEASE FOR THE LOVE OF GOD
// This is very finicky and easily causes the game to hang for some reason // This is very finicky and easily causes the game to hang for some reason
var provider = level.getChunkSource(); AbstractChunkProvider provider = world.getChunkProvider();
if (provider.hasChunk(x, z)) if (provider.isChunkLoaded(new ChunkPos(x, z)))
return provider.getChunk(x, z, false); return provider.getChunk(x, z, false);
return null; return null;
} }
public static int blendColors(int c1, int c2, float ratio) { public static int blendColors(int c1, int c2, float ratio) {
var a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio)); int a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio));
var r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio)); int r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio));
var g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio)); int g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio));
var b = (int) ((c1 & 0xFF) * ratio + (c2 & 0xFF) * (1 - ratio)); int b = (int) ((c1 & 0xFF) * ratio + (c2 & 0xFF) * (1 - ratio));
return (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | b & 255; return (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | b & 255;
} }
public static boolean areItemsEqual(ItemStack first, ItemStack second, boolean nbt) { public static boolean areItemsEqual(ItemStack first, ItemStack second, boolean nbt) {
if (!ItemStack.isSame(first, second)) if (!ItemStack.areItemsEqual(first, second))
return false; return false;
return !nbt || ItemStack.tagMatches(first, second); return !nbt || ItemStack.areItemStackTagsEqual(first, second);
} }
public static InteractionResult putStackOnTile(Player player, InteractionHand hand, BlockPos pos, int slot, boolean sound) { @OnlyIn(Dist.CLIENT)
var tile = player.level.getBlockEntity(pos); public static void renderItemInGui(ItemStack stack, int x, int y, float scale) {
if (tile instanceof BlockEntityImpl) { RenderSystem.pushMatrix();
var handler = ((BlockEntityImpl) tile).getItemHandler(); GlStateManager.enableBlend();
GlStateManager.enableDepthTest();
RenderSystem.enableRescaleNormal();
RenderSystem.translatef(x, y, 0);
RenderSystem.scalef(scale, scale, scale);
Minecraft.getInstance().getItemRenderer().renderItemAndEffectIntoGUI(stack, 0, 0);
Minecraft.getInstance().getItemRenderer().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, stack, 0, 0, null);
RenderSystem.popMatrix();
}
public static ActionResultType putStackOnTile(PlayerEntity player, Hand hand, BlockPos pos, int slot, boolean sound) {
TileEntity tile = player.world.getTileEntity(pos);
if (tile instanceof TileEntityImpl) {
IItemHandlerModifiable handler = ((TileEntityImpl) tile).getItemHandler();
if (handler != null) { if (handler != null) {
var handStack = player.getItemInHand(hand); ItemStack handStack = player.getHeldItem(hand);
if (!handStack.isEmpty()) { if (!handStack.isEmpty()) {
var remain = handler.insertItem(slot, handStack, player.level.isClientSide); ItemStack remain = handler.insertItem(slot, handStack, player.world.isRemote);
if (!ItemStack.isSame(remain, handStack)) { if (!ItemStack.areItemStacksEqual(remain, handStack)) {
if (sound) if (sound)
player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, player.world.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.PLAYERS, 0.75F, 1F); SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, SoundCategory.PLAYERS, 0.75F, 1F);
if (!player.level.isClientSide) if (!player.world.isRemote)
player.setItemInHand(hand, remain); player.setHeldItem(hand, remain);
return InteractionResult.SUCCESS; return ActionResultType.SUCCESS;
} }
} }
if (!handler.getStackInSlot(slot).isEmpty()) { if (!handler.getStackInSlot(slot).isEmpty()) {
if (sound) if (sound)
player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, player.world.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.PLAYERS, 0.75F, 1F); SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, SoundCategory.PLAYERS, 0.75F, 1F);
if (!player.level.isClientSide) { if (!player.world.isRemote) {
var stack = handler.getStackInSlot(slot); ItemStack stack = handler.getStackInSlot(slot);
if (!player.addItem(stack)) { if (!player.addItemStackToInventory(stack)) {
var item = new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), stack); ItemEntity item = new ItemEntity(player.world, player.getPosX(), player.getPosY(), player.getPosZ(), stack);
player.level.addFreshEntity(item); player.world.addEntity(item);
} }
handler.setStackInSlot(slot, ItemStack.EMPTY); handler.setStackInSlot(slot, ItemStack.EMPTY);
} }
return InteractionResult.SUCCESS; return ActionResultType.SUCCESS;
} }
} }
} }
return InteractionResult.CONSUME; return ActionResultType.CONSUME;
} }
public static ICapabilityProvider makeRechargeProvider(ItemStack stack, boolean needsSelected) { public static ICapabilityProvider makeRechargeProvider(ItemStack stack, boolean needsSelected) {
@ -168,8 +191,8 @@ public final class Helper {
} }
public static boolean rechargeAuraItem(ItemStack stack, IAuraContainer container, int toDrain) { public static boolean rechargeAuraItem(ItemStack stack, IAuraContainer container, int toDrain) {
if (stack.getDamageValue() > 0 && container.drainAura(toDrain, true) >= toDrain) { if (stack.getDamage() > 0 && container.drainAura(toDrain, true) >= toDrain) {
stack.setDamageValue(stack.getDamageValue() - 1); stack.setDamage(stack.getDamage() - 1);
container.drainAura(toDrain, false); container.drainAura(toDrain, false);
return true; return true;
} }
@ -177,15 +200,15 @@ public final class Helper {
} }
public static BlockState getStateFromString(String raw) { public static BlockState getStateFromString(String raw) {
var split = raw.split("\\["); String[] split = raw.split("\\[");
var block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0])); Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0]));
if (block != null) { if (block != null) {
var state = block.defaultBlockState(); BlockState state = block.getDefaultState();
if (split.length > 1) { if (split.length > 1) {
for (var part : split[1].replace("]", "").split(",")) { for (String part : split[1].replace("]", "").split(",")) {
var keyValue = part.split("="); String[] keyValue = part.split("=");
for (var prop : state.getProperties()) { for (Property<?> prop : state.getProperties()) {
var changed = findProperty(state, prop, keyValue[0], keyValue[1]); BlockState changed = findProperty(state, prop, keyValue[0], keyValue[1]);
if (changed != null) { if (changed != null) {
state = changed; state = changed;
break; break;
@ -200,23 +223,39 @@ public final class Helper {
private static <T extends Comparable<T>> BlockState findProperty(BlockState state, Property<T> prop, String key, String newValue) { private static <T extends Comparable<T>> BlockState findProperty(BlockState state, Property<T> prop, String key, String newValue) {
if (key.equals(prop.getName())) if (key.equals(prop.getName()))
for (var value : prop.getPossibleValues()) for (T value : prop.getAllowedValues())
if (prop.getName(value).equals(newValue)) if (prop.getName(value).equals(newValue))
return state.setValue(prop, value); return state.with(prop, value);
return null; return null;
} }
public static void addAdvancement(Player player, ResourceLocation advancement, String criterion) { public static <T> void registerCap(Class<T> type) {
if (!(player instanceof ServerPlayer playerMp)) CapabilityManager.INSTANCE.register(type, new Capability.IStorage<T>() {
@Override
public void readNBT(Capability<T> capability, T instance, Direction side, INBT nbt) {
}
@Nullable
@Override
public INBT writeNBT(Capability capability, Object instance, Direction side) {
return null;
}
}, () -> null);
}
public static void addAdvancement(PlayerEntity player, ResourceLocation advancement, String criterion) {
if (!(player instanceof ServerPlayerEntity))
return; return;
var adv = playerMp.getLevel().getServer().getAdvancements().getAdvancement(advancement); ServerPlayerEntity playerMp = (ServerPlayerEntity) player;
Advancement adv = playerMp.getServerWorld().getServer().getAdvancementManager().getAdvancement(advancement);
if (adv != null) if (adv != null)
playerMp.getAdvancements().award(adv, criterion); playerMp.getAdvancements().grantCriterion(adv, criterion);
} }
public static int getIngredientAmount(Ingredient ingredient) { public static int getIngredientAmount(Ingredient ingredient) {
var highestAmount = 0; int highestAmount = 0;
for (var stack : ingredient.getItems()) for (ItemStack stack : ingredient.getMatchingStacks())
if (stack.getCount() > highestAmount) if (stack.getCount() > highestAmount)
highestAmount = stack.getCount(); highestAmount = stack.getCount();
return highestAmount; return highestAmount;
@ -250,9 +289,9 @@ public final class Helper {
GL11.glVertex3d(x, y, z); GL11.glVertex3d(x, y, z);
} }
public static boolean isHoldingItem(Player player, Item item) { public static boolean isHoldingItem(PlayerEntity player, Item item) {
for (var hand : InteractionHand.values()) { for (Hand hand : Hand.values()) {
var stack = player.getItemInHand(hand); ItemStack stack = player.getHeldItem(hand);
if (!stack.isEmpty() && stack.getItem() == item) if (!stack.isEmpty() && stack.getItem() == item)
return true; return true;
} }
@ -260,22 +299,22 @@ public final class Helper {
} }
public static boolean isEmpty(IItemHandler handler) { public static boolean isEmpty(IItemHandler handler) {
for (var i = 0; i < handler.getSlots(); i++) for (int i = 0; i < handler.getSlots(); i++)
if (!handler.getStackInSlot(i).isEmpty()) if (!handler.getStackInSlot(i).isEmpty())
return false; return false;
return true; return true;
} }
public static AABB aabb(Vec3 pos) { public static AxisAlignedBB aabb(Vector3d pos) {
return new AABB(pos.x, pos.y, pos.z, pos.x, pos.y, pos.z); return new AxisAlignedBB(pos.x, pos.y, pos.z, pos.x, pos.y, pos.z);
} }
// This is how @ObjectHolder SHOULD work... // This is how @ObjectHolder _SHOULD_ work...
public static <T extends IForgeRegistryEntry<T>> void populateObjectHolders(Class<?> clazz, IForgeRegistry<T> registry) { public static <T extends IForgeRegistryEntry<T>> void populateObjectHolders(Class clazz, IForgeRegistry<T> registry) {
for (var entry : clazz.getFields()) { for (Field entry : clazz.getFields()) {
if (!Modifier.isStatic(entry.getModifiers())) if (!Modifier.isStatic(entry.getModifiers()))
continue; continue;
var location = new ResourceLocation(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT)); ResourceLocation location = new ResourceLocation(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT));
if (!registry.containsKey(location)) { if (!registry.containsKey(location)) {
NaturesAura.LOGGER.fatal("Couldn't find entry named " + location + " in registry " + registry.getRegistryName()); NaturesAura.LOGGER.fatal("Couldn't find entry named " + location + " in registry " + registry.getRegistryName());
continue; continue;
@ -288,15 +327,14 @@ public final class Helper {
} }
} }
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, Player player) { public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, PlayerEntity player) {
// TODO Curios if (Compat.hasCompat("curios")) {
/* if (Compat.hasCompat("curios")) {
Optional<ItemStack> stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight); Optional<ItemStack> stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight);
if (stack.isPresent()) if (stack.isPresent())
return stack.get(); return stack.get();
}*/ }
for (var i = 0; i < player.getInventory().getContainerSize(); i++) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
var slot = player.getInventory().getItem(i); ItemStack slot = player.inventory.getStackInSlot(i);
if (!slot.isEmpty() && predicate.test(slot)) if (!slot.isEmpty() && predicate.test(slot))
return slot; return slot;
} }

View file

@ -3,18 +3,18 @@ package de.ellpeck.naturesaura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.blocks.multi.Multiblock; import de.ellpeck.naturesaura.blocks.multi.Multiblock;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.WorldData;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.Level; import net.minecraft.world.World;
import org.apache.commons.lang3.mutable.MutableFloat; import org.apache.commons.lang3.mutable.MutableFloat;
import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.mutable.MutableObject;
@ -27,16 +27,16 @@ import java.util.function.BiConsumer;
public class InternalHooks implements NaturesAuraAPI.IInternalHooks { public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
@Override @Override
public boolean extractAuraFromPlayer(Player player, int amount, boolean simulate) { public boolean extractAuraFromPlayer(PlayerEntity player, int amount, boolean simulate) {
return this.auraPlayerInteraction(player, amount, true, simulate); return this.auraPlayerInteraction(player, amount, true, simulate);
} }
@Override @Override
public boolean insertAuraIntoPlayer(Player player, int amount, boolean simulate) { public boolean insertAuraIntoPlayer(PlayerEntity player, int amount, boolean simulate) {
return this.auraPlayerInteraction(player, amount, false, simulate); return this.auraPlayerInteraction(player, amount, false, simulate);
} }
private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) { private boolean auraPlayerInteraction(PlayerEntity player, int amount, boolean extract, boolean simulate) {
if (extract && player.isCreative()) if (extract && player.isCreative())
return true; return true;
ItemStack stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.capAuraContainer).isPresent(), player); ItemStack stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.capAuraContainer).isPresent(), player);
@ -90,18 +90,18 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public List<Tuple<Vector3d, Integer>> getActiveEffectPowders(Level level, AxisAlignedBB area, ResourceLocation name) { public List<Tuple<Vector3d, Integer>> getActiveEffectPowders(World world, AxisAlignedBB area, ResourceLocation name) {
List<Tuple<Vector3d, Integer>> found = new ArrayList<>(); List<Tuple<Vector3d, Integer>> found = new ArrayList<>();
for (Tuple<Vector3d, Integer> powder : ((LevelData) ILevelData.getLevelData(level)).effectPowders.get(name)) for (Tuple<Vector3d, Integer> powder : ((WorldData) IWorldData.getWorldData(world)).effectPowders.get(name))
if (area.contains(powder.getA())) if (area.contains(powder.getA()))
found.add(powder); found.add(powder);
return found; return found;
} }
@Override @Override
public boolean isEffectPowderActive(Level level, BlockPos pos, ResourceLocation name) { public boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name) {
Vector3d posVec = new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); Vector3d posVec = new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
List<Tuple<Vector3d, Integer>> powders = this.getActiveEffectPowders(level, new AxisAlignedBB(pos).grow(64), name); List<Tuple<Vector3d, Integer>> powders = this.getActiveEffectPowders(world, new AxisAlignedBB(pos).grow(64), name);
for (Tuple<Vector3d, Integer> powder : powders) { for (Tuple<Vector3d, Integer> powder : powders) {
AxisAlignedBB bounds = Helper.aabb(powder.getA()).grow(powder.getB()); AxisAlignedBB bounds = Helper.aabb(powder.getA()).grow(powder.getB());
if (bounds.contains(posVec)) if (bounds.contains(posVec))
@ -111,29 +111,29 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public void getAuraSpotsInArea(Level level, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) { public void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
Helper.getAuraChunksWithSpotsInArea(level, pos, radius, chunk -> chunk.getSpotsInArea(pos, radius, consumer)); Helper.getAuraChunksWithSpotsInArea(world, pos, radius, chunk -> chunk.getSpotsInArea(pos, radius, consumer));
} }
@Override @Override
public int getSpotAmountInArea(Level level, BlockPos pos, int radius) { public int getSpotAmountInArea(World world, BlockPos pos, int radius) {
MutableInt result = new MutableInt(); MutableInt result = new MutableInt();
this.getAuraSpotsInArea(level, pos, radius, (blockpos, drainSpot) -> result.increment()); this.getAuraSpotsInArea(world, pos, radius, (blockpos, drainSpot) -> result.increment());
return result.intValue(); return result.intValue();
} }
@Override @Override
public int getAuraInArea(Level level, BlockPos pos, int radius) { public int getAuraInArea(World world, BlockPos pos, int radius) {
MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA); MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA);
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot)); this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot));
return result.intValue(); return result.intValue();
} }
@Override @Override
public Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius) { public Pair<Integer, Integer> getAuraAndSpotAmountInArea(World world, BlockPos pos, int radius) {
MutableInt spots = new MutableInt(); MutableInt spots = new MutableInt();
MutableInt aura = new MutableInt(IAuraChunk.DEFAULT_AURA); MutableInt aura = new MutableInt(IAuraChunk.DEFAULT_AURA);
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
aura.add(drainSpot); aura.add(drainSpot);
spots.increment(); spots.increment();
}); });
@ -141,9 +141,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public int triangulateAuraInArea(Level level, BlockPos pos, int radius) { public int triangulateAuraInArea(World world, BlockPos pos, int radius) {
MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA); MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA);
IAuraChunk.getSpotsInArea(level, pos, radius, (blockPos, spot) -> { IAuraChunk.getSpotsInArea(world, pos, radius, (blockPos, spot) -> {
float percentage = 1F - (float) Math.sqrt(pos.distanceSq(blockPos)) / radius; float percentage = 1F - (float) Math.sqrt(pos.distanceSq(blockPos)) / radius;
result.add(spot * percentage); result.add(spot * percentage);
}); });
@ -151,10 +151,10 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) { public BlockPos getLowestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE); MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE);
MutableObject<BlockPos> lowestSpot = new MutableObject<>(); MutableObject<BlockPos> lowestSpot = new MutableObject<>();
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
if (drainSpot < lowestAmount.intValue()) { if (drainSpot < lowestAmount.intValue()) {
lowestAmount.setValue(drainSpot); lowestAmount.setValue(drainSpot);
lowestSpot.setValue(blockPos); lowestSpot.setValue(blockPos);
@ -167,10 +167,10 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
@Override @Override
public BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) { public BlockPos getHighestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) {
MutableInt highestAmount = new MutableInt(Integer.MIN_VALUE); MutableInt highestAmount = new MutableInt(Integer.MIN_VALUE);
MutableObject<BlockPos> highestSpot = new MutableObject<>(); MutableObject<BlockPos> highestSpot = new MutableObject<>();
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> {
if (drainSpot > highestAmount.intValue()) { if (drainSpot > highestAmount.intValue()) {
highestAmount.setValue(drainSpot); highestAmount.setValue(drainSpot);
highestSpot.setValue(blockPos); highestSpot.setValue(blockPos);

View file

@ -46,7 +46,7 @@ public final class ModConfig {
public ConfigValue<Integer> auraBarLocation; public ConfigValue<Integer> auraBarLocation;
public ConfigValue<Integer> cacheBarLocation; public ConfigValue<Integer> cacheBarLocation;
public ConfigValue<Boolean> debugText; public ConfigValue<Boolean> debugText;
public ConfigValue<Boolean> debugLevel; public ConfigValue<Boolean> debugWorld;
public ConfigValue<Boolean> renderItemsOnPlayer; public ConfigValue<Boolean> renderItemsOnPlayer;
public ModConfig(ForgeConfigSpec.Builder builder) { public ModConfig(ForgeConfigSpec.Builder builder) {
@ -131,7 +131,7 @@ public final class ModConfig {
.translation("config." + NaturesAura.MOD_ID + ".oreEffect") .translation("config." + NaturesAura.MOD_ID + ".oreEffect")
.define("oreEffect", true); .define("oreEffect", true);
this.auraBlooms = builder this.auraBlooms = builder
.comment("If Aura Blooms and Aura Cacti should generate in the level") .comment("If Aura Blooms and Aura Cacti should generate in the world")
.translation("config." + NaturesAura.MOD_ID + ".auraBlooms") .translation("config." + NaturesAura.MOD_ID + ".auraBlooms")
.define("auraBlooms", true); .define("auraBlooms", true);
this.netherGrassEffect = builder this.netherGrassEffect = builder
@ -165,10 +165,10 @@ public final class ModConfig {
.comment("If debug information about Aura around the player should be displayed in the F3 debug menu if the player is in creative mode") .comment("If debug information about Aura around the player should be displayed in the F3 debug menu if the player is in creative mode")
.translation("config." + NaturesAura.MOD_ID + ".debugText") .translation("config." + NaturesAura.MOD_ID + ".debugText")
.define("debugText", true); .define("debugText", true);
this.debugLevel = builder this.debugWorld = builder
.comment("If, when the F3 debug menu is open and the player is in creative mode, every Aura spot should be highlighted in the level for debug purposes") .comment("If, when the F3 debug menu is open and the player is in creative mode, every Aura spot should be highlighted in the world for debug purposes")
.translation("config." + NaturesAura.MOD_ID + ".debugLevel") .translation("config." + NaturesAura.MOD_ID + ".debugWorld")
.define("debugLevel", false); .define("debugWorld", false);
this.renderItemsOnPlayer = builder this.renderItemsOnPlayer = builder
.comment("If certain equippable items, like the Environmental Eye, should be rendered on the player") .comment("If certain equippable items, like the Environmental Eye, should be rendered on the player")
.translation("config." + NaturesAura.MOD_ID + ".renderItemsOnPlayer") .translation("config." + NaturesAura.MOD_ID + ".renderItemsOnPlayer")

View file

@ -5,7 +5,7 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.chunk.effect.DrainSpotEffects; import de.ellpeck.naturesaura.chunk.effect.DrainSpotEffects;
import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.compat.Compat;
@ -17,10 +17,11 @@ import de.ellpeck.naturesaura.proxy.IProxy;
import de.ellpeck.naturesaura.proxy.ServerProxy; import de.ellpeck.naturesaura.proxy.ServerProxy;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.world.item.CreativeModeTab; import net.minecraft.item.ItemGroup;
import net.minecraft.world.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DeferredWorkQueue;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@ -36,9 +37,9 @@ public final class NaturesAura {
public static final String MOD_NAME = "Nature's Aura"; public static final String MOD_NAME = "Nature's Aura";
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME); public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
public static final CreativeModeTab CREATIVE_TAB = new CreativeModeTab(MOD_ID) { public static final ItemGroup CREATIVE_TAB = new ItemGroup(MOD_ID) {
@Override @Override
public ItemStack makeIcon() { public ItemStack createIcon() {
return new ItemStack(ModItems.GOLD_LEAF); return new ItemStack(ModItems.GOLD_LEAF);
} }
}; };
@ -64,7 +65,7 @@ public final class NaturesAura {
Helper.registerCap(IAuraContainer.class); Helper.registerCap(IAuraContainer.class);
Helper.registerCap(IAuraRecharge.class); Helper.registerCap(IAuraRecharge.class);
Helper.registerCap(IAuraChunk.class); Helper.registerCap(IAuraChunk.class);
Helper.registerCap(ILevelData.class); Helper.registerCap(IWorldData.class);
Compat.setup(event); Compat.setup(event);
PacketHandler.init(); PacketHandler.init();

View file

@ -8,24 +8,24 @@ import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.aura.type.BasicAuraType; import de.ellpeck.naturesaura.api.aura.type.BasicAuraType;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.api.misc.WeatherType; import de.ellpeck.naturesaura.api.misc.WeatherType;
import de.ellpeck.naturesaura.api.misc.WeightedOre; import de.ellpeck.naturesaura.api.misc.WeightedOre;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.api.multiblock.Matcher; import de.ellpeck.naturesaura.api.multiblock.Matcher;
import net.minecraft.core.BlockPos; import net.minecraft.block.BlockState;
import net.minecraft.resources.ResourceLocation; import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.world.entity.EntityType; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.entity.player.Player; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.item.ItemStack; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.level.Level; import net.minecraft.world.IWorld;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.World;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityToken;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList; import java.util.ArrayList;
@ -46,34 +46,34 @@ public final class NaturesAuraAPI {
public static final String API_ID = MOD_ID + "api"; public static final String API_ID = MOD_ID + "api";
public static final String VERSION = "9"; public static final String VERSION = "9";
/** /**
* A map of all the block states that the Botanist's Pickaxe can convert * A map of all of the block states that the Botanist's Pickaxe can convert
* into their mossy variations. Contains mossy brick and mossy cobblestone * into their mossy variations. Contains mossy brick and mossy cobblestone
* by default, along with all blocks specified in the config file * by default, along with all blocks specified in the config file
*/ */
public static final BiMap<BlockState, BlockState> BOTANIST_PICKAXE_CONVERSIONS = HashBiMap.create(); public static final BiMap<BlockState, BlockState> BOTANIST_PICKAXE_CONVERSIONS = HashBiMap.create();
/** /**
* A map of all {@link IAuraType} instances which are types of Aura present * A map of all {@link IAuraType} instances which are types of Aura present
* in different types of levels. {@link BasicAuraType} instances can be * in different types of worlds. {@link BasicAuraType} instances can be
* easily registered using {@link BasicAuraType#register()}. * easily registered using {@link BasicAuraType#register()}.
*/ */
public static final Map<ResourceLocation, IAuraType> AURA_TYPES = new HashMap<>(); public static final Map<ResourceLocation, IAuraType> AURA_TYPES = new HashMap<>();
public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), Level.OVERWORLD, 0x89cc37, 0).register(); public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), World.field_234918_g_, 0x89cc37, 0).register();
public static final BasicAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), Level.NETHER, 0x871c0c, 0).register(); public static final BasicAuraType TYPE_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), World.field_234919_h_, 0x871c0c, 0).register();
public static final BasicAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), Level.END, 0x302624, 0).register(); public static final BasicAuraType TYPE_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), World.field_234920_i_, 0x302624, 0).register();
public static final BasicAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0, Integer.MIN_VALUE).register(); public static final BasicAuraType TYPE_OTHER = new BasicAuraType(new ResourceLocation(MOD_ID, "other"), null, 0x2fa8a0, Integer.MIN_VALUE).register();
/** /**
* A map of all {@link IDrainSpotEffect} suppliers which are effects that * A map of all {@link IDrainSpotEffect} suppliers which are effects that
* happen passively at every spot that Aura has been drained from in the * happen passively at every spot that Aura has been drained from in the
* level. These effects include things like vegetational increase and * world. These effects include things like vegetational increase and
* natural decay. To register your own drain spot effects, just add a * natural decay. To register your own drain spot effects, just add a
* supplier for them to this map, and they will automatically be executed * supplier for them to this map and they will automatically be executed
* once a second for every drain spot currently loaded. * once a second for every drain spot currently loaded.
*/ */
public static final Map<ResourceLocation, Supplier<IDrainSpotEffect>> DRAIN_SPOT_EFFECTS = new HashMap<>(); public static final Map<ResourceLocation, Supplier<IDrainSpotEffect>> DRAIN_SPOT_EFFECTS = new HashMap<>();
/** /**
* A map of all effect powder type. The integer the effect is registered to * A map of all effect powder type. The integer the effect is registered to
* is the color that the powder and its effect should have. To check if a * is the color that the powder and its effect should have. To check if a
* powder is active in any given area, use {@link IInternalHooks#isEffectPowderActive(Level, * powder is active in any given area, use {@link IInternalHooks#isEffectPowderActive(World,
* BlockPos, ResourceLocation)} * BlockPos, ResourceLocation)}
*/ */
public static final Map<ResourceLocation, Integer> EFFECT_POWDERS = new HashMap<>(); public static final Map<ResourceLocation, Integer> EFFECT_POWDERS = new HashMap<>();
@ -90,50 +90,48 @@ public final class NaturesAuraAPI {
public static final List<WeightedOre> OVERWORLD_ORES = new ArrayList<>(); public static final List<WeightedOre> OVERWORLD_ORES = new ArrayList<>();
/** /**
* A list of all {@link WeightedOre} objects that represent ores that can * A list of all {@link WeightedOre} objects that represent ores that can
* spawn inside netherrack blocks in the nether * spawn inside of netherrack blocks in the nether
*/ */
public static final List<WeightedOre> NETHER_ORES = new ArrayList<>(); public static final List<WeightedOre> NETHER_ORES = new ArrayList<>();
/** /**
* A map of all the entities' registry names to the amounts of aura they * A map of all of the entities' registry names to the amounts of aura they
* each generate in the projectile generator * each generate in the projectile generator
*/ */
public static final Map<EntityType<?>, Integer> PROJECTILE_GENERATIONS = new HashMap<>(); public static final Map<EntityType, Integer> PROJECTILE_GENERATIONS = new HashMap<>();
/** /**
* A map of all the items that cause the {@link WeatherType} to be changed * A map of all of the items that cause the {@link WeatherType} to be
* using the weather changer * changed using the weather changer
*/ */
public static final Map<ItemStack, WeatherType> WEATHER_CHANGER_CONVERSIONS = new HashMap<>(); public static final Map<ItemStack, WeatherType> WEATHER_CHANGER_CONVERSIONS = new HashMap<>();
/** /**
* The capability for any item or block that stores Aura in the form of an * The capability for any item or block that stores Aura in the form of an
* {@link IAuraContainer} * {@link IAuraContainer}
*/ */
public static Capability<IAuraContainer> capAuraContainer = CapabilityManager.get(new CapabilityToken<>() { @CapabilityInject(IAuraContainer.class)
}); public static Capability<IAuraContainer> capAuraContainer;
/** /**
* The capability for any item that can be recharged from an Aura storage * The capability for any item that can be recharged from an Aura storage
* container like the Aura Cache in the form of {@link IAuraRecharge} by a * container like the Aura Cache in the form of {@link IAuraRecharge} by a
* player holding it in their hand * player holding it in their hand
*/ */
public static Capability<IAuraRecharge> capAuraRecharge = CapabilityManager.get(new CapabilityToken<>() { @CapabilityInject(IAuraRecharge.class)
}); public static Capability<IAuraRecharge> capAuraRecharge;
/** /**
* The capability that any chunk in a level has to store Aura in it. As this * The capability that any chunk in a world has to store Aura in it. As this
* is only applicable to chunks and all chunks in the level automatically * is only applicable to chunks and all chunks in the world automatically
* get assigned this capability, using it directly is not necessary for * get assigned this capability, using it directly is not necessary for
* addon developers. To retrieve this capability from any chunk, use the * addon developers. To retrieve this capability from any chunk, use the
* helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level, * helper method {@link IAuraChunk#getAuraChunk(IWorld, BlockPos)}.
* BlockPos)}.
*/ */
public static Capability<IAuraChunk> capAuraChunk = CapabilityManager.get(new CapabilityToken<>() { @CapabilityInject(IAuraChunk.class)
}); public static Capability<IAuraChunk> capAuraChunk;
/** /**
* The capability that any level has to store Nature's Aura specific data in * The capability that any world has to store Nature's Aura specific data in
* it. To retrieve this capability from any level, use the helper methods * it. To retrieve this capability from any world, use the helper methods
* {@link ILevelData#getLevelData(net.minecraft.world.level.Level)} or * {@link IWorldData#getWorldData(World)} or {@link IWorldData#getOverworldData(World)}.
* {@link ILevelData#getOverworldData(net.minecraft.world.level.Level)}.
*/ */
public static Capability<ILevelData> capLevelData = CapabilityManager.get(new CapabilityToken<>() { @CapabilityInject(IWorldData.class)
}); public static Capability<IWorldData> capWorldData;
private static final IInternalHooks INSTANCE; private static final IInternalHooks INSTANCE;
static { static {
@ -171,7 +169,7 @@ public final class NaturesAuraAPI {
* @param simulate If the extraction should be simulated * @param simulate If the extraction should be simulated
* @return If the extraction was successful * @return If the extraction was successful
*/ */
boolean extractAuraFromPlayer(Player player, int amount, boolean simulate); boolean extractAuraFromPlayer(PlayerEntity player, int amount, boolean simulate);
/** /**
* Helper method to insert aura into an {@link IAuraContainer} in the * Helper method to insert aura into an {@link IAuraContainer} in the
@ -183,7 +181,7 @@ public final class NaturesAuraAPI {
* @param simulate If the insertion should be simulated * @param simulate If the insertion should be simulated
* @return If the insertion was successful * @return If the insertion was successful
*/ */
boolean insertAuraIntoPlayer(Player player, int amount, boolean simulate); boolean insertAuraIntoPlayer(PlayerEntity player, int amount, boolean simulate);
/** /**
* This method can be used to spawn the magic particle effect used by * This method can be used to spawn the magic particle effect used by
@ -264,65 +262,65 @@ public final class NaturesAuraAPI {
IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers); IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers);
/** /**
* Get all the active effect powders in the given area and consume the * Get all of the active effect powders in the given area and consume
* position and the range that they have. To register a powder with the * the position and the range that they have. To register a powder with
* supplied name, use {@link #EFFECT_POWDERS} * the supplied name, use {@link #EFFECT_POWDERS}
* *
* @param level The level * @param world The world
* @param area The area to find powders in * @param area The area to find powders in
* @param name The registry name of the powder * @param name The registry name of the powder
* @return A list of powders' positions and ranges * @return A list of powders' positions and ranges
*/ */
List<Tuple<Vec3, Integer>> getActiveEffectPowders(Level level, AABB area, ResourceLocation name); List<Tuple<Vector3d, Integer>> getActiveEffectPowders(World world, AxisAlignedBB area, ResourceLocation name);
/** /**
* Returns true if there is an effect powder entity active anywhere * Returns true if there is an effect powder entity active anywhere
* around the given position based on the radius it has. This is a * around the given position based on the radius it has. This is a
* shorthand function of {@link #getActiveEffectPowders(Level, * shorthand function of {@link #getActiveEffectPowders(World,
* net.minecraft.world.phys.AABB, ResourceLocation)} that returns true * AxisAlignedBB, ResourceLocation)} that returns true if the list is
* if the list is non-empty * non-empty
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param name The registry name of the powder * @param name The registry name of the powder
* @return If the effect is currently inhibited by any inhibitors * @return If the effect is currently inhibited by any inhibitors
*/ */
boolean isEffectPowderActive(Level level, BlockPos pos, ResourceLocation name); boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name);
/** /**
* @see IAuraChunk#getSpotsInArea(Level, BlockPos, int, BiConsumer) * @see IAuraChunk#getSpotsInArea(IWorld, BlockPos, int, BiConsumer)
*/ */
void getAuraSpotsInArea(Level level, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer); void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer);
/** /**
* @see IAuraChunk#getSpotAmountInArea(Level, BlockPos, int) * @see IAuraChunk#getSpotAmountInArea(IWorld, BlockPos, int)
*/ */
int getSpotAmountInArea(Level level, BlockPos pos, int radius); int getSpotAmountInArea(World world, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#getAuraInArea(Level, BlockPos, int) * @see IAuraChunk#getAuraInArea(IWorld, BlockPos, int)
*/ */
int getAuraInArea(Level level, BlockPos pos, int radius); int getAuraInArea(World world, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#getAuraAndSpotAmountInArea(Level, BlockPos, int) * @see IAuraChunk#getAuraAndSpotAmountInArea(World, BlockPos, int)
*/ */
Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius); Pair<Integer, Integer> getAuraAndSpotAmountInArea(World world, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#triangulateAuraInArea(Level, BlockPos, int) * @see IAuraChunk#triangulateAuraInArea(IWorld, BlockPos, int)
*/ */
int triangulateAuraInArea(Level level, BlockPos pos, int radius); int triangulateAuraInArea(World world, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#getLowestSpot(Level, BlockPos, int, BlockPos) * @see IAuraChunk#getLowestSpot(IWorld, BlockPos, int, BlockPos)
*/ */
BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot); BlockPos getLowestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot);
/** /**
* @see IAuraChunk#getHighestSpot(Level, BlockPos, int, BlockPos) * @see IAuraChunk#getHighestSpot(IWorld, BlockPos, int, BlockPos)
*/ */
BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot); BlockPos getHighestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot);
} }
} }

View file

@ -2,10 +2,11 @@ package de.ellpeck.naturesaura.api.aura.chunk;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.CompoundTag; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.Level; import net.minecraft.world.IWorld;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.INBTSerializable;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -13,13 +14,13 @@ import java.util.function.BiConsumer;
/** /**
* A class whose instances hold information about the aura present in any given * A class whose instances hold information about the aura present in any given
* {@link net.minecraft.world.level.chunk.LevelChunk}. To get an instance for a * {@link Chunk}. To get an instance for a chunk, use {@link
* chunk, use {@link #getAuraChunk(Level, BlockPos)}. * #getAuraChunk(IWorld, BlockPos)}.
* <p> * <p>
* It is not intended for API users to create custom implementation of this * It is not intended for API users to create custom implementation of this
* class. * class.
*/ */
public interface IAuraChunk extends INBTSerializable<CompoundTag> { public interface IAuraChunk extends INBTSerializable<CompoundNBT> {
/** /**
* The default amount of Aura that a chunk has stored * The default amount of Aura that a chunk has stored
@ -30,12 +31,12 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
* This method is used to get information about the Aura in any given chunk. * This method is used to get information about the Aura in any given chunk.
* This is a convenience method. * This is a convenience method.
* *
* @param level The level * @param world The world
* @param pos A position that the chunk contains * @param pos A position that the chunk contains
* @return The {@link IAuraChunk} instance belonging to the chunk * @return The {@link IAuraChunk} instance belonging to the chunk
*/ */
static IAuraChunk getAuraChunk(Level level, BlockPos pos) { static IAuraChunk getAuraChunk(IWorld world, BlockPos pos) {
LevelChunk chunk = (LevelChunk) level.getChunk(pos); Chunk chunk = (Chunk) world.getChunk(pos);
return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
} }
@ -44,78 +45,78 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
* spots, represented as a position and the number of Aura in them, in any * spots, represented as a position and the number of Aura in them, in any
* given area. * given area.
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param radius The radius around the center to search for spots in * @param radius The radius around the center to search for spots in
* @param consumer A consumer that gets given the position and amount of * @param consumer A consumer that gets given the position and amount of
* aura in each drain spot found * aura in each drain spot found
*/ */
static void getSpotsInArea(Level level, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) { static void getSpotsInArea(IWorld world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
NaturesAuraAPI.instance().getAuraSpotsInArea(level, pos, radius, consumer); NaturesAuraAPI.instance().getAuraSpotsInArea((World) world, pos, radius, consumer);
} }
/** /**
* Convenience method that adds up the amount of aura spots from {@link * Convenience method that adds up the amount of aura spots from {@link
* #getSpotsInArea(Level, BlockPos, int, BiConsumer)} and returns it. * #getSpotsInArea(IWorld, BlockPos, int, BiConsumer)} and returns it.
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param radius The radius around the center to search for spots in * @param radius The radius around the center to search for spots in
* @return The amount of spots found in the area * @return The amount of spots found in the area
*/ */
static int getSpotAmountInArea(Level level, BlockPos pos, int radius) { static int getSpotAmountInArea(IWorld world, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().getSpotAmountInArea(level, pos, radius); return NaturesAuraAPI.instance().getSpotAmountInArea((World) world, pos, radius);
} }
/** /**
* Convenience method that adds up all of the aura from each drain spot from * Convenience method that adds up all of the aura from each drain spot from
* {@link #getSpotsInArea(Level, BlockPos, int, BiConsumer)} and * {@link #getSpotsInArea(IWorld, BlockPos, int, BiConsumer)} and
* conveniently returns it. For a better visual display with a more gradual * conveniently returns it. For a better visual display with a more gradual
* increase, use {@link #triangulateAuraInArea(Level, BlockPos, int)}. * increase, use {@link #triangulateAuraInArea(IWorld, BlockPos, int)}.
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param radius The radius around the center to search for spots in * @param radius The radius around the center to search for spots in
* @return The amount of Aura present in that area, based on the drain spots * @return The amount of Aura present in that area, based on the drain spots
* that are found * that are found
*/ */
static int getAuraInArea(Level level, BlockPos pos, int radius) { static int getAuraInArea(IWorld world, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().getAuraInArea(level, pos, radius); return NaturesAuraAPI.instance().getAuraInArea((World) world, pos, radius);
} }
/** /**
* Convenience method that combines {@link #getAuraInArea(Level, BlockPos, * Convenience method that combines {@link #getAuraInArea(IWorld, BlockPos,
* int)} and {@link #getSpotAmountInArea(Level, BlockPos, int)} to increase * int)} and {@link #getSpotAmountInArea(IWorld, BlockPos, int)} to increase
* performance. * performance.
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param radius The radius around the center to search for spots in * @param radius The radius around the center to search for spots in
* @return A pair of the amount of aura in the area as the {@link * @return A pair of the amount of aura in the area as the {@link
* Pair#getLeft()} entry, and the amount of aura spots in the area as the * Pair#getLeft()} entry, and the amount of aura spots in the area as the
* {@link Pair#getRight()} entry * {@link Pair#getRight()} entry
*/ */
static Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius) { static Pair<Integer, Integer> getAuraAndSpotAmountInArea(World world, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().getAuraAndSpotAmountInArea(level, pos, radius); return NaturesAuraAPI.instance().getAuraAndSpotAmountInArea(world, pos, radius);
} }
/** /**
* Convenience method that adds up all of the aura from each drain spot from * Convenience method that adds up all of the aura from each drain spot from
* {@link #getSpotsInArea(Level, BlockPos, int, BiConsumer)}, but multiplies * {@link #getSpotsInArea(IWorld, BlockPos, int, BiConsumer)}, but
* their amount by the percentual distance to the supplied position. This * multiplies their amount by the percentual distance to the supplied
* will cause for a lot more gradual of an increase and decrease of Aura * position. This will cause for a lot more gradual of an increase and
* when moving closer to actual spots. This should be used for visual * decrease of Aura when moving closer to actual spots. This should be used
* purposes as it is more performance intensive than {@link * for visual purposes as it is more performance intensive than {@link
* #getAuraInArea(Level, BlockPos, int)}. * #getAuraInArea(IWorld, BlockPos, int)}.
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param radius The radius around the center to search for spots in * @param radius The radius around the center to search for spots in
* @return The amount of Aura presetn in that area, based on the drain spots * @return The amount of Aura presetn in that area, based on the drain spots
* that are found and their distance to the center * that are found and their distance to the center
*/ */
static int triangulateAuraInArea(Level level, BlockPos pos, int radius) { static int triangulateAuraInArea(IWorld world, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().triangulateAuraInArea(level, pos, radius); return NaturesAuraAPI.instance().triangulateAuraInArea((World) world, pos, radius);
} }
/** /**
@ -125,15 +126,15 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
* drained spots get selected first. Note that, when there is no drain spot * drained spots get selected first. Note that, when there is no drain spot
* with an amount lower than 0, the default will always be returned. * with an amount lower than 0, the default will always be returned.
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param radius The radius around the center to search for spots in * @param radius The radius around the center to search for spots in
* @param defaultSpot A position that will be used to create a new drain * @param defaultSpot A position that will be used to create a new drain
* spot when none are found * spot when none are found
* @return The position of the lowest drain spot * @return The position of the lowest drain spot
*/ */
static BlockPos getLowestSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) { static BlockPos getLowestSpot(IWorld world, BlockPos pos, int radius, BlockPos defaultSpot) {
return NaturesAuraAPI.instance().getLowestAuraDrainSpot(level, pos, radius, defaultSpot); return NaturesAuraAPI.instance().getLowestAuraDrainSpot((World) world, pos, radius, defaultSpot);
} }
/** /**
@ -143,15 +144,15 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
* amount are drained first. Note that, when there is no drain spot with an * amount are drained first. Note that, when there is no drain spot with an
* amount greater than 0, the defautl will always be returned. * amount greater than 0, the defautl will always be returned.
* *
* @param level The level * @param world The world
* @param pos The center position * @param pos The center position
* @param radius The radius around the center to search for spots in * @param radius The radius around the center to search for spots in
* @param defaultSpot A position that will be used to create a new drain * @param defaultSpot A position that will be used to create a new drain
* spot when none are found * spot when none are found
* @return The position of the highest drain spot * @return The position of the highest drain spot
*/ */
static BlockPos getHighestSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) { static BlockPos getHighestSpot(IWorld world, BlockPos pos, int radius, BlockPos defaultSpot) {
return NaturesAuraAPI.instance().getHighestAuraDrainSpot(level, pos, radius, defaultSpot); return NaturesAuraAPI.instance().getHighestAuraDrainSpot((World) world, pos, radius, defaultSpot);
} }
/** /**

View file

@ -1,22 +1,22 @@
package de.ellpeck.naturesaura.api.aura.chunk; package de.ellpeck.naturesaura.api.aura.chunk;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.core.BlockPos; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.resources.ResourceLocation; import net.minecraft.item.ItemStack;
import net.minecraft.world.entity.player.Player; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.Level; import net.minecraft.world.World;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.chunk.Chunk;
public interface IDrainSpotEffect { public interface IDrainSpotEffect {
void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot); void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot);
boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type); boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type);
ResourceLocation getName(); ResourceLocation getName();
default ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { default ActiveType isActiveHere(PlayerEntity player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
return ActiveType.INACTIVE; return ActiveType.INACTIVE;
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.api.aura.container; package de.ellpeck.naturesaura.api.aura.container;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
public class BasicAuraContainer implements IAuraContainer { public class BasicAuraContainer implements IAuraContainer {
@ -52,11 +52,11 @@ public class BasicAuraContainer implements IAuraContainer {
return this.type == null || type.isSimilar(this.type); return this.type == null || type.isSimilar(this.type);
} }
public void writeNBT(CompoundTag compound) { public void writeNBT(CompoundNBT compound) {
compound.putInt("aura", this.aura); compound.putInt("aura", this.aura);
} }
public void readNBT(CompoundTag compound) { public void readNBT(CompoundNBT compound) {
this.aura = compound.getInt("aura"); this.aura = compound.getInt("aura");
} }
} }

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.api.aura.container;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
public class ItemAuraContainer implements IAuraContainer { public class ItemAuraContainer implements IAuraContainer {
@ -38,7 +38,7 @@ public class ItemAuraContainer implements IAuraContainer {
private void setAura(int amount) { private void setAura(int amount) {
if (!this.stack.hasTag()) { if (!this.stack.hasTag()) {
this.stack.setTag(new CompoundTag()); this.stack.setTag(new CompoundNBT());
} }
this.stack.getTag().putInt("aura", amount); this.stack.getTag().putInt("aura", amount);
} }

View file

@ -1,9 +1,10 @@
package de.ellpeck.naturesaura.api.aura.type; package de.ellpeck.naturesaura.api.aura.type;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.resources.ResourceKey; import net.minecraft.util.RegistryKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.level.Level; import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -15,12 +16,12 @@ public class BasicAuraType implements IAuraType {
private final int priority; private final int priority;
private final Set<ResourceLocation> dimensions = new HashSet<>(); private final Set<ResourceLocation> dimensions = new HashSet<>();
public BasicAuraType(ResourceLocation name, ResourceKey<Level> dimension, int color, int priority) { public BasicAuraType(ResourceLocation name, RegistryKey<World> dimension, int color, int priority) {
this.name = name; this.name = name;
this.color = color; this.color = color;
this.priority = priority; this.priority = priority;
if (dimension != null) if (dimension != null)
this.dimensions.add(dimension.location()); this.dimensions.add(dimension.func_240901_a_());
} }
public BasicAuraType register() { public BasicAuraType register() {
@ -34,8 +35,8 @@ public class BasicAuraType implements IAuraType {
} }
@Override @Override
public boolean isPresentInLevel(Level level) { public boolean isPresentInWorld(IWorld world) {
return this.dimensions.isEmpty() || this.dimensions.contains(level.dimension().location()); return this.dimensions.isEmpty() || this.dimensions.contains(((World) world).func_234923_W_().func_240901_a_());
} }
@Override @Override

View file

@ -1,22 +1,22 @@
package de.ellpeck.naturesaura.api.aura.type; package de.ellpeck.naturesaura.api.aura.type;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.level.Level; import net.minecraft.world.IWorld;
public interface IAuraType { public interface IAuraType {
static IAuraType forLevel(Level level) { static IAuraType forWorld(IWorld world) {
IAuraType highestType = NaturesAuraAPI.TYPE_OTHER; IAuraType highestType = NaturesAuraAPI.TYPE_OTHER;
for (IAuraType type : NaturesAuraAPI.AURA_TYPES.values()) for (IAuraType type : NaturesAuraAPI.AURA_TYPES.values())
if (type.isPresentInLevel(level) && type.getPriority() > highestType.getPriority()) if (type.isPresentInWorld(world) && type.getPriority() > highestType.getPriority())
highestType = type; highestType = type;
return highestType; return highestType;
} }
ResourceLocation getName(); ResourceLocation getName();
boolean isPresentInLevel(Level level); boolean isPresentInWorld(IWorld world);
int getColor(); int getColor();

View file

@ -1,25 +0,0 @@
package de.ellpeck.naturesaura.api.misc;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.items.IItemHandlerModifiable;
public interface ILevelData extends ICapabilityProvider, INBTSerializable<CompoundTag> {
static ILevelData getLevelData(Level level) {
return level.getCapability(NaturesAuraAPI.capLevelData, null).orElse(null);
}
static ILevelData getOverworldData(Level level) {
if (!level.isClientSide)
return getLevelData(level.getServer().getLevel(Level.OVERWORLD));
return getLevelData(level);
}
IItemHandlerModifiable getEnderStorage(String name);
boolean isEnderStorageLocked(String name);
}

View file

@ -0,0 +1,25 @@
package de.ellpeck.naturesaura.api.misc;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.items.IItemHandlerModifiable;
public interface IWorldData extends ICapabilityProvider, INBTSerializable<CompoundNBT> {
static IWorldData getWorldData(World world) {
return world.getCapability(NaturesAuraAPI.capWorldData, null).orElse(null);
}
static IWorldData getOverworldData(World world) {
if (!world.isRemote)
return getWorldData(world.getServer().getWorld(World.field_234918_g_));
return getWorldData(world);
}
IItemHandlerModifiable getEnderStorage(String name);
boolean isEnderStorageLocked(String name);
}

View file

@ -1,9 +1,9 @@
package de.ellpeck.naturesaura.api.misc; package de.ellpeck.naturesaura.api.misc;
import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.random.WeightedEntry; import net.minecraft.util.WeightedRandom;
public class WeightedOre extends WeightedEntry.IntrusiveBase { public class WeightedOre extends WeightedRandom.Item {
public final ResourceLocation tag; public final ResourceLocation tag;

View file

@ -1,15 +1,15 @@
package de.ellpeck.naturesaura.api.multiblock; package de.ellpeck.naturesaura.api.multiblock;
import net.minecraft.core.BlockPos; import net.minecraft.util.ResourceLocation;
import net.minecraft.resources.ResourceLocation; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.Level; import net.minecraft.world.World;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
public interface IMultiblock { public interface IMultiblock {
boolean isComplete(Level level, BlockPos center); boolean isComplete(World world, BlockPos center);
boolean forEach(BlockPos center, char c, BiFunction<BlockPos, Matcher, Boolean> function); boolean forEach(BlockPos center, char c, BiFunction<BlockPos, Matcher, Boolean> function);

View file

@ -1,11 +1,11 @@
package de.ellpeck.naturesaura.api.multiblock; package de.ellpeck.naturesaura.api.multiblock;
import net.minecraft.core.BlockPos; import net.minecraft.block.Block;
import net.minecraft.tags.Tag; import net.minecraft.block.BlockState;
import net.minecraft.world.level.Level; import net.minecraft.block.Blocks;
import net.minecraft.world.level.block.Block; import net.minecraft.tags.ITag;
import net.minecraft.world.level.block.Blocks; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.World;
public class Matcher { public class Matcher {
@ -18,11 +18,11 @@ public class Matcher {
} }
public static Matcher wildcard() { public static Matcher wildcard() {
return new Matcher(Blocks.AIR.defaultBlockState(), null); return new Matcher(Blocks.AIR.getDefaultState(), null);
} }
public static Matcher tag(Block defaultBlock, Tag.Named<?> tag) { public static Matcher tag(Block defaultBlock, ITag.INamedTag tag) {
return new Matcher(defaultBlock.defaultBlockState(), (level, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName())); return new Matcher(defaultBlock.getDefaultState(), (world, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName()));
} }
public BlockState getDefaultState() { public BlockState getDefaultState() {
@ -34,7 +34,6 @@ public class Matcher {
} }
public interface ICheck { public interface ICheck {
boolean matches(World world, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c);
boolean matches(Level level, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c);
} }
} }

View file

@ -2,14 +2,14 @@ package de.ellpeck.naturesaura.api.render;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public interface ITrinketItem { public interface ITrinketItem {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
void render(ItemStack stack, Player player, RenderType type, MatrixStack matrices, IRenderTypeBuffer buffer, int packedLight, boolean isHolding); void render(ItemStack stack, PlayerEntity player, RenderType type, MatrixStack matrices, IRenderTypeBuffer buffer, int packedLight, boolean isHolding);
enum RenderType { enum RenderType {
HEAD, BODY HEAD, BODY

View file

@ -2,15 +2,15 @@ package de.ellpeck.naturesaura.api.render;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public interface IVisualizable { public interface IVisualizable {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos); AxisAlignedBB getVisualizationBounds(World world, BlockPos pos);
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
int getVisualizationColor(Level level, BlockPos pos); int getVisualizationColor(World world, BlockPos pos);
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAncientLeaves; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAncientLeaves;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -11,11 +11,11 @@ import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor; import net.minecraft.block.material.MaterialColor;
import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -27,7 +27,7 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
public BlockAncientLeaves() { public BlockAncientLeaves() {
super(Properties.create(Material.LEAVES, MaterialColor.PINK).hardnessAndResistance(0.2F).tickRandomly().notSolid().sound(SoundType.PLANT)); super(Properties.create(Material.LEAVES, MaterialColor.PINK).hardnessAndResistance(0.2F).tickRandomly().notSolid().sound(SoundType.PLANT));
ModRegistry.add(this); ModRegistry.add(this);
ModRegistry.add(new ModTileType<>(BlockEntityAncientLeaves::new, this)); ModRegistry.add(new ModTileType<>(TileEntityAncientLeaves::new, this));
} }
@Override @Override
@ -37,19 +37,19 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
@Nullable @Nullable
@Override @Override
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) { public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new BlockEntityAncientLeaves(); return new TileEntityAncientLeaves();
} }
@Override @Override
public boolean hasBlockEntity(BlockState state) { public boolean hasTileEntity(BlockState state) {
return true; return true;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public IBlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> 0xE55B97; return (state, worldIn, pos, tintIndex) -> 0xE55B97;
} }
@Override @Override
@ -60,12 +60,12 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
super.animateTick(stateIn, levelIn, pos, rand); super.animateTick(stateIn, worldIn, pos, rand);
if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.down()).isOpaqueCube(levelIn, pos)) { if (rand.nextFloat() >= 0.95F && !worldIn.getBlockState(pos.down()).isOpaqueCube(worldIn, pos)) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) { if (tile instanceof TileEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) { if (((TileEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(), pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(),
0F, 0F, 0F, 0xCC4780, 0F, 0F, 0F, 0xCC4780,
@ -79,13 +79,13 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
super.randomTick(state, levelIn, pos, random); super.randomTick(state, worldIn, pos, random);
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) { if (tile instanceof TileEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) { if (((TileEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) {
levelIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState()); worldIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState());
} }
} }
} }

View file

@ -3,7 +3,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.gen.ModFeatures; import de.ellpeck.naturesaura.gen.ModFeatures;
import de.ellpeck.naturesaura.gen.LevelGenAncientTree; import de.ellpeck.naturesaura.gen.WorldGenAncientTree;
import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -12,9 +12,9 @@ import net.minecraft.state.StateContainer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ForgeEventFactory;
import java.util.Random; import java.util.Random;
@ -29,17 +29,17 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!level.isClientSide) { if (!world.isRemote) {
super.randomTick(state, level, pos, random); super.randomTick(state, world, pos, random);
if (level.getLight(pos.up()) >= 9 && random.nextInt(7) == 0) { if (world.getLight(pos.up()) >= 9 && random.nextInt(7) == 0) {
this.grow(level, random, pos, state); this.grow(world, random, pos, state);
} }
} }
} }
@ -55,21 +55,21 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
} }
@Override @Override
public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) { public boolean canGrow(IBlockReader worldIn, BlockPos pos, BlockState state, boolean isClient) {
return true; return true;
} }
@Override @Override
public boolean canUseBonemeal(Level level, Random rand, BlockPos pos, BlockState state) { public boolean canUseBonemeal(World world, Random rand, BlockPos pos, BlockState state) {
return level.rand.nextFloat() < 0.45F; return world.rand.nextFloat() < 0.45F;
} }
@Override @Override
public void grow(ServerLevel level, Random rand, BlockPos pos, BlockState state) { public void grow(ServerWorld world, Random rand, BlockPos pos, BlockState state) {
if (state.get(SaplingBlock.STAGE) == 0) { if (state.get(SaplingBlock.STAGE) == 0) {
level.setBlockState(pos, state.func_235896_a_(SaplingBlock.STAGE), 4); world.setBlockState(pos, state.func_235896_a_(SaplingBlock.STAGE), 4);
} else if (ForgeEventFactory.saplingGrowTree(level, rand, pos)) { } else if (ForgeEventFactory.saplingGrowTree(world, rand, pos)) {
ModFeatures.ANCIENT_TREE.func_241855_a(level, level.getChunkProvider().getChunkGenerator(), rand, pos, LevelGenAncientTree.CONFIG); ModFeatures.ANCIENT_TREE.func_241855_a(world, world.getChunkProvider().getChunkGenerator(), rand, pos, WorldGenAncientTree.CONFIG);
} }
} }

View file

@ -1,18 +1,18 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalContainer; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAnimalContainer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -21,7 +21,7 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
private static final VoxelShape SHAPE = makeCuboidShape(5, 0, 5, 11, 13, 11); private static final VoxelShape SHAPE = makeCuboidShape(5, 0, 5, 11, 13, 11);
public BlockAnimalContainer() { public BlockAnimalContainer() {
super("animal_container", BlockEntityAnimalContainer::new, Properties.from(Blocks.STONE)); super("animal_container", TileEntityAnimalContainer::new, Properties.from(Blocks.STONE));
} }
@Override @Override
@ -30,16 +30,16 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof BlockEntityAnimalContainer) { if (tile instanceof TileEntityAnimalContainer) {
int radius = ((BlockEntityAnimalContainer) tile).getRadius(); int radius = ((TileEntityAnimalContainer) tile).getRadius();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AxisAlignedBB(pos).grow(radius);
} }
@ -48,7 +48,7 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x42ddf5; return 0x42ddf5;
} }

View file

@ -3,7 +3,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAnimalGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
@ -14,11 +14,11 @@ import net.minecraft.entity.INPC;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.IMob; import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -30,7 +30,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockAnimalGenerator() { public BlockAnimalGenerator() {
super("animal_generator", BlockEntityAnimalGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("animal_generator", TileEntityAnimalGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@ -38,9 +38,9 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@SubscribeEvent @SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) { public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
LivingEntity entity = event.getEntityLiving(); LivingEntity entity = event.getEntityLiving();
if (entity.level.isClientSide || entity.level.getGameTime() % 40 != 0 || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC) if (entity.world.isRemote || entity.world.getGameTime() % 40 != 0 || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC)
return; return;
CompoundTag data = entity.getPersistentData(); CompoundNBT data = entity.getPersistentData();
int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive"); int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive");
data.putInt(NaturesAura.MOD_ID + ":time_alive", timeAlive + 40); data.putInt(NaturesAura.MOD_ID + ":time_alive", timeAlive + 40);
} }
@ -48,15 +48,15 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@SubscribeEvent @SubscribeEvent
public void onEntityDeath(LivingDeathEvent event) { public void onEntityDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving(); LivingEntity entity = event.getEntityLiving();
if (entity.level.isClientSide || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC) if (entity.world.isRemote || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC)
return; return;
BlockPos pos = entity.getPosition(); BlockPos pos = entity.getPosition();
Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> { Helper.getTileEntitiesInArea(entity.world, pos, 5, tile -> {
if (!(tile instanceof BlockEntityAnimalGenerator)) if (!(tile instanceof TileEntityAnimalGenerator))
return false; return false;
BlockEntityAnimalGenerator gen = (BlockEntityAnimalGenerator) tile; TileEntityAnimalGenerator gen = (TileEntityAnimalGenerator) tile;
CompoundTag data = entity.getPersistentData(); CompoundNBT data = entity.getPersistentData();
data.putBoolean(NaturesAura.MOD_ID + ":no_drops", true); data.putBoolean(NaturesAura.MOD_ID + ":no_drops", true);
if (gen.isBusy()) if (gen.isBusy())
@ -67,14 +67,14 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
float amountMod = child ? 0.667F : 1; float amountMod = child ? 0.667F : 1;
int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive"); int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive");
int time = Math.min(Mth.floor((timeAlive - 15000) / 500F * timeMod), 200); int time = Math.min(MathHelper.floor((timeAlive - 15000) / 500F * timeMod), 200);
int amount = Math.min(Mth.floor((timeAlive - 8000) / 2F * amountMod), 25000); int amount = Math.min(MathHelper.floor((timeAlive - 8000) / 2F * amountMod), 25000);
if (time <= 0 || amount <= 0) if (time <= 0 || amount <= 0)
return false; return false;
gen.setGenerationValues(time, amount); gen.setGenerationValues(time, amount);
BlockPos genPos = gen.getPos(); BlockPos genPos = gen.getPos();
PacketHandler.sendToAllAround(entity.level, pos, 32, new PacketParticles( PacketHandler.sendToAllAround(entity.world, pos, 32, new PacketParticles(
(float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME, (float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME,
child ? 1 : 0, child ? 1 : 0,
(int) (entity.getEyeHeight() * 10F), (int) (entity.getEyeHeight() * 10F),
@ -100,13 +100,13 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(5); return new AxisAlignedBB(pos).grow(5);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x11377a; return 0x11377a;
} }

View file

@ -1,11 +1,11 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalSpawner; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAnimalSpawner;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
public class BlockAnimalSpawner extends BlockContainerImpl { public class BlockAnimalSpawner extends BlockContainerImpl {
public BlockAnimalSpawner() { public BlockAnimalSpawner() {
super("animal_spawner", BlockEntityAnimalSpawner::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("animal_spawner", TileEntityAnimalSpawner::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
} }
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAuraBloom;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.reg.*;
@ -11,15 +11,15 @@ import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.ILevelReader; import net.minecraft.world.IWorldReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
@ -39,25 +39,25 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
} }
@Override @Override
public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) { public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
BlockPos down = pos.down(); BlockPos down = pos.down();
return this.isValidGround(levelIn.getBlockState(down), levelIn, down); return this.isValidGround(worldIn.getBlockState(down), worldIn, down);
} }
@Override @Override
protected boolean isValidGround(BlockState state, IBlockReader levelIn, BlockPos pos) { protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
return Arrays.stream(this.allowedGround).anyMatch(state::isIn); return Arrays.stream(this.allowedGround).anyMatch(state::isIn);
} }
@Override @Override
public void onEntityCollision(BlockState state, Level levelIn, BlockPos pos, Entity entityIn) { public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
if (this == ModBlocks.AURA_CACTUS) if (this == ModBlocks.AURA_CACTUS)
entityIn.attackEntityFrom(DamageSource.CACTUS, 1); entityIn.attackEntityFrom(DamageSource.CACTUS, 1);
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
Vector3d vec3d = state.getOffset(levelIn, pos); Vector3d vec3d = state.getOffset(worldIn, pos);
return SHAPE.withOffset(vec3d.x, vec3d.y, vec3d.z); return SHAPE.withOffset(vec3d.x, vec3d.y, vec3d.z);
} }
@ -83,12 +83,12 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
@Nullable @Nullable
@Override @Override
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) { public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new BlockEntityAuraBloom(); return new TileEntityAuraBloom();
} }
@Override @Override
public boolean hasBlockEntity(BlockState state) { public boolean hasTileEntity(BlockState state) {
return true; return true;
} }
} }

View file

@ -1,17 +1,17 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraDetector; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAuraDetector;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
public class BlockAuraDetector extends BlockContainerImpl { public class BlockAuraDetector extends BlockContainerImpl {
public BlockAuraDetector() { public BlockAuraDetector() {
super("aura_detector", BlockEntityAuraDetector::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("aura_detector", TileEntityAuraDetector::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
} }
@Override @Override
@ -20,10 +20,10 @@ public class BlockAuraDetector extends BlockContainerImpl {
} }
@Override @Override
public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) { public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityAuraDetector) if (tile instanceof TileEntityAuraDetector)
return ((BlockEntityAuraDetector) tile).redstonePower; return ((TileEntityAuraDetector) tile).redstonePower;
else else
return 0; return 0;
} }

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAuraTimer;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderAuraTimer; import de.ellpeck.naturesaura.blocks.tiles.render.RenderAuraTimer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
@ -12,13 +12,13 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.InteractionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
@ -26,9 +26,9 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -36,12 +36,12 @@ import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<BlockEntityAuraTimer>, ICustomRenderType { public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<TileEntityAuraTimer>, ICustomRenderType {
private static final VoxelShape SHAPE = makeCuboidShape(1, 0, 1, 15, 15, 15); private static final VoxelShape SHAPE = makeCuboidShape(1, 0, 1, 15, 15, 15);
public BlockAuraTimer() { public BlockAuraTimer() {
super("aura_timer", BlockEntityAuraTimer::new, Properties.from(Blocks.SMOOTH_STONE)); super("aura_timer", TileEntityAuraTimer::new, Properties.from(Blocks.SMOOTH_STONE));
this.setDefaultState(this.getDefaultState().with(BlockStateProperties.POWERED, false)); this.setDefaultState(this.getDefaultState().with(BlockStateProperties.POWERED, false));
} }
@ -51,13 +51,13 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public Tuple<BlockEntityType<BlockEntityAuraTimer>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityAuraTimer>>>> getTESR() { public Tuple<TileEntityType<TileEntityAuraTimer>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityAuraTimer>>>> getTESR() {
return new Tuple<>(ModTileEntities.AURA_TIMER, () -> RenderAuraTimer::new); return new Tuple<>(ModTileEntities.AURA_TIMER, () -> RenderAuraTimer::new);
} }
@ -72,7 +72,7 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@ -82,15 +82,15 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
} }
@Override @Override
public int getWeakPower(BlockState state, IBlockReader level, BlockPos pos, Direction side) { public int getWeakPower(BlockState state, IBlockReader world, BlockPos pos, Direction side) {
return state.get(BlockStateProperties.POWERED) ? 15 : 0; return state.get(BlockStateProperties.POWERED) ? 15 : 0;
} }
@Override @Override
public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
super.tick(state, levelIn, pos, random); super.tick(state, worldIn, pos, random);
if (state.get(BlockStateProperties.POWERED)) if (state.get(BlockStateProperties.POWERED))
levelIn.setBlockState(pos, state.with(BlockStateProperties.POWERED, false)); worldIn.setBlockState(pos, state.with(BlockStateProperties.POWERED, false));
} }
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAutoCrafter; import de.ellpeck.naturesaura.blocks.tiles.TileEntityAutoCrafter;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -16,7 +16,7 @@ public class BlockAutoCrafter extends BlockContainerImpl implements ICustomBlock
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public BlockAutoCrafter() { public BlockAutoCrafter() {
super("auto_crafter", BlockEntityAutoCrafter::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD)); super("auto_crafter", TileEntityAutoCrafter::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD));
} }
@Override @Override

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityBlastFurnaceBooster; import de.ellpeck.naturesaura.blocks.tiles.TileEntityBlastFurnaceBooster;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -13,15 +13,15 @@ import net.minecraft.state.StateContainer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICustomBlockState { public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICustomBlockState {
public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING; public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
private static final VoxelShape SHAPE = Shapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F); private static final VoxelShape SHAPE = VoxelShapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F);
public BlockBlastFurnaceBooster() { public BlockBlastFurnaceBooster() {
super("blast_furnace_booster", BlockEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE).setLightLevel(s -> 0)); super("blast_furnace_booster", TileEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE).setLightLevel(s -> 0));
} }
@Override @Override
@ -30,7 +30,7 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }

View file

@ -7,8 +7,8 @@ import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
public class BlockCatalyst extends BlockImpl implements ICustomBlockState { public class BlockCatalyst extends BlockImpl implements ICustomBlockState {
public static final BooleanProperty NETHER = BlockNatureAltar.NETHER; public static final BooleanProperty NETHER = BlockNatureAltar.NETHER;
@ -20,7 +20,7 @@ public class BlockCatalyst extends BlockImpl implements ICustomBlockState {
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
boolean nether = IAuraType.forLevel(context.getLevel()).isSimilar(NaturesAuraAPI.TYPE_NETHER); boolean nether = IAuraType.forWorld(context.getWorld()).isSimilar(NaturesAuraAPI.TYPE_NETHER);
return super.getStateForPlacement(context).with(NETHER, nether); return super.getStateForPlacement(context).with(NETHER, nether);
} }

View file

@ -1,13 +1,13 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChorusGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityChorusGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState { public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState {
public BlockChorusGenerator() { public BlockChorusGenerator() {
super("chorus_generator", BlockEntityChorusGenerator::new, Properties.from(Blocks.END_STONE)); super("chorus_generator", TileEntityChorusGenerator::new, Properties.from(Blocks.END_STONE));
} }
@Override @Override

View file

@ -4,7 +4,7 @@ import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChunkLoader; import de.ellpeck.naturesaura.blocks.tiles.TileEntityChunkLoader;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -12,15 +12,15 @@ import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -33,7 +33,7 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
private static final VoxelShape SHAPE = makeCuboidShape(4, 4, 4, 12, 12, 12); private static final VoxelShape SHAPE = makeCuboidShape(4, 4, 4, 12, 12, 12);
public BlockChunkLoader() { public BlockChunkLoader() {
super("chunk_loader", BlockEntityChunkLoader::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("chunk_loader", TileEntityChunkLoader::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
} }
@Override @Override
@ -43,17 +43,17 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof BlockEntityChunkLoader) { if (tile instanceof TileEntityChunkLoader) {
int range = ((BlockEntityChunkLoader) tile).range(); int range = ((TileEntityChunkLoader) tile).range();
if (range > 0) { if (range > 0) {
return new AxisAlignedBB( return new AxisAlignedBB(
(pos.getX() - range) >> 4 << 4, (pos.getX() - range) >> 4 << 4,
0, 0,
(pos.getZ() - range) >> 4 << 4, (pos.getZ() - range) >> 4 << 4,
((pos.getX() + range) >> 4 << 4) + 16, ((pos.getX() + range) >> 4 << 4) + 16,
level.getHeight(), world.getHeight(),
((pos.getZ() + range) >> 4 << 4) + 16); ((pos.getZ() + range) >> 4 << 4) + 16);
} }
} }
@ -62,28 +62,28 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if (!ModConfig.instance.chunkLoader.get()) if (!ModConfig.instance.chunkLoader.get())
return; return;
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityChunkLoader) { if (tile instanceof TileEntityChunkLoader) {
int range = ((BlockEntityChunkLoader) tile).range(); int range = ((TileEntityChunkLoader) tile).range();
for (int i = Mth.ceil(range / 8F); i > 0; i--) { for (int i = MathHelper.ceil(range / 8F); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + levelIn.rand.nextFloat(), pos.getY() + levelIn.rand.nextFloat(), pos.getZ() + levelIn.rand.nextFloat(), pos.getX() + worldIn.rand.nextFloat(), pos.getY() + worldIn.rand.nextFloat(), pos.getZ() + worldIn.rand.nextFloat(),
0, 0, 0, 0xa12dff, 1F + levelIn.rand.nextFloat(), 100, 0, false, true); 0, 0, 0, 0xa12dff, 1F + worldIn.rand.nextFloat(), 100, 0, false, true);
} }
} }
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0xc159f9; return 0xc159f9;
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@ -93,8 +93,8 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
} }
@Override @Override
public void addInformation(ItemStack stack, @Nullable IBlockReader levelIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
super.addInformation(stack, levelIn, tooltip, flagIn); super.addInformation(stack, worldIn, tooltip, flagIn);
} }
@Override @Override

View file

@ -1,42 +1,40 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import de.ellpeck.naturesaura.reg.ModTileType; import de.ellpeck.naturesaura.reg.ModTileType;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.ILevel;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.loot.LootContext; import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootParameters; import net.minecraft.loot.LootParameters;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tags.FluidTags; import net.minecraft.tags.FluidTags;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.IBlockReader;
import net.minecraft.world.level.block.Block; import net.minecraft.world.IWorld;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockContainerImpl extends BaseEntityBlock implements IModItem { public class BlockContainerImpl extends ContainerBlock implements IModItem {
private final String baseName; private final String baseName;
private final ModTileType<? extends BlockEntity> tileType; private final ModTileType<? extends TileEntity> tileType;
public BlockContainerImpl(String baseName, Supplier<BlockEntity> tileSupplier, Block.Properties properties) { public BlockContainerImpl(String baseName, Supplier<TileEntity> tileSupplier, Block.Properties properties) {
super(properties); super(properties);
this.baseName = baseName; this.baseName = baseName;
@ -65,17 +63,17 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
} }
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, ILevel levelIn, BlockPos currentPos, BlockPos facingPos) { public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
if (this.hasWaterlogging() && stateIn.get(BlockStateProperties.WATERLOGGED)) if (this.hasWaterlogging() && stateIn.get(BlockStateProperties.WATERLOGGED))
levelIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(levelIn)); worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
return super.updatePostPlacement(stateIn, facing, facingState, levelIn, currentPos, facingPos); return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
} }
@Override @Override
@Nullable @Nullable
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
if (this.hasWaterlogging()) { if (this.hasWaterlogging()) {
FluidState state = context.getLevel().getFluidState(context.getPos()); FluidState state = context.getWorld().getFluidState(context.getPos());
return this.getDefaultState().with(BlockStateProperties.WATERLOGGED, state.isTagged(FluidTags.WATER) && state.getLevel() == 8); return this.getDefaultState().with(BlockStateProperties.WATERLOGGED, state.isTagged(FluidTags.WATER) && state.getLevel() == 8);
} }
return super.getStateForPlacement(context); return super.getStateForPlacement(context);
@ -83,7 +81,7 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
@Nullable @Nullable
@Override @Override
public BlockEntity createNewBlockEntity(IBlockReader levelIn) { public TileEntity createNewTileEntity(IBlockReader worldIn) {
return this.tileType.type.create(); return this.tileType.type.create();
} }
@ -98,20 +96,20 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
} }
@Override @Override
public void onPlayerDestroy(ILevel levelIn, BlockPos pos, BlockState state) { public void onPlayerDestroy(IWorld worldIn, BlockPos pos, BlockState state) {
super.onPlayerDestroy(levelIn, pos, state); super.onPlayerDestroy(worldIn, pos, state);
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
List<ItemStack> drops = super.getDrops(state, builder); List<ItemStack> drops = super.getDrops(state, builder);
BlockEntity tile = builder.get(LootParameters.BLOCK_ENTITY); TileEntity tile = builder.get(LootParameters.BLOCK_ENTITY);
if (tile instanceof BlockEntityImpl) { if (tile instanceof TileEntityImpl) {
for (ItemStack stack : drops) { for (ItemStack stack : drops) {
if (stack.getItem() != this.asItem()) if (stack.getItem() != this.asItem())
continue; continue;
((BlockEntityImpl) tile).modifyDrop(stack); ((TileEntityImpl) tile).modifyDrop(stack);
break; break;
} }
} }
@ -119,57 +117,57 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
} }
@Override @Override
public void onReplaced(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) { public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) { if (state.getBlock() != newState.getBlock()) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityImpl) if (tile instanceof TileEntityImpl)
((BlockEntityImpl) tile).dropInventory(); ((TileEntityImpl) tile).dropInventory();
} }
super.onReplaced(state, levelIn, pos, newState, isMoving); super.onReplaced(state, worldIn, pos, newState, isMoving);
} }
@Override @Override
public void harvestBlock(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) { public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) {
super.harvestBlock(levelIn, player, pos, state, te, stack); super.harvestBlock(worldIn, player, pos, state, te, stack);
levelIn.setBlockState(pos, Blocks.AIR.getDefaultState()); worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
} }
@Override @Override
public void onBlockPlacedBy(Level levelIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityImpl) if (tile instanceof TileEntityImpl)
((BlockEntityImpl) tile).loadDataOnPlace(stack); ((TileEntityImpl) tile).loadDataOnPlace(stack);
} }
@Override @Override
public void onBlockAdded(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) { public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
this.updateRedstoneState(levelIn, pos); this.updateRedstoneState(worldIn, pos);
} }
@Override @Override
public void neighborChanged(BlockState state, Level levelIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
this.updateRedstoneState(levelIn, pos); this.updateRedstoneState(worldIn, pos);
} }
private void updateRedstoneState(Level level, BlockPos pos) { private void updateRedstoneState(World world, BlockPos pos) {
if (!level.isClientSide) { if (!world.isRemote) {
BlockEntity tile = level.getBlockEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof BlockEntityImpl) { if (tile instanceof TileEntityImpl) {
BlockEntityImpl impl = (BlockEntityImpl) tile; TileEntityImpl impl = (TileEntityImpl) tile;
int newPower = level.getRedstonePowerFromNeighbors(pos); int newPower = world.getRedstonePowerFromNeighbors(pos);
if (impl.redstonePower != newPower) if (impl.redstonePower != newPower)
level.getPendingBlockTicks().scheduleTick(pos, this, 4); world.getPendingBlockTicks().scheduleTick(pos, this, 4);
} }
} }
} }
@Override @Override
public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityImpl) { if (tile instanceof TileEntityImpl) {
BlockEntityImpl impl = (BlockEntityImpl) tile; TileEntityImpl impl = (TileEntityImpl) tile;
int newPower = levelIn.getRedstonePowerFromNeighbors(pos); int newPower = worldIn.getRedstonePowerFromNeighbors(pos);
if (impl.redstonePower != newPower) if (impl.redstonePower != newPower)
impl.onRedstonePowerChange(newPower); impl.onRedstonePowerChange(newPower);
} }

View file

@ -9,8 +9,8 @@ import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import java.util.Random; import java.util.Random;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -22,9 +22,9 @@ public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState,
} }
@Override @Override
public void tick(BlockState state, ServerLevel level, BlockPos pos, Random random) { public void tick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!level.isClientSide) { if (!world.isRemote) {
level.setBlockState(pos, Blocks.AIR.getDefaultState()); world.setBlockState(pos, Blocks.AIR.getDefaultState());
} }
} }
@ -34,7 +34,7 @@ public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState,
} }
@Override @Override
public int getOpacity(BlockState state, IBlockReader levelIn, BlockPos pos) { public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
return 1; return 1;
} }

View file

@ -15,9 +15,9 @@ import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.state.EnumProperty; import net.minecraft.state.EnumProperty;
import net.minecraft.state.Property; import net.minecraft.state.Property;
@ -28,10 +28,10 @@ import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.gen.Heightmap; import net.minecraft.world.gen.Heightmap;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.ITeleporter; import net.minecraftforge.common.util.ITeleporter;
import java.util.function.Function; import java.util.function.Function;
@ -42,10 +42,10 @@ public class BlockDimensionRail extends AbstractRailBlock implements IModItem, I
public static final EnumProperty<RailShape> SHAPE = BlockStateProperties.RAIL_SHAPE; public static final EnumProperty<RailShape> SHAPE = BlockStateProperties.RAIL_SHAPE;
private final String name; private final String name;
private final RegistryKey<Level> goalDim; private final RegistryKey<World> goalDim;
private final RegistryKey<Level>[] canUseDims; private final RegistryKey<World>[] canUseDims;
public BlockDimensionRail(String name, RegistryKey<Level> goalDim, RegistryKey<Level>... canUseDims) { public BlockDimensionRail(String name, RegistryKey<World> goalDim, RegistryKey<World>... canUseDims) {
super(false, Properties.from(Blocks.RAIL)); super(false, Properties.from(Blocks.RAIL));
this.name = name; this.name = name;
this.goalDim = goalDim; this.goalDim = goalDim;
@ -54,77 +54,77 @@ public class BlockDimensionRail extends AbstractRailBlock implements IModItem, I
ModRegistry.add(this); ModRegistry.add(this);
} }
private boolean canUseHere(RegistryKey<Level> dimension) { private boolean canUseHere(RegistryKey<World> dimension) {
for (RegistryKey<Level> dim : this.canUseDims) for (RegistryKey<World> dim : this.canUseDims)
if (dim == dimension) if (dim == dimension)
return true; return true;
return false; return false;
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand hand, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
ItemStack stack = player.getHeldItem(hand); ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() == ModItems.RANGE_VISUALIZER) { if (stack.getItem() == ModItems.RANGE_VISUALIZER) {
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
BlockPos goalPos = this.getGoalCoords(levelIn, pos); BlockPos goalPos = this.getGoalCoords(worldIn, pos);
CompoundTag data = new CompoundTag(); CompoundNBT data = new CompoundNBT();
data.putString("dim", this.goalDim.func_240901_a_().toString()); data.putString("dim", this.goalDim.func_240901_a_().toString());
data.putLong("pos", goalPos.toLong()); data.putLong("pos", goalPos.toLong());
PacketHandler.sendTo(player, new PacketClient(0, data)); PacketHandler.sendTo(player, new PacketClient(0, data));
} }
return InteractionResult.SUCCESS; return ActionResultType.SUCCESS;
} }
return InteractionResult.FAIL; return ActionResultType.FAIL;
} }
@Override @Override
public void onMinecartPass(BlockState state, Level level, BlockPos pos, AbstractMinecartEntity cart) { public void onMinecartPass(BlockState state, World world, BlockPos pos, AbstractMinecartEntity cart) {
if (level.isClientSide) if (world.isRemote)
return; return;
if (cart.isBeingRidden()) if (cart.isBeingRidden())
return; return;
if (!this.canUseHere(level.func_234923_W_())) if (!this.canUseHere(world.func_234923_W_()))
return; return;
AxisAlignedBB box = cart.getBoundingBox(); AxisAlignedBB box = cart.getBoundingBox();
PacketHandler.sendToAllAround(level, pos, 32, new PacketParticles((float) box.minX, (float) box.minY, (float) box.minZ, PacketParticles.Type.DIMENSION_RAIL, (int) ((box.maxX - box.minX) * 100F), (int) ((box.maxY - box.minY) * 100F), (int) ((box.maxZ - box.minZ) * 100F))); PacketHandler.sendToAllAround(world, pos, 32, new PacketParticles((float) box.minX, (float) box.minY, (float) box.minZ, PacketParticles.Type.DIMENSION_RAIL, (int) ((box.maxX - box.minX) * 100F), (int) ((box.maxY - box.minY) * 100F), (int) ((box.maxZ - box.minZ) * 100F)));
level.playSound(null, pos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 1F); world.playSound(null, pos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 1F);
BlockPos goalCoords = this.getGoalCoords(level, pos); BlockPos goalCoords = this.getGoalCoords(world, pos);
cart.changeDimension(level.getServer().getLevel(this.goalDim), new ITeleporter() { cart.changeDimension(world.getServer().getWorld(this.goalDim), new ITeleporter() {
@Override @Override
public Entity placeEntity(Entity entity, ServerLevel currentLevel, ServerLevel destLevel, float yaw, Function<Boolean, Entity> repositionEntity) { public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
// repositionEntity always causes a NPE because why wouldn't it, so this is a fixed copy // repositionEntity always causes a NPE because why wouldn't it, so this is a fixed copy
entity.level.getProfiler().endStartSection("reloading"); entity.world.getProfiler().endStartSection("reloading");
Entity result = entity.getType().create(destLevel); Entity result = entity.getType().create(destWorld);
if (result != null) { if (result != null) {
result.copyDataFromOld(entity); result.copyDataFromOld(entity);
destLevel.addFromAnotherDimension(result); destWorld.addFromAnotherDimension(result);
result.moveToBlockPosAndAngles(goalCoords, yaw, result.rotationPitch); result.moveToBlockPosAndAngles(goalCoords, yaw, result.rotationPitch);
} }
return result; return result;
} }
}); });
BlockPos spot = IAuraChunk.getHighestSpot(level, pos, 35, pos); BlockPos spot = IAuraChunk.getHighestSpot(world, pos, 35, pos);
IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 50000); IAuraChunk.getAuraChunk(world, spot).drainAura(spot, 50000);
} }
private BlockPos getGoalCoords(Level level, BlockPos pos) { private BlockPos getGoalCoords(World world, BlockPos pos) {
MinecraftServer server = level.getServer(); MinecraftServer server = world.getServer();
if (this == ModBlocks.DIMENSION_RAIL_NETHER) { if (this == ModBlocks.DIMENSION_RAIL_NETHER) {
// travel to the nether from the overworld // travel to the nether from the overworld
return new BlockPos(pos.getX() / 8, pos.getY() / 2, pos.getZ() / 8); return new BlockPos(pos.getX() / 8, pos.getY() / 2, pos.getZ() / 8);
} else if (this == ModBlocks.DIMENSION_RAIL_END) { } else if (this == ModBlocks.DIMENSION_RAIL_END) {
// travel to the end from the overworld // travel to the end from the overworld
return ServerLevel.field_241108_a_.up(8); return ServerWorld.field_241108_a_.up(8);
} else { } else {
if (level.func_234923_W_() == Level.field_234919_h_) { if (world.func_234923_W_() == World.field_234919_h_) {
// travel to the overworld from the nether // travel to the overworld from the nether
return new BlockPos(pos.getX() * 8, pos.getY() * 2, pos.getZ() * 8); return new BlockPos(pos.getX() * 8, pos.getY() * 2, pos.getZ() * 8);
} else { } else {
// travel to the overworld from the end // travel to the overworld from the end
ServerLevel overworld = server.getLevel(this.goalDim); ServerWorld overworld = server.getWorld(this.goalDim);
BlockPos spawn = overworld.func_241135_u_(); BlockPos spawn = overworld.func_241135_u_();
BlockPos ret = new BlockPos(spawn.getX(), 0, spawn.getZ()); BlockPos ret = new BlockPos(spawn.getX(), 0, spawn.getZ());
return ret.up(overworld.getHeight(Heightmap.Type.WORLD_SURFACE, spawn.getX(), spawn.getZ())); return ret.up(overworld.getHeight(Heightmap.Type.WORLD_SURFACE, spawn.getX(), spawn.getZ()));
@ -138,12 +138,12 @@ public class BlockDimensionRail extends AbstractRailBlock implements IModItem, I
} }
@Override @Override
public boolean isFlexibleRail(BlockState state, IBlockReader level, BlockPos pos) { public boolean isFlexibleRail(BlockState state, IBlockReader world, BlockPos pos) {
return false; return false;
} }
@Override @Override
public boolean canMakeSlopes(BlockState state, IBlockReader level, BlockPos pos) { public boolean canMakeSlopes(BlockState state, IBlockReader world, BlockPos pos) {
return false; return false;
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEndFlower; import de.ellpeck.naturesaura.blocks.tiles.TileEntityEndFlower;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.reg.*;
@ -9,21 +9,21 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.boss.dragon.EnderDragonEntity; import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootContext; import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootParameters; import net.minecraft.loot.LootParameters;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.ILevelReader; import net.minecraft.world.IWorldReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.gen.Heightmap; import net.minecraft.world.gen.Heightmap;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -40,44 +40,44 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
super(Properties.create(Material.PLANTS).doesNotBlockMovement().hardnessAndResistance(0.5F).sound(SoundType.PLANT)); super(Properties.create(Material.PLANTS).doesNotBlockMovement().hardnessAndResistance(0.5F).sound(SoundType.PLANT));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
ModRegistry.add(this); ModRegistry.add(this);
ModRegistry.add(new ModTileType<>(BlockEntityEndFlower::new, this)); ModRegistry.add(new ModTileType<>(TileEntityEndFlower::new, this));
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
Vector3d vec3d = state.getOffset(levelIn, pos); Vector3d vec3d = state.getOffset(worldIn, pos);
return SHAPE.withOffset(vec3d.x, vec3d.y, vec3d.z); return SHAPE.withOffset(vec3d.x, vec3d.y, vec3d.z);
} }
@SubscribeEvent @SubscribeEvent
public void onDragonTick(LivingUpdateEvent event) { public void onDragonTick(LivingUpdateEvent event) {
LivingEntity living = event.getEntityLiving(); LivingEntity living = event.getEntityLiving();
if (living.level.isClientSide || !(living instanceof EnderDragonEntity)) if (living.world.isRemote || !(living instanceof EnderDragonEntity))
return; return;
EnderDragonEntity dragon = (EnderDragonEntity) living; EnderDragonEntity dragon = (EnderDragonEntity) living;
if (dragon.deathTicks < 150 || dragon.deathTicks % 10 != 0) if (dragon.deathTicks < 150 || dragon.deathTicks % 10 != 0)
return; return;
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
int x = dragon.level.rand.nextInt(256) - 128; int x = dragon.world.rand.nextInt(256) - 128;
int z = dragon.level.rand.nextInt(256) - 128; int z = dragon.world.rand.nextInt(256) - 128;
BlockPos pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z); BlockPos pos = new BlockPos(x, dragon.world.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z);
if (!dragon.level.isBlockLoaded(pos)) if (!dragon.world.isBlockLoaded(pos))
continue; continue;
if (dragon.level.getBlockState(pos.down()).getBlock() != Blocks.END_STONE) if (dragon.world.getBlockState(pos.down()).getBlock() != Blocks.END_STONE)
continue; continue;
dragon.level.setBlockState(pos, this.getDefaultState()); dragon.world.setBlockState(pos, this.getDefaultState());
} }
} }
@Override @Override
protected boolean isValidGround(BlockState state, IBlockReader levelIn, BlockPos pos) { protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
return state.getBlock() == Blocks.END_STONE; return state.getBlock() == Blocks.END_STONE;
} }
@Override @Override
public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) { public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
return levelIn.getBlockState(pos.down()).getBlock() == Blocks.END_STONE; return worldIn.getBlockState(pos.down()).getBlock() == Blocks.END_STONE;
} }
@Override @Override
@ -87,30 +87,30 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
@Nullable @Nullable
@Override @Override
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) { public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new BlockEntityEndFlower(); return new TileEntityEndFlower();
} }
@Override @Override
public boolean hasBlockEntity(BlockState state) { public boolean hasTileEntity(BlockState state) {
return true; return true;
} }
@Override @Override
public boolean removedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) { public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, FluidState fluid) {
return willHarvest || super.removedByPlayer(state, level, pos, player, willHarvest, fluid); return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
} }
@Override @Override
public void harvestBlock(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) { public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) {
super.harvestBlock(levelIn, player, pos, state, te, stack); super.harvestBlock(worldIn, player, pos, state, te, stack);
levelIn.setBlockState(pos, Blocks.AIR.getDefaultState()); worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
BlockEntity tile = builder.get(LootParameters.BLOCK_ENTITY); TileEntity tile = builder.get(LootParameters.BLOCK_ENTITY);
if (tile instanceof BlockEntityEndFlower && ((BlockEntityEndFlower) tile).isDrainMode) if (tile instanceof TileEntityEndFlower && ((TileEntityEndFlower) tile).isDrainMode)
return NonNullList.create(); return NonNullList.create();
return super.getDrops(state, builder); return super.getDrops(state, builder);
} }

View file

@ -1,9 +1,9 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate; import de.ellpeck.naturesaura.blocks.tiles.TileEntityEnderCrate;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderEnderCrate; import de.ellpeck.naturesaura.blocks.tiles.render.RenderEnderCrate;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
@ -13,19 +13,19 @@ import net.minecraft.block.AnvilBlock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayer; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.particles.ParticleTypes; import net.minecraft.particles.ParticleTypes;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.InteractionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -33,8 +33,8 @@ import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -50,13 +50,13 @@ import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider<BlockEntityEnderCrate>, ICustomBlockState { public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider<TileEntityEnderCrate>, ICustomBlockState {
// This is terrible but I can't see a better solution right now so oh well // This is terrible but I can't see a better solution right now so oh well
private static final ThreadLocal<WeakReference<Level>> CACHED_WORLD = new ThreadLocal<>(); private static final ThreadLocal<WeakReference<World>> CACHED_WORLD = new ThreadLocal<>();
public BlockEnderCrate() { public BlockEnderCrate() {
super("ender_crate", BlockEntityEnderCrate::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).setLightLevel(s -> 7).sound(SoundType.STONE)); super("ender_crate", TileEntityEnderCrate::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).setLightLevel(s -> 7).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@ -79,18 +79,18 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
@SubscribeEvent @SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickBlock event) { public void onRightClick(PlayerInteractEvent.RightClickBlock event) {
Level level = event.getLevel(); World world = event.getWorld();
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
BlockState state = level.getBlockState(pos); BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof AnvilBlock) { if (state.getBlock() instanceof AnvilBlock) {
CACHED_WORLD.set(new WeakReference<>(level)); CACHED_WORLD.set(new WeakReference<>(world));
} }
} }
@SubscribeEvent @SubscribeEvent
public void onAnvilUpdate(AnvilUpdateEvent event) { public void onAnvilUpdate(AnvilUpdateEvent event) {
WeakReference<Level> level = CACHED_WORLD.get(); WeakReference<World> world = CACHED_WORLD.get();
if (level == null || level.get() == null) if (world == null || world.get() == null)
return; return;
ItemStack stack = event.getLeft(); ItemStack stack = event.getLeft();
if (stack.getItem() != Item.getItemFromBlock(this) && stack.getItem() != ModItems.ENDER_ACCESS) if (stack.getItem() != Item.getItemFromBlock(this) && stack.getItem() != ModItems.ENDER_ACCESS)
@ -101,7 +101,7 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
String name = event.getName(); String name = event.getName();
if (name == null || name.isEmpty()) if (name == null || name.isEmpty())
return; return;
if (ILevelData.getOverworldData(level.get()).isEnderStorageLocked(name)) if (IWorldData.getOverworldData(world.get()).isEnderStorageLocked(name))
return; return;
ItemStack output = stack.copy(); ItemStack output = stack.copy();
output.getOrCreateTag().putString(NaturesAura.MOD_ID + ":ender_name", name); output.getOrCreateTag().putString(NaturesAura.MOD_ID + ":ender_name", name);
@ -111,29 +111,29 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityEnderCrate) { if (tile instanceof TileEntityEnderCrate) {
BlockEntityEnderCrate crate = (BlockEntityEnderCrate) tile; TileEntityEnderCrate crate = (TileEntityEnderCrate) tile;
if (crate.canOpen()) { if (crate.canOpen()) {
crate.drainAura(2500); crate.drainAura(2500);
NetworkHooks.openGui((ServerPlayer) player, crate, pos); NetworkHooks.openGui((ServerPlayerEntity) player, crate, pos);
} }
} }
} }
return InteractionResult.SUCCESS; return ActionResultType.SUCCESS;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, @Nullable IBlockReader levelIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
addEnderNameInfo(stack, tooltip); addEnderNameInfo(stack, tooltip);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
int j = rand.nextInt(2) * 2 - 1; int j = rand.nextInt(2) * 2 - 1;
int k = rand.nextInt(2) * 2 - 1; int k = rand.nextInt(2) * 2 - 1;
@ -143,12 +143,12 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
double d3 = rand.nextFloat() * (float) j; double d3 = rand.nextFloat() * (float) j;
double d4 = ((double) rand.nextFloat() - 0.5D) * 0.125D; double d4 = ((double) rand.nextFloat() - 0.5D) * 0.125D;
double d5 = rand.nextFloat() * (float) k; double d5 = rand.nextFloat() * (float) k;
levelIn.addParticle(ParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5); worldIn.addParticle(ParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
} }
} }
@Override @Override
public Tuple<BlockEntityType<BlockEntityEnderCrate>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityEnderCrate>>>> getTESR() { public Tuple<TileEntityType<TileEntityEnderCrate>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityEnderCrate>>>> getTESR() {
return new Tuple<>(ModTileEntities.ENDER_CRATE, () -> RenderEnderCrate::new); return new Tuple<>(ModTileEntities.ENDER_CRATE, () -> RenderEnderCrate::new);
} }

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFieldCreator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityFieldCreator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType; import de.ellpeck.naturesaura.reg.ICustomRenderType;
@ -10,15 +10,15 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.InteractionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -27,28 +27,28 @@ import java.util.function.Supplier;
public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType { public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType {
public BlockFieldCreator() { public BlockFieldCreator() {
super("field_creator", BlockEntityFieldCreator::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE)); super("field_creator", TileEntityFieldCreator::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE));
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityFieldCreator) { if (tile instanceof TileEntityFieldCreator) {
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
String key = NaturesAura.MOD_ID + ":field_creator_pos"; String key = NaturesAura.MOD_ID + ":field_creator_pos";
CompoundTag compound = player.getPersistentData(); CompoundNBT compound = player.getPersistentData();
if (!player.isSneaking() && compound.contains(key)) { if (!player.isSneaking() && compound.contains(key)) {
BlockPos stored = BlockPos.fromLong(compound.getLong(key)); BlockPos stored = BlockPos.fromLong(compound.getLong(key));
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) tile; TileEntityFieldCreator creator = (TileEntityFieldCreator) tile;
if (!pos.equals(stored)) { if (!pos.equals(stored)) {
if (creator.isCloseEnough(stored)) { if (creator.isCloseEnough(stored)) {
BlockEntity otherTile = levelIn.getBlockEntity(stored); TileEntity otherTile = worldIn.getTileEntity(stored);
if (otherTile instanceof BlockEntityFieldCreator) { if (otherTile instanceof TileEntityFieldCreator) {
creator.connectionOffset = stored.subtract(pos); creator.connectionOffset = stored.subtract(pos);
creator.isMain = true; creator.isMain = true;
creator.sendToClients(); creator.sendToClients();
BlockEntityFieldCreator otherCreator = (BlockEntityFieldCreator) otherTile; TileEntityFieldCreator otherCreator = (TileEntityFieldCreator) otherTile;
otherCreator.connectionOffset = pos.subtract(stored); otherCreator.connectionOffset = pos.subtract(stored);
otherCreator.isMain = false; otherCreator.isMain = false;
otherCreator.sendToClients(); otherCreator.sendToClients();
@ -66,17 +66,17 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".stored_pos"), true); player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".stored_pos"), true);
} }
} }
return InteractionResult.SUCCESS; return ActionResultType.SUCCESS;
} else } else
return InteractionResult.FAIL; return ActionResultType.FAIL;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityFieldCreator) { if (tile instanceof TileEntityFieldCreator) {
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) tile; TileEntityFieldCreator creator = (TileEntityFieldCreator) tile;
if (creator.isCharged) { if (creator.isCharged) {
BlockPos connected = creator.getConnectedPos(); BlockPos connected = creator.getConnectedPos();
if (connected != null) if (connected != null)

View file

@ -1,31 +1,31 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFireworkGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityFireworkGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockFireworkGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockFireworkGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockFireworkGenerator() { public BlockFireworkGenerator() {
super("firework_generator", BlockEntityFireworkGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("firework_generator", TileEntityFireworkGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(4); return new AxisAlignedBB(pos).grow(4);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0xa442f4; return 0xa442f4;
} }

View file

@ -1,32 +1,32 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFlowerGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityFlowerGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockFlowerGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockFlowerGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockFlowerGenerator() { public BlockFlowerGenerator() {
super("flower_generator", BlockEntityFlowerGenerator::new, Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(2F)); super("flower_generator", TileEntityFlowerGenerator::new, Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(2F));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(3, 1, 3); return new AxisAlignedBB(pos).grow(3, 1, 3);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0xffed2b; return 0xffed2b;
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFurnaceHeater; import de.ellpeck.naturesaura.blocks.tiles.TileEntityFurnaceHeater;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -11,13 +11,13 @@ import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty; import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ToolType; import net.minecraftforge.common.ToolType;
@ -38,7 +38,7 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
}; };
public BlockFurnaceHeater() { public BlockFurnaceHeater() {
super("furnace_heater", BlockEntityFurnaceHeater::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("furnace_heater", TileEntityFurnaceHeater::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
} }
@Override @Override
@ -48,9 +48,9 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityFurnaceHeater && ((BlockEntityFurnaceHeater) tile).isActive) { if (tile instanceof TileEntityFurnaceHeater && ((TileEntityFurnaceHeater) tile).isActive) {
Direction facing = stateIn.get(FACING); Direction facing = stateIn.get(FACING);
float x; float x;
@ -80,7 +80,7 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPES[state.get(FACING).getIndex()]; return SHAPES[state.get(FACING).getIndex()];
} }

View file

@ -1,29 +1,29 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover; import de.ellpeck.naturesaura.blocks.tiles.TileEntityGeneratorLimitRemover;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderGeneratorLimitRemover; import de.ellpeck.naturesaura.blocks.tiles.render.RenderGeneratorLimitRemover;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockGeneratorLimitRemover extends BlockContainerImpl implements ITESRProvider<BlockEntityGeneratorLimitRemover>, ICustomBlockState { public class BlockGeneratorLimitRemover extends BlockContainerImpl implements ITESRProvider<TileEntityGeneratorLimitRemover>, ICustomBlockState {
public BlockGeneratorLimitRemover() { public BlockGeneratorLimitRemover() {
super("generator_limit_remover", BlockEntityGeneratorLimitRemover::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("generator_limit_remover", TileEntityGeneratorLimitRemover::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
} }
@Override @Override
public Tuple<BlockEntityType<BlockEntityGeneratorLimitRemover>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityGeneratorLimitRemover>>>> getTESR() { public Tuple<TileEntityType<TileEntityGeneratorLimitRemover>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityGeneratorLimitRemover>>>> getTESR() {
return new Tuple<>(ModTileEntities.GENERATOR_LIMIT_REMOVER, () -> RenderGeneratorLimitRemover::new); return new Tuple<>(ModTileEntities.GENERATOR_LIMIT_REMOVER, () -> RenderGeneratorLimitRemover::new);
} }

View file

@ -21,11 +21,11 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.ILevel; import net.minecraft.world.IWorld;
import net.minecraft.level.ILevelReader; import net.minecraft.world.IWorldReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -71,39 +71,39 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override @Override
public IBlockColor getBlockColor() { public IBlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> 0xf4cb42; return (state, worldIn, pos, tintIndex) -> 0xf4cb42;
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPES[getShapeIndex(state)]; return SHAPES[getShapeIndex(state)];
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
IBlockReader iblockreader = context.getLevel(); IBlockReader iblockreader = context.getWorld();
BlockPos blockpos = context.getPos(); BlockPos blockpos = context.getPos();
return this.getDefaultState().with(WEST, this.getSide(iblockreader, blockpos, Direction.WEST)).with(EAST, this.getSide(iblockreader, blockpos, Direction.EAST)).with(NORTH, this.getSide(iblockreader, blockpos, Direction.NORTH)).with(SOUTH, this.getSide(iblockreader, blockpos, Direction.SOUTH)); return this.getDefaultState().with(WEST, this.getSide(iblockreader, blockpos, Direction.WEST)).with(EAST, this.getSide(iblockreader, blockpos, Direction.EAST)).with(NORTH, this.getSide(iblockreader, blockpos, Direction.NORTH)).with(SOUTH, this.getSide(iblockreader, blockpos, Direction.SOUTH));
} }
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, ILevel levelIn, BlockPos currentPos, BlockPos facingPos) { public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
if (facing == Direction.DOWN) { if (facing == Direction.DOWN) {
return stateIn; return stateIn;
} else { } else {
return facing == Direction.UP ? stateIn.with(WEST, this.getSide(levelIn, currentPos, Direction.WEST)).with(EAST, this.getSide(levelIn, currentPos, Direction.EAST)).with(NORTH, this.getSide(levelIn, currentPos, Direction.NORTH)).with(SOUTH, this.getSide(levelIn, currentPos, Direction.SOUTH)) : stateIn.with(RedstoneWireBlock.FACING_PROPERTY_MAP.get(facing), this.getSide(levelIn, currentPos, facing)); return facing == Direction.UP ? stateIn.with(WEST, this.getSide(worldIn, currentPos, Direction.WEST)).with(EAST, this.getSide(worldIn, currentPos, Direction.EAST)).with(NORTH, this.getSide(worldIn, currentPos, Direction.NORTH)).with(SOUTH, this.getSide(worldIn, currentPos, Direction.SOUTH)) : stateIn.with(RedstoneWireBlock.FACING_PROPERTY_MAP.get(facing), this.getSide(worldIn, currentPos, facing));
} }
} }
private RedstoneSide getSide(IBlockReader levelIn, BlockPos pos, Direction face) { private RedstoneSide getSide(IBlockReader worldIn, BlockPos pos, Direction face) {
BlockPos blockpos = pos.offset(face); BlockPos blockpos = pos.offset(face);
BlockState blockstate = levelIn.getBlockState(blockpos); BlockState blockstate = worldIn.getBlockState(blockpos);
BlockPos blockpos1 = pos.up(); BlockPos blockpos1 = pos.up();
BlockState blockstate1 = levelIn.getBlockState(blockpos1); BlockState blockstate1 = worldIn.getBlockState(blockpos1);
if (!blockstate1.isNormalCube(levelIn, blockpos1)) { if (!blockstate1.isNormalCube(worldIn, blockpos1)) {
boolean flag = blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER; boolean flag = blockstate.isSolidSide(worldIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
if (flag && this.canConnectTo(levelIn.getBlockState(blockpos.up()))) { if (flag && this.canConnectTo(worldIn.getBlockState(blockpos.up()))) {
if (blockstate.hasOpaqueCollisionShape(levelIn, blockpos)) { if (blockstate.hasOpaqueCollisionShape(worldIn, blockpos)) {
return RedstoneSide.UP; return RedstoneSide.UP;
} }
@ -111,7 +111,7 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
} }
return !this.canConnectTo(blockstate) && (blockstate.isNormalCube(levelIn, blockpos) || !this.canConnectTo(levelIn.getBlockState(blockpos.down()))) ? RedstoneSide.NONE : RedstoneSide.SIDE; return !this.canConnectTo(blockstate) && (blockstate.isNormalCube(worldIn, blockpos) || !this.canConnectTo(worldIn.getBlockState(blockpos.down()))) ? RedstoneSide.NONE : RedstoneSide.SIDE;
} }
protected boolean canConnectTo(BlockState blockState) { protected boolean canConnectTo(BlockState blockState) {
@ -120,32 +120,32 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
@Override @Override
public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) { public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
BlockPos blockpos = pos.down(); BlockPos blockpos = pos.down();
BlockState blockstate = levelIn.getBlockState(blockpos); BlockState blockstate = worldIn.getBlockState(blockpos);
return blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER; return blockstate.isSolidSide(worldIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
} }
@Override @Override
public VoxelShape getCollisionShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return Shapes.empty(); return VoxelShapes.empty();
} }
@Override @Override
public void onBlockAdded(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) { public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
if (oldState.getBlock() != state.getBlock() && !levelIn.isClientSide) { if (oldState.getBlock() != state.getBlock() && !worldIn.isRemote) {
for (Direction direction : Direction.Plane.VERTICAL) { for (Direction direction : Direction.Plane.VERTICAL) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this); worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (Direction direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.offset(direction1)); this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(direction1));
} }
for (Direction direction2 : Direction.Plane.HORIZONTAL) { for (Direction direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.offset(direction2); BlockPos blockpos = pos.offset(direction2);
if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) { if (worldIn.getBlockState(blockpos).isNormalCube(worldIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up()); this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
} else { } else {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down()); this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
} }
} }
@ -153,22 +153,22 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
@Override @Override
public void onReplaced(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) { public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (!isMoving && state.getBlock() != newState.getBlock()) { if (!isMoving && state.getBlock() != newState.getBlock()) {
super.onReplaced(state, levelIn, pos, newState, isMoving); super.onReplaced(state, worldIn, pos, newState, isMoving);
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
for (Direction direction : Direction.values()) { for (Direction direction : Direction.values()) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this); worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (Direction direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.offset(direction1)); this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(direction1));
} }
for (Direction direction2 : Direction.Plane.HORIZONTAL) { for (Direction direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.offset(direction2); BlockPos blockpos = pos.offset(direction2);
if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) { if (worldIn.getBlockState(blockpos).isNormalCube(worldIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up()); this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
} else { } else {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down()); this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
} }
} }
@ -177,47 +177,47 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
@Override @Override
public void neighborChanged(BlockState state, Level levelIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
if (!state.isValidPosition(levelIn, pos)) { if (!state.isValidPosition(worldIn, pos)) {
spawnDrops(state, levelIn, pos); spawnDrops(state, worldIn, pos);
levelIn.removeBlock(pos, false); worldIn.removeBlock(pos, false);
} }
} }
} }
@Override @Override
public void updateDiagonalNeighbors(BlockState state, ILevel levelIn, BlockPos pos, int flags, int recursionLeft) { public void updateDiagonalNeighbors(BlockState state, IWorld worldIn, BlockPos pos, int flags, int recursionLeft) {
BlockPos.Mutable pool = new BlockPos.Mutable(); BlockPos.Mutable pool = new BlockPos.Mutable();
for (Direction direction : Direction.Plane.HORIZONTAL) { for (Direction direction : Direction.Plane.HORIZONTAL) {
RedstoneSide redstoneside = state.get(RedstoneWireBlock.FACING_PROPERTY_MAP.get(direction)); RedstoneSide redstoneside = state.get(RedstoneWireBlock.FACING_PROPERTY_MAP.get(direction));
if (redstoneside != RedstoneSide.NONE && levelIn.getBlockState(pool.setPos(pos).move(direction)).getBlock() != this) { if (redstoneside != RedstoneSide.NONE && worldIn.getBlockState(pool.setPos(pos).move(direction)).getBlock() != this) {
pool.move(Direction.DOWN); pool.move(Direction.DOWN);
BlockState blockstate = levelIn.getBlockState(pool); BlockState blockstate = worldIn.getBlockState(pool);
if (blockstate.getBlock() != Blocks.OBSERVER) { if (blockstate.getBlock() != Blocks.OBSERVER) {
BlockPos blockpos = pool.offset(direction.getOpposite()); BlockPos blockpos = pool.offset(direction.getOpposite());
BlockState blockstate1 = blockstate.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos); BlockState blockstate1 = blockstate.updatePostPlacement(direction.getOpposite(), worldIn.getBlockState(blockpos), worldIn, pool, blockpos);
replaceBlock(blockstate, blockstate1, levelIn, pool, flags); replaceBlock(blockstate, blockstate1, worldIn, pool, flags);
} }
pool.setPos(pos).move(direction).move(Direction.UP); pool.setPos(pos).move(direction).move(Direction.UP);
BlockState blockstate3 = levelIn.getBlockState(pool); BlockState blockstate3 = worldIn.getBlockState(pool);
if (blockstate3.getBlock() != Blocks.OBSERVER) { if (blockstate3.getBlock() != Blocks.OBSERVER) {
BlockPos blockpos1 = pool.offset(direction.getOpposite()); BlockPos blockpos1 = pool.offset(direction.getOpposite());
BlockState blockstate2 = blockstate3.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1); BlockState blockstate2 = blockstate3.updatePostPlacement(direction.getOpposite(), worldIn.getBlockState(blockpos1), worldIn, pool, blockpos1);
replaceBlock(blockstate3, blockstate2, levelIn, pool, flags); replaceBlock(blockstate3, blockstate2, worldIn, pool, flags);
} }
} }
} }
} }
private void notifyWireNeighborsOfStateChange(Level levelIn, BlockPos pos) { private void notifyWireNeighborsOfStateChange(World worldIn, BlockPos pos) {
if (levelIn.getBlockState(pos).getBlock() == this) { if (worldIn.getBlockState(pos).getBlock() == this) {
levelIn.notifyNeighborsOfStateChange(pos, this); worldIn.notifyNeighborsOfStateChange(pos, this);
for (Direction direction : Direction.values()) { for (Direction direction : Direction.values()) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this); worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
} }
} }
} }

View file

@ -16,9 +16,9 @@ import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.biome.BiomeColors; import net.minecraft.world.biome.BiomeColors;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -34,11 +34,11 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
ModRegistry.add(this); ModRegistry.add(this);
} }
public static boolean convert(Level level, BlockPos pos) { public static boolean convert(World world, BlockPos pos) {
BlockState state = level.getBlockState(pos); BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof LeavesBlock && !(state.getBlock() instanceof BlockAncientLeaves || state.getBlock() instanceof BlockGoldenLeaves)) { if (state.getBlock() instanceof LeavesBlock && !(state.getBlock() instanceof BlockAncientLeaves || state.getBlock() instanceof BlockGoldenLeaves)) {
if (!level.isClientSide) { if (!world.isRemote) {
level.setBlockState(pos, ModBlocks.GOLDEN_LEAVES.getDefaultState() world.setBlockState(pos, ModBlocks.GOLDEN_LEAVES.getDefaultState()
.with(DISTANCE, state.hasProperty(DISTANCE) ? state.get(DISTANCE) : 1) .with(DISTANCE, state.hasProperty(DISTANCE) ? state.get(DISTANCE) : 1)
.with(PERSISTENT, state.hasProperty(PERSISTENT) ? state.get(PERSISTENT) : false)); .with(PERSISTENT, state.hasProperty(PERSISTENT) ? state.get(PERSISTENT) : false));
} }
@ -54,7 +54,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if (stateIn.get(STAGE) == HIGHEST_STAGE && rand.nextFloat() >= 0.75F) if (stateIn.get(STAGE) == HIGHEST_STAGE && rand.nextFloat() >= 0.75F)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + rand.nextFloat(), pos.getX() + rand.nextFloat(),
@ -73,10 +73,10 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public IBlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> { return (state, worldIn, pos, tintIndex) -> {
int color = 0xF2FF00; int color = 0xF2FF00;
if (state != null && levelIn != null && pos != null) { if (state != null && worldIn != null && pos != null) {
int foliage = BiomeColors.getFoliageColor(levelIn, pos); int foliage = BiomeColors.getFoliageColor(worldIn, pos);
return Helper.blendColors(color, foliage, state.get(STAGE) / (float) HIGHEST_STAGE); return Helper.blendColors(color, foliage, state.get(STAGE) / (float) HIGHEST_STAGE);
} else { } else {
return color; return color;
@ -91,18 +91,18 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
super.randomTick(state, levelIn, pos, random); super.randomTick(state, worldIn, pos, random);
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
int stage = state.get(STAGE); int stage = state.get(STAGE);
if (stage < HIGHEST_STAGE) { if (stage < HIGHEST_STAGE) {
levelIn.setBlockState(pos, state.with(STAGE, stage + 1)); worldIn.setBlockState(pos, state.with(STAGE, stage + 1));
} }
if (stage > 1) { if (stage > 1) {
BlockPos offset = pos.offset(Direction.func_239631_a_(random)); BlockPos offset = pos.offset(Direction.func_239631_a_(random));
if (levelIn.isBlockLoaded(offset)) if (worldIn.isBlockLoaded(offset))
convert(levelIn, offset); convert(worldIn, offset);
} }
} }
} }

View file

@ -1,31 +1,31 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGratedChute; import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.state.DirectionProperty; import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.IHopper; import net.minecraft.tileentity.IHopper;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.InteractionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -35,21 +35,21 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
public static final DirectionProperty FACING = HopperBlock.FACING; public static final DirectionProperty FACING = HopperBlock.FACING;
private static final VoxelShape INPUT_SHAPE = Block.makeCuboidShape(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D); private static final VoxelShape INPUT_SHAPE = Block.makeCuboidShape(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D);
private static final VoxelShape MIDDLE_SHAPE = Block.makeCuboidShape(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D); private static final VoxelShape MIDDLE_SHAPE = Block.makeCuboidShape(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D);
private static final VoxelShape INPUT_MIDDLE_SHAPE = Shapes.or(MIDDLE_SHAPE, INPUT_SHAPE); private static final VoxelShape INPUT_MIDDLE_SHAPE = VoxelShapes.or(MIDDLE_SHAPE, INPUT_SHAPE);
private static final VoxelShape COMBINED_SHAPE = Shapes.combineAndSimplify(INPUT_MIDDLE_SHAPE, IHopper.INSIDE_BOWL_SHAPE, IBooleanFunction.ONLY_FIRST); private static final VoxelShape COMBINED_SHAPE = VoxelShapes.combineAndSimplify(INPUT_MIDDLE_SHAPE, IHopper.INSIDE_BOWL_SHAPE, IBooleanFunction.ONLY_FIRST);
private static final VoxelShape DOWN_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D)); private static final VoxelShape DOWN_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D));
private static final VoxelShape EAST_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D)); private static final VoxelShape EAST_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D));
private static final VoxelShape NORTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D)); private static final VoxelShape NORTH_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D));
private static final VoxelShape SOUTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D)); private static final VoxelShape SOUTH_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D));
private static final VoxelShape WEST_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D)); private static final VoxelShape WEST_SHAPE = VoxelShapes.or(COMBINED_SHAPE, Block.makeCuboidShape(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D));
private static final VoxelShape DOWN_RAYTRACE_SHAPE = IHopper.INSIDE_BOWL_SHAPE; private static final VoxelShape DOWN_RAYTRACE_SHAPE = IHopper.INSIDE_BOWL_SHAPE;
private static final VoxelShape EAST_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D)); private static final VoxelShape EAST_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D));
private static final VoxelShape NORTH_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D)); private static final VoxelShape NORTH_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D));
private static final VoxelShape SOUTH_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D)); private static final VoxelShape SOUTH_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D));
private static final VoxelShape WEST_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D)); private static final VoxelShape WEST_RAYTRACE_SHAPE = VoxelShapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D));
public BlockGratedChute() { public BlockGratedChute() {
super("grated_chute", BlockEntityGratedChute::new, Properties.create(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL)); super("grated_chute", TileEntityGratedChute::new, Properties.create(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL));
} }
@Override @Override
@ -58,7 +58,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
switch (state.get(FACING)) { switch (state.get(FACING)) {
case DOWN: case DOWN:
return DOWN_SHAPE; return DOWN_SHAPE;
@ -76,7 +76,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
} }
@Override @Override
public VoxelShape getRaytraceShape(BlockState state, IBlockReader levelIn, BlockPos pos) { public VoxelShape getRaytraceShape(BlockState state, IBlockReader worldIn, BlockPos pos) {
switch (state.get(FACING)) { switch (state.get(FACING)) {
case DOWN: case DOWN:
return DOWN_RAYTRACE_SHAPE; return DOWN_RAYTRACE_SHAPE;
@ -94,18 +94,18 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (!player.isSneaking()) if (!player.isSneaking())
return InteractionResult.FAIL; return ActionResultType.FAIL;
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (!(tile instanceof BlockEntityGratedChute)) if (!(tile instanceof TileEntityGratedChute))
return InteractionResult.FAIL; return ActionResultType.FAIL;
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
BlockEntityGratedChute chute = (BlockEntityGratedChute) tile; TileEntityGratedChute chute = (TileEntityGratedChute) tile;
chute.isBlacklist = !chute.isBlacklist; chute.isBlacklist = !chute.isBlacklist;
chute.sendToClients(); chute.sendToClients();
} }
return InteractionResult.SUCCESS; return ActionResultType.SUCCESS;
} }
@Nullable @Nullable
@ -128,14 +128,14 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
} }
@Override @Override
public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) { public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntityGratedChute) { if (tile instanceof TileEntityGratedChute) {
IItemHandler handler = ((BlockEntityGratedChute) tile).getItemHandler(); IItemHandler handler = ((TileEntityGratedChute) tile).getItemHandler();
ItemStack stack = handler.getStackInSlot(0); ItemStack stack = handler.getStackInSlot(0);
if (stack.isEmpty()) if (stack.isEmpty())
return 0; return 0;
return Mth.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15); return MathHelper.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15);
} else } else
return 0; return 0;
} }

View file

@ -1,29 +1,29 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityHopperUpgrade; import de.ellpeck.naturesaura.blocks.tiles.TileEntityHopperUpgrade;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockHopperUpgrade extends BlockContainerImpl implements IVisualizable { public class BlockHopperUpgrade extends BlockContainerImpl implements IVisualizable {
public BlockHopperUpgrade() { public BlockHopperUpgrade() {
super("hopper_upgrade", BlockEntityHopperUpgrade::new, Properties.create(Material.IRON).hardnessAndResistance(2.5F).sound(SoundType.METAL)); super("hopper_upgrade", TileEntityHopperUpgrade::new, Properties.create(Material.IRON).hardnessAndResistance(2.5F).sound(SoundType.METAL));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(7); return new AxisAlignedBB(pos).grow(7);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x434f3f; return 0x434f3f;
} }
} }

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.world.level.block.Block; import net.minecraft.block.Block;
public class BlockImpl extends Block implements IModItem { public class BlockImpl extends Block implements IModItem {

View file

@ -1,37 +1,37 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityItemDistributor; import de.ellpeck.naturesaura.blocks.tiles.TileEntityItemDistributor;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.InteractionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.level.Level; import net.minecraft.world.World;
public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState { public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState {
public BlockItemDistributor() { public BlockItemDistributor() {
super("item_distributor", BlockEntityItemDistributor::new, Properties.from(Blocks.STONE_BRICKS)); super("item_distributor", TileEntityItemDistributor::new, Properties.from(Blocks.STONE_BRICKS));
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (!player.isSneaking()) if (!player.isSneaking())
return InteractionResult.FAIL; return ActionResultType.FAIL;
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (!(tile instanceof BlockEntityItemDistributor)) if (!(tile instanceof TileEntityItemDistributor))
return InteractionResult.FAIL; return ActionResultType.FAIL;
if (!levelIn.isClientSide) { if (!worldIn.isRemote) {
BlockEntityItemDistributor distributor = (BlockEntityItemDistributor) tile; TileEntityItemDistributor distributor = (TileEntityItemDistributor) tile;
distributor.isRandomMode = !distributor.isRandomMode; distributor.isRandomMode = !distributor.isRandomMode;
distributor.sendToClients(); distributor.sendToClients();
} }
return InteractionResult.SUCCESS; return ActionResultType.SUCCESS;
} }
@Override @Override

View file

@ -12,8 +12,8 @@ import net.minecraft.item.BlockItemUseContext;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -30,7 +30,7 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F,
@ -39,7 +39,7 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }

View file

@ -1,29 +1,29 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityMossGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityMossGenerator;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockMossGenerator extends BlockContainerImpl implements IVisualizable { public class BlockMossGenerator extends BlockContainerImpl implements IVisualizable {
public BlockMossGenerator() { public BlockMossGenerator() {
super("moss_generator", BlockEntityMossGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("moss_generator", TileEntityMossGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(2); return new AxisAlignedBB(pos).grow(2);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x15702d; return 0x15702d;
} }
} }

View file

@ -3,46 +3,45 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar; import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.Player;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.InteractionResult; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.world.level.BlockGetter; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.level.Level; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.IBlockReader;
import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.World;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.ToolType; import net.minecraftforge.common.ToolType;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvider<BlockEntityNatureAltar>, ICustomBlockState { public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvider<TileEntityNatureAltar>, ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(0, 0, 0, 1, 12 / 16F, 1); private static final VoxelShape SHAPE = VoxelShapes.create(0, 0, 0, 1, 12 / 16F, 1);
public static final BooleanProperty NETHER = BooleanProperty.create("nether"); public static final BooleanProperty NETHER = BooleanProperty.create("nether");
public BlockNatureAltar() { public BlockNatureAltar() {
super("nature_altar", BlockEntityNatureAltar::new, Block.Properties.create(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("nature_altar", TileEntityNatureAltar::new, Properties.create(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
this.setDefaultState(this.getDefaultState().with(NETHER, false)); this.setDefaultState(this.getDefaultState().with(NETHER, false));
} }
@ -52,18 +51,17 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
} }
@Override @Override
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@Override @Override
public Tuple<BlockEntityType<BlockEntityNatureAltar>, Supplier<Function<? super BlockEntityRenderDispatcher, ? extends BlockEntityRenderer<? super BlockEntityNatureAltar>>>> getTESR() { public Tuple<TileEntityType<TileEntityNatureAltar>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityNatureAltar>>>> getTESR() {
return new Tuple<>(ModTileEntities.NATURE_ALTAR, () -> RenderNatureAltar::new); return new Tuple<>(ModTileEntities.NATURE_ALTAR, () -> RenderNatureAltar::new);
} }
@ -81,7 +79,7 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
@Nullable @Nullable
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
boolean nether = IAuraType.forLevel(context.getLevel()).isSimilar(NaturesAuraAPI.TYPE_NETHER); boolean nether = IAuraType.forWorld(context.getWorld()).isSimilar(NaturesAuraAPI.TYPE_NETHER);
return super.getStateForPlacement(context).with(NETHER, nether); return super.getStateForPlacement(context).with(NETHER, nether);
} }
} }

View file

@ -7,9 +7,9 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.IGrowable; import net.minecraft.block.IGrowable;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import java.util.Random; import java.util.Random;
@ -20,11 +20,11 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IG
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
BlockPos up = pos.up(); BlockPos up = pos.up();
BlockState upState = levelIn.getBlockState(up); BlockState upState = worldIn.getBlockState(up);
if (upState.isSolidSide(levelIn, up, Direction.DOWN)) if (upState.isSolidSide(worldIn, up, Direction.DOWN))
levelIn.setBlockState(pos, Blocks.NETHERRACK.getDefaultState()); worldIn.setBlockState(pos, Blocks.NETHERRACK.getDefaultState());
} }
@Override @Override
@ -36,17 +36,17 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IG
} }
@Override @Override
public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) { public boolean canGrow(IBlockReader worldIn, BlockPos pos, BlockState state, boolean isClient) {
return levelIn.getBlockState(pos.up()).isAir(levelIn, pos.up()); return worldIn.getBlockState(pos.up()).isAir(worldIn, pos.up());
} }
@Override @Override
public boolean canUseBonemeal(Level levelIn, Random rand, BlockPos pos, BlockState state) { public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, BlockState state) {
return true; return true;
} }
@Override @Override
public void grow(ServerLevel level, Random rand, BlockPos pos, BlockState state) { public void grow(ServerWorld world, Random rand, BlockPos pos, BlockState state) {
BlockPos blockpos = pos.up(); BlockPos blockpos = pos.up();
BlockState blockstate = Blocks.GRASS.getDefaultState(); BlockState blockstate = Blocks.GRASS.getDefaultState();
@ -56,23 +56,23 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IG
while (true) { while (true) {
if (j >= i / 16) { if (j >= i / 16) {
BlockState blockstate2 = level.getBlockState(blockpos1); BlockState blockstate2 = world.getBlockState(blockpos1);
if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) { if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
((IGrowable) blockstate.getBlock()).grow(level, rand, blockpos1, blockstate2); ((IGrowable) blockstate.getBlock()).grow(world, rand, blockpos1, blockstate2);
} }
if (!blockstate2.isAir()) { if (!blockstate2.isAir()) {
break; break;
} }
if (blockstate.isValidPosition(level, blockpos1)) { if (blockstate.isValidPosition(world, blockpos1)) {
level.setBlockState(blockpos1, blockstate, 3); world.setBlockState(blockpos1, blockstate, 3);
} }
break; break;
} }
blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1); blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
if (level.getBlockState(blockpos1.down()).getBlock() != this || level.getBlockState(blockpos1).hasOpaqueCollisionShape(level, blockpos1)) { if (world.getBlockState(blockpos1.down()).getBlock() != this || world.getBlockState(blockpos1).hasOpaqueCollisionShape(world, blockpos1)) {
break; break;
} }

View file

@ -4,7 +4,7 @@ import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOakGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityOakGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SaplingBlock; import net.minecraft.block.SaplingBlock;
@ -12,12 +12,12 @@ import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.ILevel; import net.minecraft.world.IWorld;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.level.SaplingGrowTreeEvent; import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.Random; import java.util.Random;
@ -25,24 +25,24 @@ import java.util.Random;
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockOakGenerator() { public BlockOakGenerator() {
super("oak_generator", BlockEntityOakGenerator::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); super("oak_generator", TileEntityOakGenerator::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent @SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) { public void onTreeGrow(SaplingGrowTreeEvent event) {
ILevel level = event.getLevel(); IWorld world = event.getWorld();
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel(level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) if (world instanceof World && !world.isRemote() && IAuraType.forWorld(world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
&& level.getBlockState(pos).getBlock() instanceof SaplingBlock) { && world.getBlockState(pos).getBlock() instanceof SaplingBlock) {
Helper.getBlockEntitiesInArea(level, pos, 10, tile -> { Helper.getTileEntitiesInArea(world, pos, 10, tile -> {
if (!(tile instanceof BlockEntityOakGenerator)) if (!(tile instanceof TileEntityOakGenerator))
return false; return false;
Random rand = event.getRand(); Random rand = event.getRand();
if (rand.nextInt(10) == 0) if (rand.nextInt(10) == 0)
((BlockEntityOakGenerator) tile).scheduledBigTrees.add(pos); ((TileEntityOakGenerator) tile).scheduledBigTrees.add(pos);
long seed; long seed;
do { do {
@ -59,13 +59,13 @@ public class BlockOakGenerator extends BlockContainerImpl implements IVisualizab
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(10); return new AxisAlignedBB(pos).grow(10);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x2e7a11; return 0x2e7a11;
} }

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable; import de.ellpeck.naturesaura.blocks.tiles.TileEntityOfferingTable;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderOfferingTable; import de.ellpeck.naturesaura.blocks.tiles.render.RenderOfferingTable;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
@ -10,30 +10,30 @@ import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.InteractionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.Level; import net.minecraft.world.World;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvider<BlockEntityOfferingTable>, ICustomBlockState { public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvider<TileEntityOfferingTable>, ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F); private static final VoxelShape SHAPE = VoxelShapes.create(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F);
public BlockOfferingTable() { public BlockOfferingTable() {
super("offering_table", BlockEntityOfferingTable::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); super("offering_table", TileEntityOfferingTable::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD));
} }
@Override @Override
@ -42,17 +42,17 @@ public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvi
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
public Tuple<BlockEntityType<BlockEntityOfferingTable>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityOfferingTable>>>> getTESR() { public Tuple<TileEntityType<TileEntityOfferingTable>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityOfferingTable>>>> getTESR() {
return new Tuple<>(ModTileEntities.OFFERING_TABLE, () -> RenderOfferingTable::new); return new Tuple<>(ModTileEntities.OFFERING_TABLE, () -> RenderOfferingTable::new);
} }

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPickupStopper; import de.ellpeck.naturesaura.blocks.tiles.TileEntityPickupStopper;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
@ -10,11 +10,11 @@ import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -23,21 +23,21 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockPickupStopper extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockPickupStopper extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockPickupStopper() { public BlockPickupStopper() {
super("pickup_stopper", BlockEntityPickupStopper::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("pickup_stopper", TileEntityPickupStopper::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent @SubscribeEvent
public void onPickup(EntityItemPickupEvent event) { public void onPickup(EntityItemPickupEvent event) {
Player player = event.getPlayer(); PlayerEntity player = event.getPlayer();
if (player != null && !player.isSneaking()) { if (player != null && !player.isSneaking()) {
ItemEntity item = event.getItem(); ItemEntity item = event.getItem();
BlockPos pos = item.getPosition(); BlockPos pos = item.getPosition();
Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> { Helper.getTileEntitiesInArea(item.world, pos, 8, tile -> {
if (!(tile instanceof BlockEntityPickupStopper)) if (!(tile instanceof TileEntityPickupStopper))
return false; return false;
BlockEntityPickupStopper stopper = (BlockEntityPickupStopper) tile; TileEntityPickupStopper stopper = (TileEntityPickupStopper) tile;
float radius = stopper.getRadius(); float radius = stopper.getRadius();
if (radius <= 0F) if (radius <= 0F)
return false; return false;
@ -47,8 +47,8 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
event.setCanceled(true); event.setCanceled(true);
if (item.level.getGameTime() % 3 == 0) if (item.world.getGameTime() % 3 == 0)
PacketHandler.sendToAllAround(item.level, pos, 32, PacketHandler.sendToAllAround(item.world, pos, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.PICKUP_STOPPER)); new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.PICKUP_STOPPER));
return true; return true;
}); });
@ -57,10 +57,10 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof BlockEntityPickupStopper) { if (tile instanceof TileEntityPickupStopper) {
double radius = ((BlockEntityPickupStopper) tile).getRadius(); double radius = ((TileEntityPickupStopper) tile).getRadius();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AxisAlignedBB(pos).grow(radius);
} }
@ -69,7 +69,7 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0xf4aa42; return 0xf4aa42;
} }

View file

@ -1,32 +1,32 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPlacer; import de.ellpeck.naturesaura.blocks.tiles.TileEntityPlacer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockPlacer extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockPlacer extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockPlacer() { public BlockPlacer() {
super("placer", BlockEntityPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("placer", TileEntityPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(5); return new AxisAlignedBB(pos).grow(5);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x078a93; return 0x078a93;
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPotionGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityPotionGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -8,7 +8,7 @@ import net.minecraftforge.common.ToolType;
public class BlockPotionGenerator extends BlockContainerImpl implements ICustomBlockState { public class BlockPotionGenerator extends BlockContainerImpl implements ICustomBlockState {
public BlockPotionGenerator() { public BlockPotionGenerator() {
super("potion_generator", BlockEntityPotionGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).harvestTool(ToolType.PICKAXE).harvestLevel(1)); super("potion_generator", TileEntityPotionGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).harvestTool(ToolType.PICKAXE).harvestLevel(1));
} }
@Override @Override

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPowderPlacer; import de.ellpeck.naturesaura.blocks.tiles.TileEntityPowderPlacer;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -9,15 +9,15 @@ import net.minecraft.block.material.Material;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState { public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(0F, 0F, 0F, 1F, 4 / 16F, 1F); private static final VoxelShape SHAPE = VoxelShapes.create(0F, 0F, 0F, 1F, 4 / 16F, 1F);
public BlockPowderPlacer() { public BlockPowderPlacer() {
super("powder_placer", BlockEntityPowderPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE)); super("powder_placer", TileEntityPowderPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE));
} }
@Override @Override
@ -26,7 +26,7 @@ public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBloc
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }

View file

@ -3,7 +3,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntityProjectileGenerator;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderProjectileGenerator; import de.ellpeck.naturesaura.blocks.tiles.render.RenderProjectileGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
@ -13,8 +13,8 @@ import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.DispenserBlock; import net.minecraft.block.DispenserBlock;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.dispenser.IPosition; import net.minecraft.dispenser.IPosition;
import net.minecraft.dispenser.ProjectileDispenseBehavior; import net.minecraft.dispenser.ProjectileDispenseBehavior;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -25,15 +25,15 @@ import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.projectile.TridentEntity; import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.ProjectileImpactEvent; import net.minecraftforge.event.entity.ProjectileImpactEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -42,24 +42,24 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider<BlockEntityProjectileGenerator>, ICustomBlockState { public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider<TileEntityProjectileGenerator>, ICustomBlockState {
public BlockProjectileGenerator() { public BlockProjectileGenerator() {
super("projectile_generator", BlockEntityProjectileGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("projectile_generator", TileEntityProjectileGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
DispenserBlock.registerDispenseBehavior(Items.ENDER_PEARL, new ProjectileDispenseBehavior() { DispenserBlock.registerDispenseBehavior(Items.ENDER_PEARL, new ProjectileDispenseBehavior() {
@Override @Override
protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) { protected ProjectileEntity getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn) {
EnderPearlEntity ret = new EnderPearlEntity(EntityType.ENDER_PEARL, levelIn); EnderPearlEntity ret = new EnderPearlEntity(EntityType.ENDER_PEARL, worldIn);
ret.setPosition(position.getX(), position.getY(), position.getZ()); ret.setPosition(position.getX(), position.getY(), position.getZ());
return ret; return ret;
} }
}); });
DispenserBlock.registerDispenseBehavior(Items.TRIDENT, new ProjectileDispenseBehavior() { DispenserBlock.registerDispenseBehavior(Items.TRIDENT, new ProjectileDispenseBehavior() {
@Override @Override
protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) { protected ProjectileEntity getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn) {
TridentEntity ret = new TridentEntity(EntityType.TRIDENT, levelIn); TridentEntity ret = new TridentEntity(EntityType.TRIDENT, worldIn);
ret.setPosition(position.getX(), position.getY(), position.getZ()); ret.setPosition(position.getX(), position.getY(), position.getZ());
// set thrownStack // set thrownStack
ObfuscationReflectionHelper.setPrivateValue(TridentEntity.class, ret, stackIn.copy(), "field_203054_h"); ObfuscationReflectionHelper.setPrivateValue(TridentEntity.class, ret, stackIn.copy(), "field_203054_h");
@ -72,7 +72,7 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
@SubscribeEvent @SubscribeEvent
public void onProjectileImpact(ProjectileImpactEvent event) { public void onProjectileImpact(ProjectileImpactEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity.level.isClientSide) if (entity.world.isRemote)
return; return;
RayTraceResult ray = event.getRayTraceResult(); RayTraceResult ray = event.getRayTraceResult();
if (!(ray instanceof BlockRayTraceResult)) if (!(ray instanceof BlockRayTraceResult))
@ -81,10 +81,10 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
BlockPos pos = blockRay.getPos(); BlockPos pos = blockRay.getPos();
if (pos == null) if (pos == null)
return; return;
BlockEntity tile = entity.level.getBlockEntity(pos); TileEntity tile = entity.world.getTileEntity(pos);
if (!(tile instanceof BlockEntityProjectileGenerator)) if (!(tile instanceof TileEntityProjectileGenerator))
return; return;
BlockEntityProjectileGenerator generator = (BlockEntityProjectileGenerator) tile; TileEntityProjectileGenerator generator = (TileEntityProjectileGenerator) tile;
if (generator.nextSide != blockRay.getFace()) if (generator.nextSide != blockRay.getFace())
return; return;
Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType()); Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType());
@ -94,9 +94,9 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
return; return;
generator.generateAura(amount); generator.generateAura(amount);
PacketHandler.sendToAllAround(entity.level, pos, 32, PacketHandler.sendToAllAround(entity.world, pos, 32,
new PacketParticles((float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.PROJECTILE_GEN, pos.getX(), pos.getY(), pos.getZ())); new PacketParticles((float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.PROJECTILE_GEN, pos.getX(), pos.getY(), pos.getZ()));
entity.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ENDER_EYE_LAUNCH, SoundCategory.BLOCKS, 0.8F, 1F); entity.world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ENDER_EYE_LAUNCH, SoundCategory.BLOCKS, 0.8F, 1F);
generator.nextSide = generator.nextSide.rotateY(); generator.nextSide = generator.nextSide.rotateY();
generator.sendToClients(); generator.sendToClients();
@ -106,7 +106,7 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
} }
@Override @Override
public Tuple<BlockEntityType<BlockEntityProjectileGenerator>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityProjectileGenerator>>>> getTESR() { public Tuple<TileEntityType<TileEntityProjectileGenerator>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityProjectileGenerator>>>> getTESR() {
return new Tuple<>(ModTileEntities.PROJECTILE_GENERATOR, () -> RenderProjectileGenerator::new); return new Tuple<>(ModTileEntities.PROJECTILE_GENERATOR, () -> RenderProjectileGenerator::new);
} }

View file

@ -2,14 +2,14 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityRFConverter; import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
public class BlockRFConverter extends BlockContainerImpl { public class BlockRFConverter extends BlockContainerImpl {
public BlockRFConverter() { public BlockRFConverter() {
super("rf_converter", BlockEntityRFConverter::new, Properties.create(Material.ROCK).sound(SoundType.STONE).hardnessAndResistance(3)); super("rf_converter", TileEntityRFConverter::new, Properties.create(Material.ROCK).sound(SoundType.STONE).hardnessAndResistance(3));
} }
@Override @Override

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySlimeSplitGenerator; import de.ellpeck.naturesaura.blocks.tiles.TileEntitySlimeSplitGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
@ -10,7 +10,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.SlimeEntity; import net.minecraft.entity.monster.SlimeEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -19,7 +19,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSlimeSplitGenerator() { public BlockSlimeSplitGenerator() {
super("slime_split_generator", BlockEntitySlimeSplitGenerator::new, Properties.from(Blocks.SLIME_BLOCK).hardnessAndResistance(2)); super("slime_split_generator", TileEntitySlimeSplitGenerator::new, Properties.from(Blocks.SLIME_BLOCK).hardnessAndResistance(2));
MinecraftForge.EVENT_BUS.register(new Events()); MinecraftForge.EVENT_BUS.register(new Events());
} }
@ -33,13 +33,13 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(pos).grow(8); return new AxisAlignedBB(pos).grow(8);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x4da84f; return 0x4da84f;
} }
@ -48,16 +48,16 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
@SubscribeEvent @SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) { public void onLivingDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving(); LivingEntity entity = event.getEntityLiving();
if (!(entity instanceof SlimeEntity) || entity.level.isClientSide) if (!(entity instanceof SlimeEntity) || entity.world.isRemote)
return; return;
SlimeEntity slime = (SlimeEntity) entity; SlimeEntity slime = (SlimeEntity) entity;
int size = slime.getSlimeSize(); int size = slime.getSlimeSize();
if (size <= 1) if (size <= 1)
return; return;
Helper.getBlockEntitiesInArea(entity.level, entity.getPosition(), 8, tile -> { Helper.getTileEntitiesInArea(entity.world, entity.getPosition(), 8, tile -> {
if (!(tile instanceof BlockEntitySlimeSplitGenerator)) if (!(tile instanceof TileEntitySlimeSplitGenerator))
return false; return false;
BlockEntitySlimeSplitGenerator gen = (BlockEntitySlimeSplitGenerator) tile; TileEntitySlimeSplitGenerator gen = (TileEntitySlimeSplitGenerator) tile;
if (gen.isBusy()) if (gen.isBusy())
return false; return false;
gen.startGenerating(slime); gen.startGenerating(slime);

View file

@ -1,28 +1,28 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySnowCreator; import de.ellpeck.naturesaura.blocks.tiles.TileEntitySnowCreator;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSnowCreator() { public BlockSnowCreator() {
super("snow_creator", BlockEntitySnowCreator::new, Properties.from(Blocks.STONE_BRICKS)); super("snow_creator", TileEntitySnowCreator::new, Properties.from(Blocks.STONE_BRICKS));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof BlockEntitySnowCreator) { if (tile instanceof TileEntitySnowCreator) {
int radius = ((BlockEntitySnowCreator) tile).getRange(); int radius = ((TileEntitySnowCreator) tile).getRange();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AxisAlignedBB(pos).grow(radius);
} }
@ -30,7 +30,7 @@ public class BlockSnowCreator extends BlockContainerImpl implements IVisualizabl
} }
@Override @Override
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0xdbe9ff; return 0xdbe9ff;
} }

View file

@ -1,11 +1,11 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySpawnLamp; import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.WorldData;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
@ -15,17 +15,17 @@ import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.MobEntity; import net.minecraft.entity.MobEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.ILevel; import net.minecraft.world.IWorld;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -37,10 +37,10 @@ import java.util.function.Supplier;
public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable, ICustomBlockState, ICustomRenderType { public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable, ICustomBlockState, ICustomRenderType {
private static final VoxelShape SHAPE = Shapes.create(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F); private static final VoxelShape SHAPE = VoxelShapes.create(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F);
public BlockSpawnLamp() { public BlockSpawnLamp() {
super("spawn_lamp", BlockEntitySpawnLamp::new, Properties.create(Material.IRON).hardnessAndResistance(3F).setLightLevel(s -> 15).sound(SoundType.METAL)); super("spawn_lamp", TileEntitySpawnLamp::new, Properties.create(Material.IRON).hardnessAndResistance(3F).setLightLevel(s -> 15).sound(SoundType.METAL));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@ -53,12 +53,12 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
public void onSpawn(LivingSpawnEvent.CheckSpawn event) { public void onSpawn(LivingSpawnEvent.CheckSpawn event) {
if (event.getSpawner() != null) if (event.getSpawner() != null)
return; return;
ILevel level = event.getLevel(); IWorld world = event.getWorld();
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ()); BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ());
if (!(level instanceof Level)) if (!(world instanceof World))
return; return;
LevelData data = (LevelData) ILevelData.getLevelData((Level) level); WorldData data = (WorldData) IWorldData.getWorldData((World) world);
for (BlockEntitySpawnLamp lamp : data.spawnLamps) { for (TileEntitySpawnLamp lamp : data.spawnLamps) {
if (lamp.isRemoved()) if (lamp.isRemoved())
continue; continue;
@ -71,11 +71,11 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
continue; continue;
MobEntity entity = (MobEntity) event.getEntityLiving(); MobEntity entity = (MobEntity) event.getEntityLiving();
if (entity.canSpawn(level, event.getSpawnReason()) && entity.isNotColliding(level)) { if (entity.canSpawn(world, event.getSpawnReason()) && entity.isNotColliding(world)) {
BlockPos spot = IAuraChunk.getHighestSpot(level, lampPos, 32, lampPos); BlockPos spot = IAuraChunk.getHighestSpot(world, lampPos, 32, lampPos);
IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 200); IAuraChunk.getAuraChunk(world, spot).drainAura(spot, 200);
PacketHandler.sendToAllAround((ServerLevel) level, lampPos, 32, PacketHandler.sendToAllAround((ServerWorld) world, lampPos, 32,
new PacketParticles(lampPos.getX(), lampPos.getY(), lampPos.getZ(), PacketParticles.Type.SPAWN_LAMP)); new PacketParticles(lampPos.getX(), lampPos.getY(), lampPos.getZ(), PacketParticles.Type.SPAWN_LAMP));
} }
@ -85,16 +85,16 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof BlockEntitySpawnLamp) { if (tile instanceof TileEntitySpawnLamp) {
int radius = ((BlockEntitySpawnLamp) tile).getRadius(); int radius = ((TileEntitySpawnLamp) tile).getRadius();
if (radius > 0) if (radius > 0)
return new AxisAlignedBB(pos).grow(radius); return new AxisAlignedBB(pos).grow(radius);
} }
@ -103,7 +103,7 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(Level level, BlockPos pos) { public int getVisualizationColor(World world, BlockPos pos) {
return 0x825ee5; return 0x825ee5;
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySpring; import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpring;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.IColorProvidingBlock; import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.IColorProvidingItem; import de.ellpeck.naturesaura.reg.IColorProvidingItem;
@ -13,14 +13,14 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.ILevel; import net.minecraft.world.IWorld;
import net.minecraft.level.biome.BiomeColors; import net.minecraft.world.biome.BiomeColors;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -28,13 +28,13 @@ import java.util.function.Supplier;
public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, IBucketPickupHandler, ICustomRenderType { public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, IBucketPickupHandler, ICustomRenderType {
public BlockSpring() { public BlockSpring() {
super("spring", BlockEntitySpring::new, Properties.from(Blocks.STONE_BRICKS)); super("spring", TileEntitySpring::new, Properties.from(Blocks.STONE_BRICKS));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public IBlockColor getBlockColor() {
return (state, level, pos, i) -> BiomeColors.getWaterColor(level, pos); return (state, world, pos, i) -> BiomeColors.getWaterColor(world, pos);
} }
@Override @Override
@ -44,8 +44,8 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
return new IItemColor() { return new IItemColor() {
@Override @Override
public int getColor(ItemStack stack, int i) { public int getColor(ItemStack stack, int i) {
Player player = Minecraft.getInstance().player; PlayerEntity player = Minecraft.getInstance().player;
return BiomeColors.getWaterColor(player.level, player.getPosition()); return BiomeColors.getWaterColor(player.world, player.getPosition());
} }
}; };
} }
@ -56,10 +56,10 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
} }
@Override @Override
public Fluid pickupFluid(ILevel levelIn, BlockPos pos, BlockState state) { public Fluid pickupFluid(IWorld worldIn, BlockPos pos, BlockState state) {
BlockEntity tile = levelIn.getBlockEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof BlockEntitySpring) if (tile instanceof TileEntitySpring)
((BlockEntitySpring) tile).consumeAura(2500); ((TileEntitySpring) tile).consumeAura(2500);
return Fluids.WATER; return Fluids.WATER;
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityTimeChanger; import de.ellpeck.naturesaura.blocks.tiles.TileEntityTimeChanger;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
@ -8,7 +8,7 @@ import net.minecraft.block.material.Material;
public class BlockTimeChanger extends BlockContainerImpl implements ICustomBlockState { public class BlockTimeChanger extends BlockContainerImpl implements ICustomBlockState {
public BlockTimeChanger() { public BlockTimeChanger() {
super("time_changer", BlockEntityTimeChanger::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("time_changer", TileEntityTimeChanger::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
} }
@Override @Override

View file

@ -1,13 +1,13 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWeatherChanger; import de.ellpeck.naturesaura.blocks.tiles.TileEntityWeatherChanger;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState; import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
public class BlockWeatherChanger extends BlockContainerImpl implements ICustomBlockState { public class BlockWeatherChanger extends BlockContainerImpl implements ICustomBlockState {
public BlockWeatherChanger() { public BlockWeatherChanger() {
super("weather_changer", BlockEntityWeatherChanger::new, Properties.from(Blocks.STONE_BRICKS)); super("weather_changer", TileEntityWeatherChanger::new, Properties.from(Blocks.STONE_BRICKS));
} }
@Override @Override

View file

@ -3,7 +3,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand; import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand; import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
@ -13,27 +13,27 @@ import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.InteractionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.level.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.level.ILevel; import net.minecraft.world.IWorld;
import net.minecraft.level.Level; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ToolType; import net.minecraftforge.common.ToolType;
import net.minecraftforge.event.level.SaplingGrowTreeEvent; import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.mutable.MutableObject;
@ -43,12 +43,12 @@ import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<BlockEntityWoodStand>, ICustomBlockState { public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<TileEntityWoodStand>, ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F); private static final VoxelShape SHAPE = VoxelShapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F);
public BlockWoodStand() { public BlockWoodStand() {
super("wood_stand", BlockEntityWoodStand::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD).harvestLevel(0).harvestTool(ToolType.AXE)); super("wood_stand", TileEntityWoodStand::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD).harvestLevel(0).harvestTool(ToolType.AXE));
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@ -58,28 +58,28 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@SubscribeEvent @SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) { public void onTreeGrow(SaplingGrowTreeEvent event) {
ILevel level = event.getLevel(); IWorld world = event.getWorld();
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
if (!level.isClientSide() && level instanceof Level) { if (!world.isRemote() && world instanceof World) {
if (Multiblocks.TREE_RITUAL.isComplete((Level) level, pos)) { if (Multiblocks.TREE_RITUAL.isComplete((World) world, pos)) {
BlockState sapling = level.getBlockState(pos); BlockState sapling = world.getBlockState(pos);
ItemStack saplingStack = sapling.getBlock().getItem(level, pos, sapling); ItemStack saplingStack = sapling.getBlock().getItem(world, pos, sapling);
if (!saplingStack.isEmpty()) { if (!saplingStack.isEmpty()) {
for (TreeRitualRecipe recipe : ((Level) level).getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null)) { for (TreeRitualRecipe recipe : ((World) world).getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null)) {
if (recipe.saplingType.test(saplingStack)) { if (recipe.saplingType.test(saplingStack)) {
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients)); List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients));
MutableObject<BlockEntityWoodStand> toPick = new MutableObject<>(); MutableObject<TileEntityWoodStand> toPick = new MutableObject<>();
boolean fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> { boolean fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> {
BlockEntity tile = level.getBlockEntity(tilePos); TileEntity tile = world.getTileEntity(tilePos);
if (tile instanceof BlockEntityWoodStand) { if (tile instanceof TileEntityWoodStand) {
BlockEntityWoodStand stand = (BlockEntityWoodStand) tile; TileEntityWoodStand stand = (TileEntityWoodStand) tile;
ItemStack stack = stand.items.getStackInSlot(0); ItemStack stack = stand.items.getStackInSlot(0);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
for (int i = required.size() - 1; i >= 0; i--) { for (int i = required.size() - 1; i >= 0; i--) {
@ -111,12 +111,12 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
} }
@Override @Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);
} }
@Override @Override
public Tuple<BlockEntityType<BlockEntityWoodStand>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityWoodStand>>>> getTESR() { public Tuple<TileEntityType<TileEntityWoodStand>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityWoodStand>>>> getTESR() {
return new Tuple<>(ModTileEntities.WOOD_STAND, () -> RenderWoodStand::new); return new Tuple<>(ModTileEntities.WOOD_STAND, () -> RenderWoodStand::new);
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import net.minecraft.world.level.block.Block; import net.minecraft.block.Block;
@SuppressWarnings("FieldNamingConvention") @SuppressWarnings("FieldNamingConvention")
public final class ModBlocks { public final class ModBlocks {

View file

@ -8,7 +8,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level; import net.minecraft.world.World;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -83,11 +83,11 @@ public class Multiblock implements IMultiblock {
if (value instanceof BlockState) { if (value instanceof BlockState) {
BlockState state = (BlockState) value; BlockState state = (BlockState) value;
matchers.put(c, new Matcher(state, matchers.put(c, new Matcher(state,
(level, start, offset, pos, other, otherC) -> other == state)); (world, start, offset, pos, other, otherC) -> other == state));
} else if (value instanceof Block) { } else if (value instanceof Block) {
Block block = (Block) value; Block block = (Block) value;
matchers.put(c, new Matcher(block.getDefaultState(), matchers.put(c, new Matcher(block.getDefaultState(),
(level, start, offset, pos, state, otherC) -> state.getBlock() == block)); (world, start, offset, pos, state, otherC) -> state.getBlock() == block));
} else } else
matchers.put(c, (Matcher) value); matchers.put(c, (Matcher) value);
} }
@ -107,11 +107,11 @@ public class Multiblock implements IMultiblock {
} }
@Override @Override
public boolean isComplete(Level level, BlockPos center) { public boolean isComplete(World world, BlockPos center) {
BlockPos start = this.getStart(center); BlockPos start = this.getStart(center);
return this.forEach(center, (char) 0, (pos, matcher) -> { return this.forEach(center, (char) 0, (pos, matcher) -> {
BlockPos offset = pos.subtract(start); BlockPos offset = pos.subtract(start);
return matcher.getCheck().matches(level, start, offset, pos, level.getBlockState(pos), this.getChar(offset)); return matcher.getCheck().matches(world, start, offset, pos, world.getBlockState(pos), this.getChar(offset));
}); });
} }

View file

@ -8,12 +8,12 @@ import de.ellpeck.naturesaura.blocks.BlockNatureAltar;
import de.ellpeck.naturesaura.blocks.ModBlocks; import de.ellpeck.naturesaura.blocks.ModBlocks;
import de.ellpeck.naturesaura.data.BlockTagProvider; import de.ellpeck.naturesaura.data.BlockTagProvider;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.resources.ResourceLocation; import net.minecraft.block.Blocks;
import net.minecraft.block.SaplingBlock;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.ItemStack; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.material.Material;
public final class Multiblocks { public final class Multiblocks {
@ -38,23 +38,23 @@ public final class Multiblocks {
'B', Blocks.NETHER_BRICKS, 'B', Blocks.NETHER_BRICKS,
'W', Matcher.tag(Blocks.CRIMSON_PLANKS, BlockTagProvider.NETHER_ALTAR_WOOD), 'W', Matcher.tag(Blocks.CRIMSON_PLANKS, BlockTagProvider.NETHER_ALTAR_WOOD),
'M', ModBlocks.GOLD_NETHER_BRICK, 'M', ModBlocks.GOLD_NETHER_BRICK,
'0', ModBlocks.NATURE_ALTAR.defaultBlockState().setValue(BlockNatureAltar.NETHER, true), '0', ModBlocks.NATURE_ALTAR.getDefaultState().with(BlockNatureAltar.NETHER, true),
' ', Matcher.wildcard()); ' ', Matcher.wildcard());
public static final IMultiblock TREE_RITUAL = NaturesAuraAPI.instance().createMultiblock( public static final IMultiblock TREE_RITUAL = NaturesAuraAPI.instance().createMultiblock(
new ResourceLocation(NaturesAura.MOD_ID, "tree_ritual"), new ResourceLocation(NaturesAura.MOD_ID, "tree_ritual"),
new String[][]{ new String[][]{
{" W ", " W W ", " GGG ", " GG GG ", "W G 0 G W", " GG GG ", " GGG ", " W W ", " W "}}, {" W ", " W W ", " GGG ", " GG GG ", "W G 0 G W", " GG GG ", " GGG ", " W W ", " W "}},
'W', new Matcher(ModBlocks.WOOD_STAND.defaultBlockState(), 'W', new Matcher(ModBlocks.WOOD_STAND.getDefaultState(),
(level, start, offset, pos, state, c) -> level != null || state.getBlock() == ModBlocks.WOOD_STAND), (world, start, offset, pos, state, c) -> world != null || state.getBlock() == ModBlocks.WOOD_STAND),
'G', ModBlocks.GOLD_POWDER, 'G', ModBlocks.GOLD_POWDER,
'0', new Matcher(Blocks.OAK_SAPLING.defaultBlockState(), '0', new Matcher(Blocks.OAK_SAPLING.getDefaultState(),
(level, start, offset, pos, state, c) -> { (world, start, offset, pos, state, c) -> {
if (state.getBlock() instanceof SaplingBlock || state.getMaterial() == Material.WOOD) if (state.getBlock() instanceof SaplingBlock || state.getMaterial() == Material.WOOD)
return true; return true;
// try-catch to prevent blocks that need to have been placed crashing here // try-catch to prevent blocks that need to have been placed crashing here
try { try {
ItemStack stack = state.getBlock().getCloneItemStack(level, pos, state); ItemStack stack = state.getBlock().getItem(world, pos, state);
return !stack.isEmpty() && level.getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, null).stream().anyMatch(r -> r.saplingType.test(stack)); return !stack.isEmpty() && world.getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null).stream().anyMatch(r -> r.saplingType.test(stack));
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
@ -76,8 +76,8 @@ public final class Multiblocks {
new ResourceLocation(NaturesAura.MOD_ID, "offering_table"), new ResourceLocation(NaturesAura.MOD_ID, "offering_table"),
new String[][]{ new String[][]{
{" RRRRR ", " R R ", "R RRR R", "R R R R", "R R 0 R R", "R R R R", "R RRR R", " R R ", " RRRRR "}}, {" RRRRR ", " R R ", "R RRR R", "R R R R", "R R 0 R R", "R R R R", "R RRR R", " R R ", " RRRRR "}},
'R', new Matcher(Blocks.POPPY.defaultBlockState(), 'R', new Matcher(Blocks.POPPY.getDefaultState(),
(level, start, offset, pos, state, c) -> BlockTags.SMALL_FLOWERS.contains(state.getBlock())), (world, start, offset, pos, state, c) -> BlockTags.SMALL_FLOWERS.contains(state.getBlock())),
'0', ModBlocks.OFFERING_TABLE, '0', ModBlocks.OFFERING_TABLE,
' ', Matcher.wildcard()); ' ', Matcher.wildcard());
public static final IMultiblock ANIMAL_SPAWNER = NaturesAuraAPI.instance().createMultiblock( public static final IMultiblock ANIMAL_SPAWNER = NaturesAuraAPI.instance().createMultiblock(

View file

@ -1,51 +0,0 @@
package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import java.util.HashSet;
import java.util.Set;
public class BlockEntityAnimalContainer extends BlockEntityImpl implements ITickableBlockEntity {
public BlockEntityAnimalContainer(BlockPos pos, BlockState state) {
super(ModTileEntities.ANIMAL_CONTAINER, pos, state);
}
public int getRadius() {
return this.redstonePower / 2;
}
@Override
public void onRedstonePowerChange(int newPower) {
super.onRedstonePowerChange(newPower);
this.sendToClients();
}
@Override
public void tick() {
if (this.level.isClientSide)
return;
var radius = this.getRadius();
Set<Animal> animalsInRange = new HashSet<>(this.level.getEntitiesOfClass(Animal.class, new AABB(this.worldPosition).inflate(radius - 1)));
var animalsOutRange = this.level.getEntitiesOfClass(Animal.class, new AABB(this.worldPosition).inflate(radius + 1));
for (var animal : animalsOutRange) {
if (animalsInRange.contains(animal))
continue;
var pos = animal.position();
var distance = pos.subtract(this.worldPosition.getX(), pos.y, this.worldPosition.getZ());
distance = distance.normalize().scale(-0.15F);
animal.setDeltaMovement(distance);
if (this.level.random.nextBoolean()) {
var eye = animal.getEyePosition(1).add(animal.getLookAngle());
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) eye.x, (float) eye.y, (float) eye.z, PacketParticles.Type.ANIMAL_CONTAINER));
}
}
}
}

View file

@ -1,7 +0,0 @@
package de.ellpeck.naturesaura.blocks.tiles;
public interface ITickableBlockEntity {
void tick();
}

View file

@ -7,14 +7,14 @@ import javax.annotation.Nonnull;
public class ItemStackHandlerNA extends ItemStackHandler { public class ItemStackHandlerNA extends ItemStackHandler {
private final BlockEntityImpl tile; private final TileEntityImpl tile;
private final boolean sendToClients; private final boolean sendToClients;
public ItemStackHandlerNA(int size) { public ItemStackHandlerNA(int size) {
this(size, null, false); this(size, null, false);
} }
public ItemStackHandlerNA(int size, BlockEntityImpl tile, boolean sendToClients) { public ItemStackHandlerNA(int size, TileEntityImpl tile, boolean sendToClients) {
super(size); super(size);
this.tile = tile; this.tile = tile;
this.sendToClients = sendToClients; this.sendToClients = sendToClients;
@ -24,7 +24,7 @@ public class ItemStackHandlerNA extends ItemStackHandler {
protected void onContentsChanged(int slot) { protected void onContentsChanged(int slot) {
if (this.tile != null) { if (this.tile != null) {
this.tile.markDirty(); this.tile.markDirty();
if (this.sendToClients && !this.tile.getLevel().isClientSide) if (this.sendToClients && !this.tile.getWorld().isRemote)
this.tile.sendToClients(); this.tile.sendToClients();
} }
} }

View file

@ -1,46 +1,45 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
@SuppressWarnings("FieldNamingConvention") @SuppressWarnings("FieldNamingConvention")
public final class ModTileEntities { public final class ModTileEntities {
public static TileEntityType<TileEntityAncientLeaves> ANCIENT_LEAVES;
public static BlockEntityType<BlockEntityAncientLeaves> ANCIENT_LEAVES; public static TileEntityType<TileEntityAnimalGenerator> ANIMAL_GENERATOR;
public static BlockEntityType<BlockEntityAnimalGenerator> ANIMAL_GENERATOR; public static TileEntityType<TileEntityAnimalSpawner> ANIMAL_SPAWNER;
public static BlockEntityType<BlockEntityAnimalSpawner> ANIMAL_SPAWNER; public static TileEntityType<TileEntityAuraDetector> AURA_DETECTOR;
public static BlockEntityType<BlockEntityAuraDetector> AURA_DETECTOR; public static TileEntityType<TileEntityAutoCrafter> AUTO_CRAFTER;
public static BlockEntityType<BlockEntityAutoCrafter> AUTO_CRAFTER; public static TileEntityType<TileEntityChunkLoader> CHUNK_LOADER;
public static BlockEntityType<BlockEntityChunkLoader> CHUNK_LOADER; public static TileEntityType<TileEntityEnderCrate> ENDER_CRATE;
public static BlockEntityType<BlockEntityEnderCrate> ENDER_CRATE; public static TileEntityType<TileEntityEndFlower> END_FLOWER;
public static BlockEntityType<BlockEntityEndFlower> END_FLOWER; public static TileEntityType<TileEntityFieldCreator> FIELD_CREATOR;
public static BlockEntityType<BlockEntityFieldCreator> FIELD_CREATOR; public static TileEntityType<TileEntityFireworkGenerator> FIREWORK_GENERATOR;
public static BlockEntityType<BlockEntityFireworkGenerator> FIREWORK_GENERATOR; public static TileEntityType<TileEntityFlowerGenerator> FLOWER_GENERATOR;
public static BlockEntityType<BlockEntityFlowerGenerator> FLOWER_GENERATOR; public static TileEntityType<TileEntityFurnaceHeater> FURNACE_HEATER;
public static BlockEntityType<BlockEntityFurnaceHeater> FURNACE_HEATER; public static TileEntityType<TileEntityGeneratorLimitRemover> GENERATOR_LIMIT_REMOVER;
public static BlockEntityType<BlockEntityGeneratorLimitRemover> GENERATOR_LIMIT_REMOVER; public static TileEntityType<TileEntityGratedChute> GRATED_CHUTE;
public static BlockEntityType<BlockEntityGratedChute> GRATED_CHUTE; public static TileEntityType<TileEntityHopperUpgrade> HOPPER_UPGRADE;
public static BlockEntityType<BlockEntityHopperUpgrade> HOPPER_UPGRADE; public static TileEntityType<TileEntityMossGenerator> MOSS_GENERATOR;
public static BlockEntityType<BlockEntityMossGenerator> MOSS_GENERATOR; public static TileEntityType<TileEntityNatureAltar> NATURE_ALTAR;
public static BlockEntityType<BlockEntityNatureAltar> NATURE_ALTAR; public static TileEntityType<TileEntityOakGenerator> OAK_GENERATOR;
public static BlockEntityType<BlockEntityOakGenerator> OAK_GENERATOR; public static TileEntityType<TileEntityOfferingTable> OFFERING_TABLE;
public static BlockEntityType<BlockEntityOfferingTable> OFFERING_TABLE; public static TileEntityType<TileEntityPickupStopper> PICKUP_STOPPER;
public static BlockEntityType<BlockEntityPickupStopper> PICKUP_STOPPER; public static TileEntityType<TileEntityPlacer> PLACER;
public static BlockEntityType<BlockEntityPlacer> PLACER; public static TileEntityType<TileEntityPotionGenerator> POTION_GENERATOR;
public static BlockEntityType<BlockEntityPotionGenerator> POTION_GENERATOR; public static TileEntityType<TileEntityPowderPlacer> POWDER_PLACER;
public static BlockEntityType<BlockEntityPowderPlacer> POWDER_PLACER; public static TileEntityType<TileEntityProjectileGenerator> PROJECTILE_GENERATOR;
public static BlockEntityType<BlockEntityProjectileGenerator> PROJECTILE_GENERATOR; public static TileEntityType<TileEntityRFConverter> RF_CONVERTER;
public static BlockEntityType<BlockEntityRFConverter> RF_CONVERTER; public static TileEntityType<TileEntitySpawnLamp> SPAWN_LAMP;
public static BlockEntityType<BlockEntitySpawnLamp> SPAWN_LAMP; public static TileEntityType<TileEntityTimeChanger> TIME_CHANGER;
public static BlockEntityType<BlockEntityTimeChanger> TIME_CHANGER; public static TileEntityType<TileEntityWoodStand> WOOD_STAND;
public static BlockEntityType<BlockEntityWoodStand> WOOD_STAND; public static TileEntityType<TileEntityBlastFurnaceBooster> BLAST_FURNACE_BOOSTER;
public static BlockEntityType<BlockEntityBlastFurnaceBooster> BLAST_FURNACE_BOOSTER; public static TileEntityType<TileEntityAnimalContainer> ANIMAL_CONTAINER;
public static BlockEntityType<BlockEntityAnimalContainer> ANIMAL_CONTAINER; public static TileEntityType<TileEntitySnowCreator> SNOW_CREATOR;
public static BlockEntityType<BlockEntitySnowCreator> SNOW_CREATOR; public static TileEntityType<TileEntityItemDistributor> ITEM_DISTRIBUTOR;
public static BlockEntityType<BlockEntityItemDistributor> ITEM_DISTRIBUTOR; public static TileEntityType<TileEntityAuraBloom> AURA_BLOOM;
public static BlockEntityType<BlockEntityAuraBloom> AURA_BLOOM; public static TileEntityType<TileEntityChorusGenerator> CHORUS_GENERATOR;
public static BlockEntityType<BlockEntityChorusGenerator> CHORUS_GENERATOR; public static TileEntityType<TileEntityAuraTimer> AURA_TIMER;
public static BlockEntityType<BlockEntityAuraTimer> AURA_TIMER; public static TileEntityType<TileEntitySlimeSplitGenerator> SLIME_SPLIT_GENERATOR;
public static BlockEntityType<BlockEntitySlimeSplitGenerator> SLIME_SPLIT_GENERATOR; public static TileEntityType<TileEntitySpring> SPRING;
public static BlockEntityType<BlockEntitySpring> SPRING; public static TileEntityType<TileEntityWeatherChanger> WEATHER_CHANGER;
public static BlockEntityType<BlockEntityWeatherChanger> WEATHER_CHANGER;
} }

View file

@ -3,11 +3,9 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.container.NaturalAuraContainer; import de.ellpeck.naturesaura.api.aura.container.NaturalAuraContainer;
import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.state.BlockState;
public class BlockEntityAncientLeaves extends BlockEntityImpl { public class TileEntityAncientLeaves extends TileEntityImpl {
private final NaturalAuraContainer container = new NaturalAuraContainer(NaturesAuraAPI.TYPE_OVERWORLD, 2000, 500) { private final NaturalAuraContainer container = new NaturalAuraContainer(NaturesAuraAPI.TYPE_OVERWORLD, 2000, 500) {
@Override @Override
@ -19,14 +17,14 @@ public class BlockEntityAncientLeaves extends BlockEntityImpl {
public int drainAura(int amountToDrain, boolean simulate) { public int drainAura(int amountToDrain, boolean simulate) {
int amount = super.drainAura(amountToDrain, simulate); int amount = super.drainAura(amountToDrain, simulate);
if (amount > 0 && !simulate) { if (amount > 0 && !simulate) {
BlockEntityAncientLeaves.this.sendToClients(); TileEntityAncientLeaves.this.sendToClients();
} }
return amount; return amount;
} }
}; };
public BlockEntityAncientLeaves(BlockPos pos, BlockState state) { public TileEntityAncientLeaves() {
super(ModTileEntities.ANCIENT_LEAVES, pos, state); super(ModTileEntities.ANCIENT_LEAVES);
} }
@Override @Override
@ -35,14 +33,14 @@ public class BlockEntityAncientLeaves extends BlockEntityImpl {
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) if (type != SaveType.BLOCK)
this.container.writeNBT(compound); this.container.writeNBT(compound);
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) if (type != SaveType.BLOCK)
this.container.readNBT(compound); this.container.readNBT(compound);

View file

@ -0,0 +1,52 @@
package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.vector.Vector3d;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TileEntityAnimalContainer extends TileEntityImpl implements ITickableTileEntity {
public TileEntityAnimalContainer() {
super(ModTileEntities.ANIMAL_CONTAINER);
}
public int getRadius() {
return this.redstonePower / 2;
}
@Override
public void onRedstonePowerChange(int newPower) {
super.onRedstonePowerChange(newPower);
this.sendToClients();
}
@Override
public void tick() {
if (this.world.isRemote)
return;
int radius = this.getRadius();
Set<AnimalEntity> animalsInRange = new HashSet<>(this.world.getEntitiesWithinAABB(AnimalEntity.class, new AxisAlignedBB(this.pos).grow(radius - 1)));
List<AnimalEntity> animalsOutRange = this.world.getEntitiesWithinAABB(AnimalEntity.class, new AxisAlignedBB(this.pos).grow(radius + 1));
for (AnimalEntity animal : animalsOutRange) {
if (animalsInRange.contains(animal))
continue;
Vector3d pos = animal.getPositionVec();
Vector3d distance = pos.subtract(this.pos.getX(), pos.getY(), this.pos.getZ());
distance = distance.normalize().scale(-0.15F);
animal.setMotion(distance);
if (this.world.rand.nextBoolean()) {
Vector3d eye = animal.getEyePosition(1).add(animal.getLookVec());
PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles((float) eye.getX(), (float) eye.getY(), (float) eye.getZ(), PacketParticles.Type.ANIMAL_CONTAINER));
}
}
}
}

View file

@ -1,23 +1,24 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.core.BlockPos; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.util.math.BlockPos;
public class BlockEntityAnimalGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityAnimalGenerator extends TileEntityImpl implements ITickableTileEntity {
private int timeRemaining; private int timeRemaining;
private int amountToRelease; private int amountToRelease;
public BlockEntityAnimalGenerator(BlockPos pos, BlockState state) { public TileEntityAnimalGenerator() {
super(ModTileEntities.ANIMAL_GENERATOR, pos, state); super(ModTileEntities.ANIMAL_GENERATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.world.isRemote) {
if (this.level.getGameTime() % 10 != 0) if (this.world.getGameTime() % 10 != 0)
return; return;
if (this.timeRemaining <= 0) if (this.timeRemaining <= 0)
return; return;
@ -25,8 +26,8 @@ public class BlockEntityAnimalGenerator extends BlockEntityImpl implements ITick
int remain = this.amountToRelease; int remain = this.amountToRelease;
if (this.canGenerateRightNow(remain)) { if (this.canGenerateRightNow(remain)) {
this.generateAura(remain); this.generateAura(remain);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.ANIMAL_GEN_CREATE)); new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ANIMAL_GEN_CREATE));
} }
this.timeRemaining -= 10; this.timeRemaining -= 10;

View file

@ -9,22 +9,22 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe; import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.core.BlockPos; import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.resources.ResourceLocation; import net.minecraft.item.ItemStack;
import net.minecraft.util.Mth; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.world.entity.Entity; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.world.item.ItemStack; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.phys.AABB; import net.minecraft.util.math.MathHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityAnimalSpawner extends TileEntityImpl implements ITickableTileEntity {
private AnimalSpawnerRecipe currentRecipe; private AnimalSpawnerRecipe currentRecipe;
private double spawnX; private double spawnX;
@ -32,16 +32,16 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
private int time; private int time;
private Entity entityClient; private Entity entityClient;
public BlockEntityAnimalSpawner(BlockPos pos, BlockState state) { public TileEntityAnimalSpawner() {
super(ModTileEntities.ANIMAL_SPAWNER, pos, state); super(ModTileEntities.ANIMAL_SPAWNER);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.world.isRemote) {
if (this.level.getGameTime() % 10 != 0) if (this.world.getGameTime() % 10 != 0)
return; return;
if (!Multiblocks.ANIMAL_SPAWNER.isComplete(this.level, this.worldPosition)) { if (!Multiblocks.ANIMAL_SPAWNER.isComplete(this.world, this.pos)) {
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
this.currentRecipe = null; this.currentRecipe = null;
this.time = 0; this.time = 0;
@ -51,29 +51,29 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
int drain = Mth.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F); int drain = MathHelper.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F);
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, drain); IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, drain);
this.time += 10; this.time += 10;
if (this.time >= this.currentRecipe.time) { if (this.time >= this.currentRecipe.time) {
Entity entity = this.currentRecipe.makeEntity(this.level, new BlockPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ)); Entity entity = this.currentRecipe.makeEntity(this.world, new BlockPos(this.spawnX, this.pos.getY() + 1, this.spawnZ));
this.level.addFreshEntity(entity); this.world.addEntity(entity);
this.currentRecipe = null; this.currentRecipe = null;
this.time = 0; this.time = 0;
this.sendToClients(); this.sendToClients();
} }
} else { } else {
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class,
new AABB(this.worldPosition).inflate(2)); new AxisAlignedBB(this.pos).grow(2));
for (AnimalSpawnerRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null)) { for (AnimalSpawnerRecipe recipe : this.world.getRecipeManager().getRecipes(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null)) {
if (recipe.ingredients.length != items.size()) if (recipe.ingredients.length != items.size())
continue; continue;
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients)); List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients));
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (!item.isAlive() || item.hasPickUpDelay()) if (!item.isAlive() || item.cannotPickup())
break; break;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (stack.isEmpty()) if (stack.isEmpty())
@ -89,20 +89,20 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
continue; continue;
for (ItemEntity item : items) { for (ItemEntity item : items) {
item.remove(Entity.RemovalReason.KILLED); item.remove();
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.ANIMAL_SPAWNER)); new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.ANIMAL_SPAWNER));
} }
this.currentRecipe = recipe; this.currentRecipe = recipe;
this.spawnX = this.worldPosition.getX() + 0.5 + this.level.random.nextFloat() * 4 - 2; this.spawnX = this.pos.getX() + 0.5 + this.world.rand.nextFloat() * 4 - 2;
this.spawnZ = this.worldPosition.getZ() + 0.5 + this.level.random.nextFloat() * 4 - 2; this.spawnZ = this.pos.getZ() + 0.5 + this.world.rand.nextFloat() * 4 - 2;
this.sendToClients(); this.sendToClients();
break; break;
} }
} }
} else { } else {
if (this.level.getGameTime() % 5 != 0) if (this.world.getGameTime() % 5 != 0)
return; return;
if (this.currentRecipe == null) { if (this.currentRecipe == null) {
this.entityClient = null; this.entityClient = null;
@ -110,32 +110,32 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
NaturesAuraAPI.instance().spawnParticleStream( NaturesAuraAPI.instance().spawnParticleStream(
this.worldPosition.getX() + (float) this.level.random.nextGaussian() * 5F, this.pos.getX() + (float) this.world.rand.nextGaussian() * 5F,
this.worldPosition.getY() + 1 + this.level.random.nextFloat() * 5F, this.pos.getY() + 1 + this.world.rand.nextFloat() * 5F,
this.worldPosition.getZ() + (float) this.level.random.nextGaussian() * 5F, this.pos.getZ() + (float) this.world.rand.nextGaussian() * 5F,
this.worldPosition.getX() + this.level.random.nextFloat(), this.pos.getX() + this.world.rand.nextFloat(),
this.worldPosition.getY() + this.level.random.nextFloat(), this.pos.getY() + this.world.rand.nextFloat(),
this.worldPosition.getZ() + this.level.random.nextFloat(), this.pos.getZ() + this.world.rand.nextFloat(),
this.level.random.nextFloat() * 0.07F + 0.07F, this.world.rand.nextFloat() * 0.07F + 0.07F,
IAuraType.forLevel(this.level).getColor(), IAuraType.forWorld(this.world).getColor(),
this.level.random.nextFloat() + 0.5F); this.world.rand.nextFloat() + 0.5F);
if (this.entityClient == null) { if (this.entityClient == null) {
this.entityClient = this.currentRecipe.makeEntity(this.level, BlockPos.ZERO); this.entityClient = this.currentRecipe.makeEntity(this.world, BlockPos.ZERO);
this.entityClient.setPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ); this.entityClient.setPosition(this.spawnX, this.pos.getY() + 1, this.spawnZ);
} }
AABB bounds = this.entityClient.getBoundingBox(); AxisAlignedBB bounds = this.entityClient.getBoundingBox();
for (int i = this.level.random.nextInt(5) + 5; i >= 0; i--) for (int i = this.world.rand.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
bounds.minX + this.level.random.nextFloat() * (bounds.maxX - bounds.minX), bounds.minX + this.world.rand.nextFloat() * (bounds.maxX - bounds.minX),
bounds.minY + this.level.random.nextFloat() * (bounds.maxY - bounds.minY), bounds.minY + this.world.rand.nextFloat() * (bounds.maxY - bounds.minY),
bounds.minZ + this.level.random.nextFloat() * (bounds.maxZ - bounds.minZ), bounds.minZ + this.world.rand.nextFloat() * (bounds.maxZ - bounds.minZ),
0F, 0F, 0F, 0x2fd8d3, 2F, 60, 0F, false, true); 0F, 0F, 0F, 0x2fd8d3, 2F, 60, 0F, false, true);
} }
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
@ -148,13 +148,13 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
if (this.hasLevel()) { if (this.hasWorld()) {
ResourceLocation name = new ResourceLocation(compound.getString("recipe")); ResourceLocation name = new ResourceLocation(compound.getString("recipe"));
this.currentRecipe = (AnimalSpawnerRecipe) this.level.getRecipeManager().byKey(name).orElse(null); this.currentRecipe = (AnimalSpawnerRecipe) this.world.getRecipeManager().getRecipe(name).orElse(null);
} }
this.spawnX = compound.getDouble("spawn_x"); this.spawnX = compound.getDouble("spawn_x");
this.spawnZ = compound.getDouble("spawn_z"); this.spawnZ = compound.getDouble("spawn_z");

View file

@ -1,40 +1,40 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.BlockEntityType; import net.minecraft.tileentity.TileEntityType;
public class BlockEntityAuraBloom extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityAuraBloom extends TileEntityImpl implements ITickableTileEntity {
public boolean justGenerated; public boolean justGenerated;
public BlockEntityAuraBloom() { public TileEntityAuraBloom() {
this(ModTileEntities.AURA_BLOOM); this(ModTileEntities.AURA_BLOOM);
} }
protected BlockEntityAuraBloom(BlockEntityType<BlockEntityAuraBloom> type) { protected TileEntityAuraBloom(TileEntityType<TileEntityAuraBloom> type) {
super(type); super(type);
} }
// Doing this in validate() creates a loading deadlock for some reason... // Doing this in validate() creates a loading deadlock for some reason...
@Override @Override
public void tick() { public void tick() {
if (this.level.isClientSide || !this.justGenerated) if (this.world.isRemote || !this.justGenerated)
return; return;
this.generateAura(150000); this.generateAura(150000);
this.justGenerated = false; this.justGenerated = false;
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type == SaveType.TILE) if (type == SaveType.TILE)
compound.putBoolean("just_generated", this.justGenerated); compound.putBoolean("just_generated", this.justGenerated);
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type == SaveType.TILE) if (type == SaveType.TILE)
this.justGenerated = compound.getBoolean("just_generated"); this.justGenerated = compound.getBoolean("just_generated");

View file

@ -1,25 +1,25 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
public class BlockEntityAuraDetector extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityAuraDetector extends TileEntityImpl implements ITickableTileEntity {
public int redstonePower; public int redstonePower;
public BlockEntityAuraDetector() { public TileEntityAuraDetector() {
super(ModTileEntities.AURA_DETECTOR); super(ModTileEntities.AURA_DETECTOR);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) { if (!this.world.isRemote && this.world.getGameTime() % 20 == 0) {
int totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 25); int totalAmount = IAuraChunk.triangulateAuraInArea(this.world, this.pos, 25);
int power = Mth.clamp(Mth.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15); int power = MathHelper.clamp(MathHelper.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15);
if (this.redstonePower != power) { if (this.redstonePower != power) {
this.redstonePower = power; this.redstonePower = power;
this.level.updateComparatorOutputLevel(this.worldPosition, this.getBlockState().getBlock()); this.world.updateComparatorOutputLevel(this.pos, this.getBlockState().getBlock());
} }
} }
} }

View file

@ -9,14 +9,14 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import java.util.Map; import java.util.Map;
public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityAuraTimer extends TileEntityImpl implements ITickableTileEntity {
private static final Map<IAuraType, Integer> TIMES = ImmutableMap.<IAuraType, Integer>builder() private static final Map<IAuraType, Integer> TIMES = ImmutableMap.<IAuraType, Integer>builder()
.put(NaturesAuraAPI.TYPE_OVERWORLD, 20) .put(NaturesAuraAPI.TYPE_OVERWORLD, 20)
@ -30,7 +30,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
}; };
private int timer; private int timer;
public BlockEntityAuraTimer() { public TileEntityAuraTimer() {
super(ModTileEntities.AURA_TIMER); super(ModTileEntities.AURA_TIMER);
} }
@ -39,7 +39,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
if (this.redstonePower <= 0 && newPower > 0) { if (this.redstonePower <= 0 && newPower > 0) {
this.timer = 0; this.timer = 0;
int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor(); int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor();
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.TIMER_RESET, color)); PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.TIMER_RESET, color));
this.sendToClients(); this.sendToClients();
} }
super.onRedstonePowerChange(newPower); super.onRedstonePowerChange(newPower);
@ -53,14 +53,14 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
return; return;
} }
if (this.level.isClientSide) { if (this.world.isRemote) {
if (this.level.getGameTime() % 8 == 0) { if (this.world.getGameTime() % 8 == 0) {
int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor(); int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor();
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
this.worldPosition.getX() + 1 / 16F + this.level.rand.nextFloat() * 14 / 16F, this.pos.getX() + 1 / 16F + this.world.rand.nextFloat() * 14 / 16F,
this.worldPosition.getY() + 1 / 16F + this.level.rand.nextFloat() * 14 / 16F, this.pos.getY() + 1 / 16F + this.world.rand.nextFloat() * 14 / 16F,
this.worldPosition.getZ() + 1 / 16F + this.level.rand.nextFloat() * 14 / 16F, this.pos.getZ() + 1 / 16F + this.world.rand.nextFloat() * 14 / 16F,
0, 0, 0, color, 1, 80 + this.level.rand.nextInt(50), 0, false, true); 0, 0, 0, color, 1, 80 + this.world.rand.nextInt(50), 0, false, true);
} }
return; return;
} }
@ -70,11 +70,11 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
this.timer = 0; this.timer = 0;
BlockState state = this.getBlockState(); BlockState state = this.getBlockState();
this.level.setBlockState(this.worldPosition, state.with(BlockStateProperties.POWERED, true), 1); this.world.setBlockState(this.pos, state.with(BlockStateProperties.POWERED, true), 1);
this.level.getPendingBlockTicks().scheduleTick(this.worldPosition, state.getBlock(), 4); this.world.getPendingBlockTicks().scheduleTick(this.pos, state.getBlock(), 4);
int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor(); int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor();
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.TIMER_RESET, color)); PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.TIMER_RESET, color));
} }
if (this.timer % 2 == 0) if (this.timer % 2 == 0)
this.sendToClients(); this.sendToClients();
@ -104,7 +104,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
compound.put("items", this.itemHandler.serializeNBT()); compound.put("items", this.itemHandler.serializeNBT());
@ -113,7 +113,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
this.itemHandler.deserializeNBT(compound.getCompound("items")); this.itemHandler.deserializeNBT(compound.getCompound("items"));

View file

@ -6,13 +6,13 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory; import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType; import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.EntityPredicates; import net.minecraft.util.EntityPredicates;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
@ -21,30 +21,30 @@ import net.minecraft.util.math.BlockPos;
import java.util.List; import java.util.List;
public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityAutoCrafter extends TileEntityImpl implements ITickableTileEntity {
public final CraftingInventory crafting = new CraftingInventory(new Container(null, 0) { public final CraftingInventory crafting = new CraftingInventory(new Container(null, 0) {
@Override @Override
public boolean canInteractWith(Player playerIn) { public boolean canInteractWith(PlayerEntity playerIn) {
return false; return false;
} }
}, 3, 3); }, 3, 3);
public BlockEntityAutoCrafter() { public TileEntityAutoCrafter() {
super(ModTileEntities.AUTO_CRAFTER); super(ModTileEntities.AUTO_CRAFTER);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.world.isRemote) {
if (this.level.getGameTime() % 60 != 0) if (this.world.getGameTime() % 60 != 0)
return; return;
if (!Multiblocks.AUTO_CRAFTER.isComplete(this.level, this.worldPosition)) if (!Multiblocks.AUTO_CRAFTER.isComplete(this.world, this.pos))
return; return;
this.crafting.clear(); this.crafting.clear();
BlockState state = this.level.getBlockState(this.worldPosition); BlockState state = this.world.getBlockState(this.pos);
Direction facing = state.get(BlockAutoCrafter.FACING); Direction facing = state.get(BlockAutoCrafter.FACING);
BlockPos middlePos = this.worldPosition.up(); BlockPos middlePos = this.pos.up();
BlockPos topPos = middlePos.offset(facing, 2); BlockPos topPos = middlePos.offset(facing, 2);
BlockPos bottomPos = middlePos.offset(facing.getOpposite(), 2); BlockPos bottomPos = middlePos.offset(facing.getOpposite(), 2);
BlockPos[] poses = new BlockPos[]{ BlockPos[] poses = new BlockPos[]{
@ -61,7 +61,7 @@ public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickable
ItemEntity[] items = new ItemEntity[9]; ItemEntity[] items = new ItemEntity[9];
for (int i = 0; i < poses.length; i++) { for (int i = 0; i < poses.length; i++) {
List<ItemEntity> entities = this.level.getEntitiesWithinAABB( List<ItemEntity> entities = this.world.getEntitiesWithinAABB(
ItemEntity.class, new AxisAlignedBB(poses[i]).grow(0.25), EntityPredicates.IS_ALIVE); ItemEntity.class, new AxisAlignedBB(poses[i]).grow(0.25), EntityPredicates.IS_ALIVE);
if (entities.size() > 1) if (entities.size() > 1)
return; return;
@ -77,17 +77,17 @@ public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickable
this.crafting.setInventorySlotContents(i, stack.copy()); this.crafting.setInventorySlotContents(i, stack.copy());
} }
IRecipe recipe = this.level.getRecipeManager().getRecipe(IRecipeType.CRAFTING, this.crafting, this.level).orElse(null); IRecipe recipe = this.world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, this.crafting, this.world).orElse(null);
if (recipe == null) if (recipe == null)
return; return;
ItemStack result = recipe.getCraftingResult(this.crafting); ItemStack result = recipe.getCraftingResult(this.crafting);
if (result.isEmpty()) if (result.isEmpty())
return; return;
ItemEntity resultItem = new ItemEntity(this.level, ItemEntity resultItem = new ItemEntity(this.world,
this.worldPosition.getX() + 0.5F, this.worldPosition.getY() - 0.35F, this.worldPosition.getZ() + 0.5F, result.copy()); this.pos.getX() + 0.5F, this.pos.getY() - 0.35F, this.pos.getZ() + 0.5F, result.copy());
resultItem.setMotion(0, 0, 0); resultItem.setMotion(0, 0, 0);
this.level.addEntity(resultItem); this.world.addEntity(resultItem);
NonNullList<ItemStack> remainingItems = recipe.getRemainingItems(this.crafting); NonNullList<ItemStack> remainingItems = recipe.getRemainingItems(this.crafting);
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
@ -104,12 +104,12 @@ public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickable
ItemStack remain = remainingItems.get(i); ItemStack remain = remainingItems.get(i);
if (!remain.isEmpty()) { if (!remain.isEmpty()) {
ItemEntity remItem = new ItemEntity(this.level, item.getPosX(), item.getPosY(), item.getPosZ(), remain.copy()); ItemEntity remItem = new ItemEntity(this.world, item.getPosX(), item.getPosY(), item.getPosZ(), remain.copy());
remItem.setMotion(0, 0, 0); remItem.setMotion(0, 0, 0);
this.level.addEntity(remItem); this.world.addEntity(remItem);
} }
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.ANIMAL_SPAWNER)); new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.ANIMAL_SPAWNER));
} }
} }

View file

@ -6,9 +6,9 @@ import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.tileentity.BlastFurnaceBlockEntity; import net.minecraft.tileentity.BlastFurnaceTileEntity;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.IIntArray; import net.minecraft.util.IIntArray;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -19,35 +19,35 @@ import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityBlastFurnaceBooster extends TileEntityImpl implements ITickableTileEntity {
public BlockEntityBlastFurnaceBooster() { public TileEntityBlastFurnaceBooster() {
super(ModTileEntities.BLAST_FURNACE_BOOSTER); super(ModTileEntities.BLAST_FURNACE_BOOSTER);
} }
@Override @Override
public void tick() { public void tick() {
if (this.level.isClientSide) if (this.world.isRemote)
return; return;
BlockEntity below = this.level.getBlockEntity(this.worldPosition.down()); TileEntity below = this.world.getTileEntity(this.pos.down());
if (!(below instanceof BlastFurnaceBlockEntity)) if (!(below instanceof BlastFurnaceTileEntity))
return; return;
BlastFurnaceBlockEntity tile = (BlastFurnaceBlockEntity) below; BlastFurnaceTileEntity tile = (BlastFurnaceTileEntity) below;
IRecipe<?> recipe = this.level.getRecipeManager().getRecipe(BlockEntityFurnaceHeater.getRecipeType(tile), tile, this.level).orElse(null); IRecipe<?> recipe = this.world.getRecipeManager().getRecipe(TileEntityFurnaceHeater.getRecipeType(tile), tile, this.world).orElse(null);
if (recipe == null) if (recipe == null)
return; return;
if (!this.isApplicable(recipe.getIngredients())) if (!this.isApplicable(recipe.getIngredients()))
return; return;
IIntArray data = BlockEntityFurnaceHeater.getFurnaceData(tile); IIntArray data = TileEntityFurnaceHeater.getFurnaceData(tile);
int doneDiff = data.get(3) - data.get(2); int doneDiff = data.get(3) - data.get(2);
if (doneDiff > 1) if (doneDiff > 1)
return; return;
if (this.level.rand.nextFloat() > 0.45F) { if (this.world.rand.nextFloat() > 0.45F) {
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.BLAST_FURNACE_BOOSTER, 0)); new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.BLAST_FURNACE_BOOSTER, 0));
return; return;
} }
@ -62,11 +62,11 @@ public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements I
output.grow(1); output.grow(1);
} }
BlockPos pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 30, this.worldPosition); BlockPos pos = IAuraChunk.getHighestSpot(this.world, this.pos, 30, this.pos);
IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, 6500); IAuraChunk.getAuraChunk(this.world, pos).drainAura(pos, 6500);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.BLAST_FURNACE_BOOSTER, 1)); new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.BLAST_FURNACE_BOOSTER, 1));
} }
private boolean isApplicable(List<Ingredient> ingredients) { private boolean isApplicable(List<Ingredient> ingredients) {
@ -81,8 +81,8 @@ public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements I
@Override @Override
public IItemHandlerModifiable getItemHandler() { public IItemHandlerModifiable getItemHandler() {
BlockEntity below = this.level.getBlockEntity(this.worldPosition.down()); TileEntity below = this.world.getTileEntity(this.pos.down());
if (!(below instanceof BlastFurnaceBlockEntity)) if (!(below instanceof BlastFurnaceTileEntity))
return null; return null;
IItemHandler handler = below.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null); IItemHandler handler = below.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
if (handler == null) if (handler == null)

View file

@ -5,10 +5,10 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
@ -19,32 +19,32 @@ import java.util.ArrayList;
import java.util.Deque; import java.util.Deque;
import java.util.List; import java.util.List;
public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityChorusGenerator extends TileEntityImpl implements ITickableTileEntity {
private final Deque<BlockPos> currentlyBreaking = new ArrayDeque<>(); private final Deque<BlockPos> currentlyBreaking = new ArrayDeque<>();
private int auraPerBlock; private int auraPerBlock;
public BlockEntityChorusGenerator() { public TileEntityChorusGenerator() {
super(ModTileEntities.CHORUS_GENERATOR); super(ModTileEntities.CHORUS_GENERATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (this.level.isClientSide) if (this.world.isRemote)
return; return;
if (this.level.getGameTime() % 5 != 0) if (this.world.getGameTime() % 5 != 0)
return; return;
if (this.currentlyBreaking.isEmpty()) if (this.currentlyBreaking.isEmpty())
return; return;
BlockPos pos = this.currentlyBreaking.removeLast(); BlockPos pos = this.currentlyBreaking.removeLast();
BlockState state = this.level.getBlockState(pos); BlockState state = this.world.getBlockState(pos);
if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) { if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) {
this.currentlyBreaking.clear(); this.currentlyBreaking.clear();
return; return;
} }
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.CHORUS_GENERATOR, pos.getX(), pos.getY(), pos.getZ())); PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.CHORUS_GENERATOR, pos.getX(), pos.getY(), pos.getZ()));
this.level.removeBlock(pos, false); this.world.removeBlock(pos, false);
this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, this.world.playSound(null, this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5,
SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 0.5F, 1F); SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 0.5F, 1F);
this.generateAura(this.auraPerBlock); this.generateAura(this.auraPerBlock);
} }
@ -57,11 +57,11 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
for (int x = -range; x <= range; x++) { for (int x = -range; x <= range; x++) {
for (int y = -range; y <= range; y++) { for (int y = -range; y <= range; y++) {
for (int z = -range; z <= range; z++) { for (int z = -range; z <= range; z++) {
BlockPos offset = this.worldPosition.add(x, y, z); BlockPos offset = this.pos.add(x, y, z);
BlockState below = this.level.getBlockState(offset.down()); BlockState below = this.world.getBlockState(offset.down());
if (below.getBlock() != Blocks.END_STONE) if (below.getBlock() != Blocks.END_STONE)
continue; continue;
BlockState state = this.level.getBlockState(offset); BlockState state = this.world.getBlockState(offset);
if (state.getBlock() != Blocks.CHORUS_PLANT) if (state.getBlock() != Blocks.CHORUS_PLANT)
continue; continue;
@ -90,7 +90,7 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
BlockPos offset = pos.offset(dir); BlockPos offset = pos.offset(dir);
if (blocks.contains(offset)) if (blocks.contains(offset))
continue; continue;
BlockState state = this.level.getBlockState(offset); BlockState state = this.world.getBlockState(offset);
if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER)
continue; continue;
blocks.add(offset); blocks.add(offset);
@ -99,7 +99,7 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
ListNBT list = new ListNBT(); ListNBT list = new ListNBT();
@ -111,7 +111,7 @@ public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITick
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
this.currentlyBreaking.clear(); this.currentlyBreaking.clear();

View file

@ -2,24 +2,24 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTileEntity {
private final List<ChunkPos> forcedChunks = new ArrayList<>(); private final List<ChunkPos> forcedChunks = new ArrayList<>();
private boolean firstTick = true; private boolean firstTick = true;
public BlockEntityChunkLoader() { public TileEntityChunkLoader() {
super(ModTileEntities.CHUNK_LOADER); super(ModTileEntities.CHUNK_LOADER);
} }
@ -32,7 +32,7 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
@Override @Override
public void onRedstonePowerChange(int newPower) { public void onRedstonePowerChange(int newPower) {
super.onRedstonePowerChange(newPower); super.onRedstonePowerChange(newPower);
if (!this.level.isClientSide) { if (!this.world.isRemote) {
this.loadChunks(false); this.loadChunks(false);
this.sendToClients(); this.sendToClients();
} }
@ -43,19 +43,19 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
} }
private void loadChunks(boolean unload) { private void loadChunks(boolean unload) {
if (this.level.isClientSide || !ModConfig.instance.chunkLoader.get()) if (this.world.isRemote || !ModConfig.instance.chunkLoader.get())
return; return;
ServerLevel level = (ServerLevel) this.level; ServerWorld world = (ServerWorld) this.world;
List<ChunkPos> shouldBeForced = new ArrayList<>(); List<ChunkPos> shouldBeForced = new ArrayList<>();
if (!unload) { if (!unload) {
int range = this.range(); int range = this.range();
if (range > 0) { if (range > 0) {
for (int x = (this.worldPosition.getX() - range) >> 4; x <= (this.worldPosition.getX() + range) >> 4; x++) { for (int x = (this.pos.getX() - range) >> 4; x <= (this.pos.getX() + range) >> 4; x++) {
for (int z = (this.worldPosition.getZ() - range) >> 4; z <= (this.worldPosition.getZ() + range) >> 4; z++) { for (int z = (this.pos.getZ() - range) >> 4; z <= (this.pos.getZ() + range) >> 4; z++) {
ChunkPos pos = new ChunkPos(x, z); ChunkPos pos = new ChunkPos(x, z);
// Only force chunks that we're already forcing or that nobody else is forcing // Only force chunks that we're already forcing or that nobody else is forcing
if (this.forcedChunks.contains(pos) || !level.getForcedChunks().contains(pos.asLong())) if (this.forcedChunks.contains(pos) || !world.getForcedChunks().contains(pos.asLong()))
shouldBeForced.add(pos); shouldBeForced.add(pos);
} }
} }
@ -65,20 +65,20 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
// Unforce all of the chunks that shouldn't be forced anymore // Unforce all of the chunks that shouldn't be forced anymore
for (ChunkPos pos : this.forcedChunks) { for (ChunkPos pos : this.forcedChunks) {
if (!shouldBeForced.contains(pos)) if (!shouldBeForced.contains(pos))
level.forceChunk(pos.x, pos.z, false); world.forceChunk(pos.x, pos.z, false);
} }
this.forcedChunks.clear(); this.forcedChunks.clear();
// Force all chunks that should be forced // Force all chunks that should be forced
for (ChunkPos pos : shouldBeForced) { for (ChunkPos pos : shouldBeForced) {
level.forceChunk(pos.x, pos.z, true); world.forceChunk(pos.x, pos.z, true);
this.forcedChunks.add(pos); this.forcedChunks.add(pos);
} }
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide && ModConfig.instance.chunkLoader.get()) { if (!this.world.isRemote && ModConfig.instance.chunkLoader.get()) {
// defer loading chunks on load to here since, otherwise, deadlocks happen oof // defer loading chunks on load to here since, otherwise, deadlocks happen oof
// since forced chunks are saved to disk by the game, this is only necessary for when the chunk loader config changes // since forced chunks are saved to disk by the game, this is only necessary for when the chunk loader config changes
if (this.firstTick) { if (this.firstTick) {
@ -86,25 +86,25 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
this.firstTick = false; this.firstTick = false;
} }
if (this.level.getGameTime() % 20 != 0) if (this.world.getGameTime() % 20 != 0)
return; return;
int toUse = Mth.ceil(this.range() / 2F); int toUse = MathHelper.ceil(this.range() / 2F);
if (toUse > 0) { if (toUse > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, toUse); IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, toUse);
} }
} }
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type == SaveType.TILE) if (type == SaveType.TILE)
compound.putLongArray("forced_chunks", this.forcedChunks.stream().map(ChunkPos::asLong).collect(Collectors.toList())); compound.putLongArray("forced_chunks", this.forcedChunks.stream().map(ChunkPos::asLong).collect(Collectors.toList()));
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type == SaveType.TILE) { if (type == SaveType.TILE) {

View file

@ -10,15 +10,15 @@ import net.minecraft.block.Blocks;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.EntityPredicates; import net.minecraft.util.EntityPredicates;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.List; import java.util.List;
public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityEndFlower extends TileEntityImpl implements ITickableTileEntity {
private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) { private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) {
{ {
@ -34,7 +34,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
public int drainAura(int amountToDrain, boolean simulate) { public int drainAura(int amountToDrain, boolean simulate) {
int amount = super.drainAura(amountToDrain, simulate); int amount = super.drainAura(amountToDrain, simulate);
if (amount > 0 && !simulate) if (amount > 0 && !simulate)
BlockEntityEndFlower.this.sendToClients(); TileEntityEndFlower.this.sendToClients();
return amount; return amount;
} }
@ -46,19 +46,19 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
public boolean isDrainMode; public boolean isDrainMode;
public BlockEntityEndFlower() { public TileEntityEndFlower() {
super(ModTileEntities.END_FLOWER); super(ModTileEntities.END_FLOWER);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.world.isRemote) {
if (this.level.getGameTime() % 10 != 0) if (this.world.getGameTime() % 10 != 0)
return; return;
if (!this.isDrainMode) { if (!this.isDrainMode) {
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class,
new AxisAlignedBB(this.worldPosition).grow(1), EntityPredicates.IS_ALIVE); new AxisAlignedBB(this.pos).grow(1), EntityPredicates.IS_ALIVE);
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (item.cannotPickup()) if (item.cannotPickup())
continue; continue;
@ -71,7 +71,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
this.isDrainMode = true; this.isDrainMode = true;
item.remove(); item.remove();
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.END_FLOWER_CONSUME, this.container.getAuraColor())); new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.END_FLOWER_CONSUME, this.container.getAuraColor()));
break; break;
} }
@ -81,21 +81,21 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
this.generateAura(toDrain); this.generateAura(toDrain);
if (this.container.getStoredAura() <= 0) { if (this.container.getStoredAura() <= 0) {
this.level.setBlockState(this.worldPosition, Blocks.DEAD_BUSH.getDefaultState()); this.world.setBlockState(this.pos, Blocks.DEAD_BUSH.getDefaultState());
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.END_FLOWER_DECAY, this.container.getAuraColor())); new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.END_FLOWER_DECAY, this.container.getAuraColor()));
} }
} }
} else { } else {
if (this.isDrainMode && this.level.getGameTime() % 5 == 0) if (this.isDrainMode && this.world.getGameTime() % 5 == 0)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.pos.getX() + 0.25F + this.world.rand.nextFloat() * 0.5F,
this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.pos.getY() + 0.25F + this.world.rand.nextFloat() * 0.5F,
this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.pos.getZ() + 0.25F + this.world.rand.nextFloat() * 0.5F,
this.level.rand.nextGaussian() * 0.05F, this.world.rand.nextGaussian() * 0.05F,
this.level.rand.nextFloat() * 0.1F, this.world.rand.nextFloat() * 0.1F,
this.level.rand.nextGaussian() * 0.05F, this.world.rand.nextGaussian() * 0.05F,
this.container.getAuraColor(), this.level.rand.nextFloat() * 2F + 1F, 50, 0F, false, true); this.container.getAuraColor(), this.world.rand.nextFloat() * 2F + 1F, 50, 0F, false, true);
} }
} }
@ -105,7 +105,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
this.container.writeNBT(compound); this.container.writeNBT(compound);
@ -114,7 +114,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
this.container.readNBT(compound); this.container.readNBT(compound);

View file

@ -2,16 +2,16 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.IWorldData;
import de.ellpeck.naturesaura.blocks.BlockEnderCrate; import de.ellpeck.naturesaura.blocks.BlockEnderCrate;
import de.ellpeck.naturesaura.gui.ContainerEnderCrate; import de.ellpeck.naturesaura.gui.ContainerEnderCrate;
import de.ellpeck.naturesaura.gui.ModContainers; import de.ellpeck.naturesaura.gui.ModContainers;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@ -21,7 +21,7 @@ import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedContainerProvider { public class TileEntityEnderCrate extends TileEntityImpl implements INamedContainerProvider {
public String name; public String name;
private final IItemHandlerModifiable wrappedEnderStorage = new IItemHandlerModifiable() { private final IItemHandlerModifiable wrappedEnderStorage = new IItemHandlerModifiable() {
@ -46,7 +46,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
ItemStack remain = this.getStorage().insertItem(slot, stack, simulate); ItemStack remain = this.getStorage().insertItem(slot, stack, simulate);
if (!simulate) if (!simulate)
BlockEntityEnderCrate.this.drainAura((stack.getCount() - remain.getCount()) * 20); TileEntityEnderCrate.this.drainAura((stack.getCount() - remain.getCount()) * 20);
return remain; return remain;
} }
@ -55,7 +55,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
public ItemStack extractItem(int slot, int amount, boolean simulate) { public ItemStack extractItem(int slot, int amount, boolean simulate) {
ItemStack extracted = this.getStorage().extractItem(slot, amount, simulate); ItemStack extracted = this.getStorage().extractItem(slot, amount, simulate);
if (!simulate) if (!simulate)
BlockEntityEnderCrate.this.drainAura(extracted.getCount() * 20); TileEntityEnderCrate.this.drainAura(extracted.getCount() * 20);
return extracted; return extracted;
} }
@ -70,11 +70,11 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
} }
private IItemHandlerModifiable getStorage() { private IItemHandlerModifiable getStorage() {
return ILevelData.getOverworldData(BlockEntityEnderCrate.this.level).getEnderStorage(BlockEntityEnderCrate.this.name); return IWorldData.getOverworldData(TileEntityEnderCrate.this.world).getEnderStorage(TileEntityEnderCrate.this.name);
} }
}; };
public BlockEntityEnderCrate() { public TileEntityEnderCrate() {
super(ModTileEntities.ENDER_CRATE); super(ModTileEntities.ENDER_CRATE);
} }
@ -97,7 +97,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
public void modifyDrop(ItemStack regularItem) { public void modifyDrop(ItemStack regularItem) {
if (this.name != null) { if (this.name != null) {
if (!regularItem.hasTag()) if (!regularItem.hasTag())
regularItem.setTag(new CompoundTag()); regularItem.setTag(new CompoundNBT());
regularItem.getTag().putString(NaturesAura.MOD_ID + ":ender_name", this.name); regularItem.getTag().putString(NaturesAura.MOD_ID + ":ender_name", this.name);
} }
} }
@ -105,7 +105,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
@Override @Override
public void loadDataOnPlace(ItemStack stack) { public void loadDataOnPlace(ItemStack stack) {
super.loadDataOnPlace(stack); super.loadDataOnPlace(stack);
if (!this.level.isClientSide) { if (!this.world.isRemote) {
String name = BlockEnderCrate.getEnderName(stack); String name = BlockEnderCrate.getEnderName(stack);
if (name != null && !name.isEmpty()) if (name != null && !name.isEmpty())
this.name = name; this.name = name;
@ -113,7 +113,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (this.name != null) if (this.name != null)
@ -122,7 +122,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (compound.contains("name")) if (compound.contains("name"))
@ -132,8 +132,8 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
public void drainAura(int amount) { public void drainAura(int amount) {
if (amount > 0) { if (amount > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, amount); IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, amount);
} }
} }
@ -144,7 +144,7 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements INamedCont
@Nullable @Nullable
@Override @Override
public Container createMenu(int window, PlayerInventory inv, Player player) { public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) {
return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler()); return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler());
} }
} }

View file

@ -13,44 +13,44 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.loot.LootContext; import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootParameters; import net.minecraft.loot.LootParameters;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.event.world.BlockEvent;
import java.util.List; import java.util.List;
public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityFieldCreator extends TileEntityImpl implements ITickableTileEntity {
public BlockPos connectionOffset; public BlockPos connectionOffset;
public boolean isMain; public boolean isMain;
public boolean isCharged; public boolean isCharged;
private int chargeTimer; private int chargeTimer;
public BlockEntityFieldCreator() { public TileEntityFieldCreator() {
super(ModTileEntities.FIELD_CREATOR); super(ModTileEntities.FIELD_CREATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (this.level.isClientSide || this.level.getGameTime() % 10 != 0) if (this.world.isRemote || this.world.getGameTime() % 10 != 0)
return; return;
BlockPos connectedPos = this.getConnectedPos(); BlockPos connectedPos = this.getConnectedPos();
if (connectedPos == null || !this.level.isBlockLoaded(connectedPos)) if (connectedPos == null || !this.world.isBlockLoaded(connectedPos))
return; return;
BlockEntity other = this.level.getBlockEntity(connectedPos); TileEntity other = this.world.getTileEntity(connectedPos);
if (!this.isCloseEnough(connectedPos) if (!this.isCloseEnough(connectedPos)
|| !(other instanceof BlockEntityFieldCreator) || !(other instanceof TileEntityFieldCreator)
|| !this.worldPosition.equals(((BlockEntityFieldCreator) other).getConnectedPos())) { || !this.pos.equals(((TileEntityFieldCreator) other).getConnectedPos())) {
this.connectionOffset = null; this.connectionOffset = null;
this.chargeTimer = 0; this.chargeTimer = 0;
this.isCharged = false; this.isCharged = false;
@ -62,7 +62,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
if (!this.isMain) if (!this.isMain)
return; return;
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) other; TileEntityFieldCreator creator = (TileEntityFieldCreator) other;
if (this.redstonePower <= 0 && creator.redstonePower <= 0) { if (this.redstonePower <= 0 && creator.redstonePower <= 0) {
this.chargeTimer = 0; this.chargeTimer = 0;
if (this.isCharged) { if (this.isCharged) {
@ -74,8 +74,8 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
return; return;
} }
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 32, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 32, this.pos);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot); IAuraChunk chunk = IAuraChunk.getAuraChunk(this.world, spot);
if (!this.isCharged) { if (!this.isCharged) {
this.chargeTimer += 10; this.chargeTimer += 10;
@ -91,41 +91,41 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
chunk.drainAura(spot, 300); chunk.drainAura(spot, 300);
this.sendParticles(); this.sendParticles();
} else { } else {
if (this.level.getGameTime() % 40 == 0) if (this.world.getGameTime() % 40 == 0)
chunk.drainAura(spot, 20); chunk.drainAura(spot, 20);
ItemStack tool = this.getToolUsed(creator); ItemStack tool = this.getToolUsed(creator);
Vector3d dist = new Vector3d( Vector3d dist = new Vector3d(
this.worldPosition.getX() - connectedPos.getX(), this.pos.getX() - connectedPos.getX(),
this.worldPosition.getY() - connectedPos.getY(), this.pos.getY() - connectedPos.getY(),
this.worldPosition.getZ() - connectedPos.getZ() this.pos.getZ() - connectedPos.getZ()
); );
double length = dist.length(); double length = dist.length();
Vector3d normal = new Vector3d(dist.x / length, dist.y / length, dist.z / length); Vector3d normal = new Vector3d(dist.x / length, dist.y / length, dist.z / length);
for (float i = Mth.floor(length); i > 0; i -= 0.5F) { for (float i = MathHelper.floor(length); i > 0; i -= 0.5F) {
Vector3d scaled = normal.scale(i); Vector3d scaled = normal.scale(i);
BlockPos pos = connectedPos.add( BlockPos pos = connectedPos.add(
Mth.floor(scaled.x + 0.5F), MathHelper.floor(scaled.x + 0.5F),
Mth.floor(scaled.y + 0.5F), MathHelper.floor(scaled.y + 0.5F),
Mth.floor(scaled.z + 0.5F)); MathHelper.floor(scaled.z + 0.5F));
if (pos.equals(this.worldPosition) || pos.equals(connectedPos)) if (pos.equals(this.pos) || pos.equals(connectedPos))
continue; continue;
BlockState state = this.level.getBlockState(pos); BlockState state = this.world.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
if (!block.isAir(state, this.level, pos) && state.getBlockHardness(this.level, pos) >= 0F) { if (!block.isAir(state, this.world, pos) && state.getBlockHardness(this.world, pos) >= 0F) {
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); FakePlayer fake = FakePlayerFactory.getMinecraft((ServerWorld) this.world);
if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.level, pos, state, fake))) { if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.world, pos, state, fake))) {
List<ItemStack> drops = state.getDrops(new LootContext.Builder((ServerLevel) this.level) List<ItemStack> drops = state.getDrops(new LootContext.Builder((ServerWorld) this.world)
.withParameter(LootParameters.THIS_ENTITY, fake) .withParameter(LootParameters.THIS_ENTITY, fake)
.withParameter(LootParameters.field_237457_g_, Vector3d.copyCentered(pos)) .withParameter(LootParameters.field_237457_g_, Vector3d.copyCentered(pos))
.withParameter(LootParameters.BLOCK_STATE, state) .withParameter(LootParameters.BLOCK_STATE, state)
.withParameter(LootParameters.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool) .withParameter(LootParameters.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool)
.withNullableParameter(LootParameters.BLOCK_ENTITY, this.level.getBlockEntity(pos))); .withNullableParameter(LootParameters.BLOCK_ENTITY, this.world.getTileEntity(pos)));
this.level.destroyBlock(pos, false); this.world.destroyBlock(pos, false);
for (ItemStack stack : drops) for (ItemStack stack : drops)
Block.spawnAsEntity(this.level, pos, stack); Block.spawnAsEntity(this.world, pos, stack);
chunk.drainAura(spot, !tool.isEmpty() ? 300 : 100); chunk.drainAura(spot, !tool.isEmpty() ? 300 : 100);
this.sendParticles(); this.sendParticles();
} }
@ -134,20 +134,20 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
} }
} }
private ItemStack getToolUsed(BlockEntityFieldCreator other) { private ItemStack getToolUsed(TileEntityFieldCreator other) {
ItemStack myTool = this.getMyTool(); ItemStack myTool = this.getMyTool();
ItemStack otherTool = other.getMyTool(); ItemStack otherTool = other.getMyTool();
if (!myTool.isEmpty()) { if (!myTool.isEmpty()) {
// if both have tools, choose randomly // if both have tools, choose randomly
if (!otherTool.isEmpty()) if (!otherTool.isEmpty())
return this.level.rand.nextBoolean() ? myTool : otherTool; return this.world.rand.nextBoolean() ? myTool : otherTool;
return myTool; return myTool;
} }
return otherTool; return otherTool;
} }
private ItemStack getMyTool() { private ItemStack getMyTool() {
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.world, this.pos);
for (ItemFrameEntity frame : frames) { for (ItemFrameEntity frame : frames) {
ItemStack stack = frame.getDisplayedItem(); ItemStack stack = frame.getDisplayedItem();
if (!stack.isEmpty()) if (!stack.isEmpty())
@ -158,32 +158,32 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
private void sendParticles() { private void sendParticles() {
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
BlockPos p = j == 0 ? this.worldPosition : this.getConnectedPos(); BlockPos p = j == 0 ? this.pos : this.getConnectedPos();
PacketHandler.sendToAllAround(this.level, p, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.world, p, 32, new PacketParticleStream(
p.getX() + (float) this.level.rand.nextGaussian() * 3F, p.getX() + (float) this.world.rand.nextGaussian() * 3F,
p.getY() + 1 + this.level.rand.nextFloat() * 3F, p.getY() + 1 + this.world.rand.nextFloat() * 3F,
p.getZ() + (float) this.level.rand.nextGaussian() * 3F, p.getZ() + (float) this.world.rand.nextGaussian() * 3F,
p.getX() + 0.5F, p.getX() + 0.5F,
p.getY() + 0.5F, p.getY() + 0.5F,
p.getZ() + 0.5F, p.getZ() + 0.5F,
this.level.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.rand.nextFloat() + 0.5F this.world.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forWorld(this.world).getColor(), this.world.rand.nextFloat() + 0.5F
)); ));
} }
} }
public boolean isCloseEnough(BlockPos pos) { public boolean isCloseEnough(BlockPos pos) {
int range = ModConfig.instance.fieldCreatorRange.get() + 1; int range = ModConfig.instance.fieldCreatorRange.get() + 1;
return this.worldPosition.distanceSq(pos) <= range * range; return this.pos.distanceSq(pos) <= range * range;
} }
public BlockPos getConnectedPos() { public BlockPos getConnectedPos() {
if (this.connectionOffset == null) if (this.connectionOffset == null)
return null; return null;
return this.worldPosition.add(this.connectionOffset); return this.pos.add(this.connectionOffset);
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (this.connectionOffset != null) if (this.connectionOffset != null)
@ -197,7 +197,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (compound.contains("connection")) if (compound.contains("connection"))

View file

@ -8,37 +8,37 @@ import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.projectile.FireworkRocketEntity; import net.minecraft.entity.projectile.FireworkRocketEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListNBT;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.EntityPredicates; import net.minecraft.util.EntityPredicates;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityFireworkGenerator extends TileEntityImpl implements ITickableTileEntity {
private FireworkRocketEntity trackedEntity; private FireworkRocketEntity trackedEntity;
private ItemStack trackedItem; private ItemStack trackedItem;
private int toRelease; private int toRelease;
private int releaseTimer; private int releaseTimer;
public BlockEntityFireworkGenerator() { public TileEntityFireworkGenerator() {
super(ModTileEntities.FIREWORK_GENERATOR); super(ModTileEntities.FIREWORK_GENERATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.world.isRemote) {
if (this.level.getGameTime() % 10 == 0) { if (this.world.getGameTime() % 10 == 0) {
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class,
new AxisAlignedBB(this.worldPosition).grow(4), EntityPredicates.IS_ALIVE); new AxisAlignedBB(this.pos).grow(4), EntityPredicates.IS_ALIVE);
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (item.cannotPickup()) if (item.cannotPickup())
continue; continue;
@ -46,10 +46,10 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
if (stack.isEmpty() || stack.getItem() != Items.FIREWORK_ROCKET) if (stack.isEmpty() || stack.getItem() != Items.FIREWORK_ROCKET)
continue; continue;
if (this.trackedEntity == null && this.releaseTimer <= 0) { if (this.trackedEntity == null && this.releaseTimer <= 0) {
FireworkRocketEntity entity = new FireworkRocketEntity(this.level, item.getPosX(), item.getPosY(), item.getPosZ(), stack); FireworkRocketEntity entity = new FireworkRocketEntity(this.world, item.getPosX(), item.getPosY(), item.getPosZ(), stack);
this.trackedEntity = entity; this.trackedEntity = entity;
this.trackedItem = stack.copy(); this.trackedItem = stack.copy();
this.level.addEntity(entity); this.world.addEntity(entity);
} }
stack.shrink(1); stack.shrink(1);
if (stack.isEmpty()) if (stack.isEmpty())
@ -64,8 +64,8 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
float generateFactor = 0; float generateFactor = 0;
Set<Integer> usedColors = new HashSet<>(); Set<Integer> usedColors = new HashSet<>();
CompoundTag compound = this.trackedItem.getTag(); CompoundNBT compound = this.trackedItem.getTag();
CompoundTag fireworks = compound.getCompound("Fireworks"); CompoundNBT fireworks = compound.getCompound("Fireworks");
int flightTime = fireworks.getInt("Flight"); int flightTime = fireworks.getInt("Flight");
ListNBT explosions = fireworks.getList("Explosions", 10); ListNBT explosions = fireworks.getList("Explosions", 10);
@ -73,7 +73,7 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
generateFactor += flightTime; generateFactor += flightTime;
for (INBT base : explosions) { for (INBT base : explosions) {
CompoundTag explosion = (CompoundTag) base; CompoundNBT explosion = (CompoundNBT) base;
generateFactor += 1.5F; generateFactor += 1.5F;
boolean flicker = explosion.getBoolean("Flicker"); boolean flicker = explosion.getBoolean("Flicker");
@ -97,18 +97,18 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
} }
if (generateFactor > 0) { if (generateFactor > 0) {
int toAdd = Mth.ceil(generateFactor * 10000F); int toAdd = MathHelper.ceil(generateFactor * 10000F);
if (this.canGenerateRightNow(toAdd)) { if (this.canGenerateRightNow(toAdd)) {
this.toRelease = toAdd; this.toRelease = toAdd;
this.releaseTimer = 15 * flightTime + 40; this.releaseTimer = 15 * flightTime + 40;
} }
List<Integer> data = new ArrayList<>(); List<Integer> data = new ArrayList<>();
data.add(this.worldPosition.getX()); data.add(this.pos.getX());
data.add(this.worldPosition.getY()); data.add(this.pos.getY());
data.add(this.worldPosition.getZ()); data.add(this.pos.getZ());
data.addAll(usedColors); data.addAll(usedColors);
PacketHandler.sendToAllLoaded(this.level, this.worldPosition, new PacketParticles( PacketHandler.sendToAllLoaded(this.world, this.pos, new PacketParticles(
(float) this.trackedEntity.getPosX(), (float) this.trackedEntity.getPosY(), (float) this.trackedEntity.getPosZ(), (float) this.trackedEntity.getPosX(), (float) this.trackedEntity.getPosY(), (float) this.trackedEntity.getPosZ(),
PacketParticles.Type.FIREWORK_GEN, Ints.toArray(data))); PacketParticles.Type.FIREWORK_GEN, Ints.toArray(data)));
} }
@ -124,8 +124,8 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
this.generateAura(this.toRelease); this.generateAura(this.toRelease);
this.toRelease = 0; this.toRelease = 0;
PacketHandler.sendToAllLoaded(this.level, this.worldPosition, PacketHandler.sendToAllLoaded(this.world, this.pos,
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION)); new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));
} }
} }
} }

View file

@ -9,11 +9,11 @@ import de.ellpeck.naturesaura.packet.PacketParticleStream;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListNBT;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
@ -24,24 +24,24 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityFlowerGenerator extends TileEntityImpl implements ITickableTileEntity {
private final Map<BlockState, MutableInt> consumedRecently = new HashMap<>(); private final Map<BlockState, MutableInt> consumedRecently = new HashMap<>();
public BlockEntityFlowerGenerator() { public TileEntityFlowerGenerator() {
super(ModTileEntities.FLOWER_GENERATOR); super(ModTileEntities.FLOWER_GENERATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) { if (!this.world.isRemote && this.world.getGameTime() % 10 == 0) {
List<BlockPos> possible = new ArrayList<>(); List<BlockPos> possible = new ArrayList<>();
int range = 3; int range = 3;
for (int x = -range; x <= range; x++) { for (int x = -range; x <= range; x++) {
for (int y = -1; y <= 1; y++) { for (int y = -1; y <= 1; y++) {
for (int z = -range; z <= range; z++) { for (int z = -range; z <= range; z++) {
BlockPos offset = this.worldPosition.add(x, y, z); BlockPos offset = this.pos.add(x, y, z);
BlockState state = this.level.getBlockState(offset); BlockState state = this.world.getBlockState(offset);
if (BlockTags.SMALL_FLOWERS.contains(state.getBlock())) if (BlockTags.SMALL_FLOWERS.contains(state.getBlock()))
possible.add(offset); possible.add(offset);
} }
@ -51,14 +51,14 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
if (possible.isEmpty()) if (possible.isEmpty())
return; return;
BlockPos pos = possible.get(this.level.rand.nextInt(possible.size())); BlockPos pos = possible.get(this.world.rand.nextInt(possible.size()));
BlockState state = this.level.getBlockState(pos); BlockState state = this.world.getBlockState(pos);
MutableInt curr = this.consumedRecently.computeIfAbsent(state, s -> new MutableInt()); MutableInt curr = this.consumedRecently.computeIfAbsent(state, s -> new MutableInt());
int addAmount = 25000; int addAmount = 25000;
int toAdd = Math.max(0, addAmount - curr.getValue() * 100); int toAdd = Math.max(0, addAmount - curr.getValue() * 100);
if (toAdd > 0) { if (toAdd > 0) {
if (IAuraType.forLevel(this.level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(toAdd)) { if (IAuraType.forWorld(this.world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(toAdd)) {
this.generateAura(toAdd); this.generateAura(toAdd);
} else { } else {
toAdd = 0; toAdd = 0;
@ -74,23 +74,23 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
} }
curr.add(5); curr.add(5);
this.level.removeBlock(pos, false); this.world.removeBlock(pos, false);
int color = Helper.blendColors(0x5ccc30, 0xe53c16, toAdd / (float) addAmount); int color = Helper.blendColors(0x5ccc30, 0xe53c16, toAdd / (float) addAmount);
if (toAdd > 0) { if (toAdd > 0) {
for (int i = this.level.rand.nextInt(5) + 5; i >= 0; i--) for (int i = this.world.rand.nextInt(5) + 5; i >= 0; i--)
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticleStream(
pos.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F, pos.getX() + 0.25F + this.world.rand.nextFloat() * 0.5F,
pos.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F, pos.getY() + 0.25F + this.world.rand.nextFloat() * 0.5F,
pos.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F, pos.getZ() + 0.25F + this.world.rand.nextFloat() * 0.5F,
this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.pos.getX() + 0.25F + this.world.rand.nextFloat() * 0.5F,
this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.pos.getY() + 0.25F + this.world.rand.nextFloat() * 0.5F,
this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F, this.pos.getZ() + 0.25F + this.world.rand.nextFloat() * 0.5F,
this.level.rand.nextFloat() * 0.02F + 0.1F, color, 1F this.world.rand.nextFloat() * 0.02F + 0.1F, color, 1F
)); ));
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION)); PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));
} }
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(pos.getX(), pos.getY(), pos.getZ(), PacketParticles.Type.FLOWER_GEN_CONSUME, color)); PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(pos.getX(), pos.getY(), pos.getZ(), PacketParticles.Type.FLOWER_GEN_CONSUME, color));
} }
} }
@ -100,7 +100,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.SYNC && !this.consumedRecently.isEmpty()) { if (type != SaveType.SYNC && !this.consumedRecently.isEmpty()) {
@ -109,7 +109,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
BlockState state = entry.getKey(); BlockState state = entry.getKey();
Block block = state.getBlock(); Block block = state.getBlock();
CompoundTag tag = new CompoundTag(); CompoundNBT tag = new CompoundNBT();
tag.putString("block", block.getRegistryName().toString()); tag.putString("block", block.getRegistryName().toString());
tag.putInt("amount", entry.getValue().intValue()); tag.putInt("amount", entry.getValue().intValue());
list.add(tag); list.add(tag);
@ -119,13 +119,13 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.SYNC) { if (type != SaveType.SYNC) {
this.consumedRecently.clear(); this.consumedRecently.clear();
ListNBT list = compound.getList("consumed_recently", 10); ListNBT list = compound.getList("consumed_recently", 10);
for (INBT base : list) { for (INBT base : list) {
CompoundTag tag = (CompoundTag) base; CompoundNBT tag = (CompoundNBT) base;
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("block"))); Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("block")));
if (block != null) if (block != null)
this.consumedRecently.put(block.getDefaultState(), new MutableInt(tag.getInt("amount"))); this.consumedRecently.put(block.getDefaultState(), new MutableInt(tag.getInt("amount")));

View file

@ -11,26 +11,26 @@ import net.minecraft.block.AbstractFurnaceBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.AbstractCookingRecipe; import net.minecraft.item.crafting.AbstractCookingRecipe;
import net.minecraft.item.crafting.IRecipeType; import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.*; import net.minecraft.tileentity.*;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.IIntArray; import net.minecraft.util.IIntArray;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth; import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.lang.reflect.Field; import java.lang.reflect.Field;
public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickableTileEntity {
private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceBlockEntity.class, "field_214013_b"); private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceTileEntity.class, "field_214013_b");
public boolean isActive; public boolean isActive;
public BlockEntityFurnaceHeater() { public TileEntityFurnaceHeater() {
super(ModTileEntities.FURNACE_HEATER); super(ModTileEntities.FURNACE_HEATER);
} }
public static IIntArray getFurnaceData(AbstractFurnaceBlockEntity tile) { public static IIntArray getFurnaceData(AbstractFurnaceTileEntity tile) {
try { try {
return (IIntArray) FURNACE_DATA_FIELD.get(tile); return (IIntArray) FURNACE_DATA_FIELD.get(tile);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -39,10 +39,10 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
} }
} }
public static IRecipeType<? extends AbstractCookingRecipe> getRecipeType(AbstractFurnaceBlockEntity furnace) { public static IRecipeType<? extends AbstractCookingRecipe> getRecipeType(AbstractFurnaceTileEntity furnace) {
if (furnace instanceof BlastFurnaceBlockEntity) { if (furnace instanceof BlastFurnaceTileEntity) {
return IRecipeType.BLASTING; return IRecipeType.BLASTING;
} else if (furnace instanceof SmokerBlockEntity) { } else if (furnace instanceof SmokerTileEntity) {
return IRecipeType.SMOKING; return IRecipeType.SMOKING;
} else { } else {
return IRecipeType.SMELTING; return IRecipeType.SMELTING;
@ -51,38 +51,38 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 5 == 0) { if (!this.world.isRemote && this.world.getGameTime() % 5 == 0) {
boolean did = false; boolean did = false;
Direction facing = this.level.getBlockState(this.worldPosition).get(BlockFurnaceHeater.FACING); Direction facing = this.world.getBlockState(this.pos).get(BlockFurnaceHeater.FACING);
BlockPos tilePos = this.worldPosition.offset(facing.getOpposite()); BlockPos tilePos = this.pos.offset(facing.getOpposite());
BlockEntity tile = this.level.getBlockEntity(tilePos); TileEntity tile = this.world.getTileEntity(tilePos);
if (tile instanceof AbstractFurnaceBlockEntity) { if (tile instanceof AbstractFurnaceTileEntity) {
AbstractFurnaceBlockEntity furnace = (AbstractFurnaceBlockEntity) tile; AbstractFurnaceTileEntity furnace = (AbstractFurnaceTileEntity) tile;
if (this.isReady(furnace)) { if (this.isReady(furnace)) {
IIntArray data = getFurnaceData(furnace); IIntArray data = getFurnaceData(furnace);
int burnTime = data.get(0); int burnTime = data.get(0);
if (burnTime <= 0) if (burnTime <= 0)
this.level.setBlockState(tilePos, this.level.getBlockState(tilePos).with(AbstractFurnaceBlock.LIT, true)); this.world.setBlockState(tilePos, this.world.getBlockState(tilePos).with(AbstractFurnaceBlock.LIT, true));
data.set(0, 200); data.set(0, 200);
//if set higher than 199, it'll never finish because the furnace does ++ and then == //if set higher than 199, it'll never finish because the furnace does ++ and then ==
data.set(2, Math.min(data.get(3) - 1, data.get(2) + 5)); data.set(2, Math.min(data.get(3) - 1, data.get(2) + 5));
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot); IAuraChunk chunk = IAuraChunk.getAuraChunk(this.world, spot);
chunk.drainAura(spot, Mth.ceil((200 - burnTime) * 16.6F)); chunk.drainAura(spot, MathHelper.ceil((200 - burnTime) * 16.6F));
did = true; did = true;
if (this.level.getGameTime() % 15 == 0) { if (this.world.getGameTime() % 15 == 0) {
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticleStream(
this.worldPosition.getX() + (float) this.level.rand.nextGaussian() * 5F, this.pos.getX() + (float) this.world.rand.nextGaussian() * 5F,
this.worldPosition.getY() + 1 + this.level.rand.nextFloat() * 5F, this.pos.getY() + 1 + this.world.rand.nextFloat() * 5F,
this.worldPosition.getZ() + (float) this.level.rand.nextGaussian() * 5F, this.pos.getZ() + (float) this.world.rand.nextGaussian() * 5F,
tilePos.getX() + this.level.rand.nextFloat(), tilePos.getX() + this.world.rand.nextFloat(),
tilePos.getY() + this.level.rand.nextFloat(), tilePos.getY() + this.world.rand.nextFloat(),
tilePos.getZ() + this.level.rand.nextFloat(), tilePos.getZ() + this.world.rand.nextFloat(),
this.level.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.rand.nextFloat() + 0.5F this.world.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forWorld(this.world).getColor(), this.world.rand.nextFloat() + 0.5F
)); ));
} }
} }
@ -95,13 +95,13 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
} }
} }
private boolean isReady(AbstractFurnaceBlockEntity furnace) { private boolean isReady(AbstractFurnaceTileEntity furnace) {
if (!furnace.getStackInSlot(1).isEmpty()) if (!furnace.getStackInSlot(1).isEmpty())
return false; return false;
ItemStack input = furnace.getStackInSlot(0); ItemStack input = furnace.getStackInSlot(0);
if (!input.isEmpty()) { if (!input.isEmpty()) {
AbstractCookingRecipe recipe = this.level.getRecipeManager().getRecipe(getRecipeType(furnace), furnace, this.level).orElse(null); AbstractCookingRecipe recipe = this.world.getRecipeManager().getRecipe(getRecipeType(furnace), furnace, this.world).orElse(null);
if (recipe == null) if (recipe == null)
return false; return false;
ItemStack output = recipe.getRecipeOutput(); ItemStack output = recipe.getRecipeOutput();
@ -112,7 +112,7 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type == SaveType.SYNC) if (type == SaveType.SYNC)
@ -120,7 +120,7 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type == SaveType.SYNC) if (type == SaveType.SYNC)

View file

@ -4,15 +4,15 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl { public class TileEntityGeneratorLimitRemover extends TileEntityImpl {
public BlockEntityGeneratorLimitRemover() { public TileEntityGeneratorLimitRemover() {
super(ModTileEntities.GENERATOR_LIMIT_REMOVER); super(ModTileEntities.GENERATOR_LIMIT_REMOVER);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return new AxisAlignedBB(this.worldPosition, this.worldPosition.add(1, 2, 1)); return new AxisAlignedBB(this.pos, this.pos.add(1, 2, 1));
} }
} }

View file

@ -6,9 +6,9 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.item.ItemFrameEntity; import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
@ -17,29 +17,29 @@ import net.minecraftforge.items.IItemHandlerModifiable;
import java.util.List; import java.util.List;
public class BlockEntityGratedChute extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityGratedChute extends TileEntityImpl implements ITickableTileEntity {
public boolean isBlacklist; public boolean isBlacklist;
private final ItemStackHandlerNA items = new ItemStackHandlerNA(1, this, true) { private final ItemStackHandlerNA items = new ItemStackHandlerNA(1, this, true) {
@Override @Override
protected boolean canExtract(ItemStack stack, int slot, int amount) { protected boolean canExtract(ItemStack stack, int slot, int amount) {
return BlockEntityGratedChute.this.redstonePower <= 0; return TileEntityGratedChute.this.redstonePower <= 0;
} }
@Override @Override
protected boolean canInsert(ItemStack stack, int slot) { protected boolean canInsert(ItemStack stack, int slot) {
return BlockEntityGratedChute.this.isBlacklist != BlockEntityGratedChute.this.isItemInFrame(stack); return TileEntityGratedChute.this.isBlacklist != TileEntityGratedChute.this.isItemInFrame(stack);
} }
}; };
private int cooldown; private int cooldown;
public BlockEntityGratedChute() { public TileEntityGratedChute() {
super(ModTileEntities.GRATED_CHUTE); super(ModTileEntities.GRATED_CHUTE);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide) { if (!this.world.isRemote) {
if (this.cooldown <= 0) { if (this.cooldown <= 0) {
this.cooldown = 6; this.cooldown = 6;
if (this.redstonePower > 0) if (this.redstonePower > 0)
@ -48,9 +48,9 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
ItemStack curr = this.items.getStackInSlot(0); ItemStack curr = this.items.getStackInSlot(0);
push: push:
if (!curr.isEmpty()) { if (!curr.isEmpty()) {
BlockState state = this.level.getBlockState(this.worldPosition); BlockState state = this.world.getBlockState(this.pos);
Direction facing = state.get(BlockGratedChute.FACING); Direction facing = state.get(BlockGratedChute.FACING);
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.offset(facing)); TileEntity tile = this.world.getTileEntity(this.pos.offset(facing));
if (tile == null) if (tile == null)
break push; break push;
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
@ -70,9 +70,9 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
pull: pull:
if (curr.isEmpty() || curr.getCount() < curr.getMaxStackSize()) { if (curr.isEmpty() || curr.getCount() < curr.getMaxStackSize()) {
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB( List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(
this.worldPosition.getX(), this.worldPosition.getY() + 0.5, this.worldPosition.getZ(), this.pos.getX(), this.pos.getY() + 0.5, this.pos.getZ(),
this.worldPosition.getX() + 1, this.worldPosition.getY() + 2, this.worldPosition.getZ() + 1)); this.pos.getX() + 1, this.pos.getY() + 2, this.pos.getZ() + 1));
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (!item.isAlive()) if (!item.isAlive())
continue; continue;
@ -89,7 +89,7 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
} }
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.up()); TileEntity tileUp = this.world.getTileEntity(this.pos.up());
if (tileUp == null) if (tileUp == null)
break pull; break pull;
IItemHandler handlerUp = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null); IItemHandler handlerUp = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null);
@ -112,7 +112,7 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
private boolean isItemInFrame(ItemStack stack) { private boolean isItemInFrame(ItemStack stack) {
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition); List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.world, this.pos);
if (frames.isEmpty()) if (frames.isEmpty())
return false; return false;
for (ItemFrameEntity frame : frames) { for (ItemFrameEntity frame : frames) {
@ -125,7 +125,7 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
compound.putInt("cooldown", this.cooldown); compound.putInt("cooldown", this.cooldown);
@ -135,7 +135,7 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
this.cooldown = compound.getInt("cooldown"); this.cooldown = compound.getInt("cooldown");

View file

@ -6,9 +6,9 @@ import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.HopperBlock; import net.minecraft.block.HopperBlock;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.HopperBlockEntity; import net.minecraft.tileentity.HopperTileEntity;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -17,33 +17,33 @@ import net.minecraftforge.items.IItemHandler;
import java.util.List; import java.util.List;
public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickableBlockEntity { public class TileEntityHopperUpgrade extends TileEntityImpl implements ITickableTileEntity {
public BlockEntityHopperUpgrade() { public TileEntityHopperUpgrade() {
super(ModTileEntities.HOPPER_UPGRADE); super(ModTileEntities.HOPPER_UPGRADE);
} }
private static boolean isValidHopper(BlockEntity tile) { private static boolean isValidHopper(TileEntity tile) {
if (tile instanceof HopperBlockEntity) if (tile instanceof HopperTileEntity)
return tile.getLevel().getBlockState(tile.getPos()).get(HopperBlock.ENABLED); return tile.getWorld().getBlockState(tile.getPos()).get(HopperBlock.ENABLED);
if (tile instanceof BlockEntityGratedChute) if (tile instanceof TileEntityGratedChute)
return ((BlockEntityGratedChute) tile).redstonePower <= 0; return ((TileEntityGratedChute) tile).redstonePower <= 0;
return false; return false;
} }
@Override @Override
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) { if (!this.world.isRemote && this.world.getGameTime() % 10 == 0) {
if (IAuraChunk.getAuraInArea(this.level, this.worldPosition, 25) < 100000) if (IAuraChunk.getAuraInArea(this.world, this.pos, 25) < 100000)
return; return;
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.down()); TileEntity tile = this.world.getTileEntity(this.pos.down());
if (!isValidHopper(tile)) if (!isValidHopper(tile))
return; return;
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null); IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
if (handler == null) if (handler == null)
return; return;
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class,
new AxisAlignedBB(this.worldPosition).grow(7)); new AxisAlignedBB(this.pos).grow(7));
if (items.isEmpty()) if (items.isEmpty())
return; return;
@ -67,10 +67,10 @@ public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickab
if (copy.isEmpty()) if (copy.isEmpty())
item.remove(); item.remove();
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 25, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 25, this.pos);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 500); IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, 500);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.HOPPER_UPGRADE)); new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.HOPPER_UPGRADE));
} }
} }

View file

@ -4,18 +4,19 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.blocks.ModBlocks; import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.core.BlockPos; import net.minecraft.block.BlockState;
import net.minecraft.core.Direction; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.Connection; import net.minecraft.item.ItemStack;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.server.level.ServerLevel; import net.minecraft.network.NetworkManager;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.world.item.ItemStack; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.level.ChunkPos; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.util.Direction;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
@ -23,37 +24,40 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.stream.Stream;
public class BlockEntityImpl extends BlockEntity { public class TileEntityImpl extends TileEntity {
public int redstonePower; public int redstonePower;
private LazyOptional<IItemHandler> itemHandler; private LazyOptional<IItemHandler> itemHandler;
private LazyOptional<IAuraContainer> auraContainer; private LazyOptional<IAuraContainer> auraContainer;
public BlockEntityImpl(BlockEntityType<?> type, BlockPos pos, BlockState state) { public TileEntityImpl(TileEntityType<?> tileEntityTypeIn) {
super(type, pos, state); super(tileEntityTypeIn);
} }
@Override @Override
public void saveAdditional(CompoundTag compound) { public CompoundNBT write(CompoundNBT compound) {
this.writeNBT(compound, SaveType.TILE); this.writeNBT(compound, SaveType.TILE);
return compound;
} }
@Override @Override
public void load(CompoundTag compound) { public void read(BlockState state, CompoundNBT compound) {
this.readNBT(compound, SaveType.TILE); this.readNBT(compound, SaveType.TILE);
} }
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundNBT compound, SaveType type) {
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
super.saveAdditional(compound); super.write(compound);
compound.putInt("redstone", this.redstonePower); compound.putInt("redstone", this.redstonePower);
} }
} }
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundNBT compound, SaveType type) {
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
super.load(compound); // looks like the block state isn't used in the super
super.read(null, compound);
this.redstonePower = compound.getInt("redstone"); this.redstonePower = compound.getInt("redstone");
} }
} }
@ -63,38 +67,36 @@ public class BlockEntityImpl extends BlockEntity {
} }
@Override @Override
public final ClientboundBlockEntityDataPacket getUpdatePacket() { public final SUpdateTileEntityPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, e -> { CompoundNBT compound = new CompoundNBT();
CompoundTag compound = new CompoundTag(); this.writeNBT(compound, SaveType.SYNC);
this.writeNBT(compound, SaveType.SYNC); return new SUpdateTileEntityPacket(this.pos, 0, compound);
return compound;
});
} }
@Override @Override
public final CompoundTag getUpdateTag() { public final CompoundNBT getUpdateTag() {
CompoundTag compound = new CompoundTag(); CompoundNBT compound = new CompoundNBT();
this.writeNBT(compound, SaveType.SYNC); this.writeNBT(compound, SaveType.SYNC);
return compound; return compound;
} }
@Override @Override
public void handleUpdateTag(CompoundTag tag) { public void handleUpdateTag(BlockState state, CompoundNBT tag) {
this.readNBT(tag, SaveType.SYNC); this.readNBT(tag, SaveType.SYNC);
} }
@Override @Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket packet) {
super.onDataPacket(net, pkt); super.onDataPacket(net, packet);
this.readNBT(pkt.getTag(), SaveType.SYNC); this.readNBT(packet.getNbtCompound(), SaveType.SYNC);
} }
public void sendToClients() { public void sendToClients() {
var world = (ServerLevel) this.getLevel(); ServerWorld world = (ServerWorld) this.getWorld();
var entities = world.getChunkSource().chunkMap.getPlayers(new ChunkPos(this.getBlockPos()), false); Stream<ServerPlayerEntity> entities = world.getChunkProvider().chunkManager.getTrackingPlayers(new ChunkPos(this.getPos()), false);
ClientboundBlockEntityDataPacket packet = this.getUpdatePacket(); SUpdateTileEntityPacket packet = this.getUpdatePacket();
for (var e : entities) entities.forEach(e -> e.connection.sendPacket(packet));
e.connection.send(packet);
} }
public IItemHandlerModifiable getItemHandler() { public IItemHandlerModifiable getItemHandler() {
@ -126,8 +128,8 @@ public class BlockEntityImpl extends BlockEntity {
} }
@Override @Override
public void setRemoved() { public void remove() {
super.setRemoved(); super.remove();
if (this.itemHandler != null) if (this.itemHandler != null)
this.itemHandler.invalidate(); this.itemHandler.invalidate();
if (this.auraContainer != null) if (this.auraContainer != null)
@ -140,36 +142,40 @@ public class BlockEntityImpl extends BlockEntity {
for (int i = 0; i < handler.getSlots(); i++) { for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i); ItemStack stack = handler.getStackInSlot(i);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
ItemEntity item = new ItemEntity(this.level, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, stack); ItemEntity item = new ItemEntity(this.world,
this.level.addFreshEntity(item); this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5,
stack);
this.world.addEntity(item);
} }
} }
} }
} }
public void modifyDrop(ItemStack regularItem) { public void modifyDrop(ItemStack regularItem) {
CompoundTag compound = new CompoundTag(); CompoundNBT compound = new CompoundNBT();
this.writeNBT(compound, SaveType.BLOCK); this.writeNBT(compound, SaveType.BLOCK);
if (!compound.isEmpty()) { if (!compound.isEmpty()) {
if (!regularItem.hasTag()) regularItem.setTag(new CompoundTag()); if (!regularItem.hasTag())
regularItem.setTag(new CompoundNBT());
regularItem.getTag().put("data", compound); regularItem.getTag().put("data", compound);
} }
} }
public void loadDataOnPlace(ItemStack stack) { public void loadDataOnPlace(ItemStack stack) {
if (stack.hasTag()) { if (stack.hasTag()) {
CompoundTag compound = stack.getTag().getCompound("data"); CompoundNBT compound = stack.getTag().getCompound("data");
if (compound != null) this.readNBT(compound, SaveType.BLOCK); if (compound != null)
this.readNBT(compound, SaveType.BLOCK);
} }
} }
public boolean canGenerateRightNow(int toAdd) { public boolean canGenerateRightNow(int toAdd) {
if (this.wantsLimitRemover()) { if (this.wantsLimitRemover()) {
BlockState below = this.level.getBlockState(this.worldPosition.below()); BlockState below = this.world.getBlockState(this.pos.down());
if (below.getBlock() == ModBlocks.GENERATOR_LIMIT_REMOVER) if (below.getBlock() == ModBlocks.GENERATOR_LIMIT_REMOVER)
return true; return true;
} }
int aura = IAuraChunk.getAuraInArea(this.level, this.worldPosition, 35); int aura = IAuraChunk.getAuraInArea(this.world, this.pos, 35);
return aura + toAdd <= IAuraChunk.DEFAULT_AURA * 2; return aura + toAdd <= IAuraChunk.DEFAULT_AURA * 2;
} }
@ -179,12 +185,14 @@ public class BlockEntityImpl extends BlockEntity {
public void generateAura(int amount) { public void generateAura(int amount) {
while (amount > 0) { while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.level, this.worldPosition, 35, this.worldPosition); BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
amount -= IAuraChunk.getAuraChunk(this.level, spot).storeAura(spot, amount); amount -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, amount);
} }
} }
public enum SaveType { public enum SaveType {
TILE, SYNC, BLOCK TILE,
SYNC,
BLOCK
} }
} }

Some files were not shown because too many files have changed in this diff Show more