Compare commits

..

3 commits

Author SHA1 Message Date
Ell
1880bf785d some more workkkk 2021-12-04 19:17:21 +01:00
Ell
cd328cab6a some more work?? 2021-12-04 15:40:09 +01:00
Ell
8ee01dafe4 the start of a terrible journey 2021-12-04 14:51:31 +01:00
215 changed files with 3855 additions and 3807 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 world to create useful devices and unique mechanics. naturally present in the level to create useful devices and unique mechanics.
## Maven ## Maven

View file

@ -1,11 +1,11 @@
buildscript { buildscript {
repositories { repositories {
maven { url = 'https://files.minecraftforge.net/maven' } // These repositories are only for Gradle plugins, put any other repositories in the repository block further below
jcenter() maven { url = 'https://maven.minecraftforge.net' }
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
} }
} }
apply plugin: 'net.minecraftforge.gradle' apply plugin: 'net.minecraftforge.gradle'
@ -20,10 +20,11 @@ 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: 'snapshot', version: '20200723-1.16.1' mappings channel: 'official', version: '1.18'
runs { runs {
client { client {
@ -101,18 +102,22 @@ repositories {
} }
dependencies { dependencies {
minecraft 'net.minecraftforge:forge:1.16.5-36.1.3' minecraft 'net.minecraftforge:forge:1.18-38.0.14'
compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api") // TODO JEI
runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75") /* 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")*/
compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api") // TDOO Patchouli
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50") /* compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api")
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50")*/
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0") // TODO Curios
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0:api") /* 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")*/
compile fg.deobf("quarris.enchantability:Enchantability:11.0.48") // TODO Enchantability
/* 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,6 +1,5 @@
#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,78 +1,129 @@
#!/usr/bin/env sh #!/bin/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 UN*X # Gradle start up script for POSIX generated by Gradle.
## #
# 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
PRG="$0" app_path=$0
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do # Need this for daisy-chained symlinks.
ls=`ls -ld "$PRG"` while
link=`expr "$ls" : '.*-> \(.*\)$'` APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
if expr "$link" : '/.*' > /dev/null; then [ -h "$app_path" ]
PRG="$link" do
else ls=$( ls -ld "$app_path" )
PRG=`dirname "$PRG"`"/$link" link=${ls#*' -> '}
fi case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle" APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"` APP_BASE_NAME=${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="" DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# 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* ) cygwin=true ;; #(
cygwin=true Darwin* ) darwin=true ;; #(
;; MSYS* | MINGW* ) msys=true ;; #(
Darwin* ) NONSTOP* ) nonstop=true ;;
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
@ -81,7 +132,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
@ -89,84 +140,95 @@ 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
MAX_FD_LIMIT=`ulimit -H -n` case $MAX_FD in #(
if [ $? -eq 0 ] ; then max*)
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD=$( ulimit -H -n ) ||
MAX_FD="$MAX_FD_LIMIT" warn "Could not query maximum file descriptor limit"
fi esac
ulimit -n $MAX_FD case $MAX_FD in #(
if [ $? -ne 0 ] ; then '' | soft) :;; #(
warn "Could not set maximum file descriptor limit: $MAX_FD" *)
fi ulimit -n "$MAX_FD" ||
else warn "Could not set maximum file descriptor limit to $MAX_FD"
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
# Escape application args # Collect all arguments for the java command, stacking in reverse order:
save () { # * args from the command line
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done # * the main class name
echo " " # * -classpath
} # * -D...appname settings
APP_ARGS=$(save "$@") # * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# Collect all arguments for the java command, following the shell quoting and substitution rules # For Cygwin or MSYS, switch paths to Windows format before running java
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong JAVACMD=$( cygpath --unix "$JAVACMD" )
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")" # 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
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@" exec "$JAVACMD" "$@"

43
gradlew.bat vendored
View file

@ -1,3 +1,19 @@
@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
@ -13,15 +29,18 @@ 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= set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@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 init if "%ERRORLEVEL%" == "0" goto execute
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.
@ -35,7 +54,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 init if exist "%JAVA_EXE%" goto execute
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%
@ -45,28 +64,14 @@ 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 %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
: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,74 +1,64 @@
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.IWorldData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
import de.ellpeck.naturesaura.chunk.AuraChunk; import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.misc.LevelData;
import de.ellpeck.naturesaura.misc.WorldData; import net.minecraft.core.BlockPos;
import net.minecraft.advancements.Advancement; import net.minecraft.core.Direction;
import net.minecraft.block.Block; import net.minecraft.resources.ResourceLocation;
import net.minecraft.block.BlockState; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.client.Minecraft; import net.minecraft.sounds.SoundEvents;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.sounds.SoundSource;
import net.minecraft.entity.item.ItemFrameEntity; import net.minecraft.world.InteractionHand;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.InteractionResult;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.item.Item; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.player.Player;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.item.Item;
import net.minecraft.nbt.INBT; import net.minecraft.world.item.ItemStack;
import net.minecraft.state.Property; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.ChunkPos;
import net.minecraft.util.*; import net.minecraft.world.level.Level;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.ChunkPos; import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.IWorld; import net.minecraft.world.phys.AABB;
import net.minecraft.world.World; import net.minecraft.world.phys.Vec3;
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 getTileEntitiesInArea(IWorld world, BlockPos pos, int radius, Function<TileEntity, Boolean> consumer) { public static boolean getBlockEntitiesInArea(Level level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) {
for (int x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) { for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (int z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) { for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
Chunk chunk = getLoadedChunk(world, x, z); var chunk = getLoadedChunk(level, x, z);
if (chunk != null) { if (chunk != null) {
for (BlockPos tilePos : chunk.getTileEntitiesPos()) { for (var tilePos : chunk.getBlockEntitiesPos()) {
if (tilePos.distanceSq(pos) <= radius * radius) if (tilePos.distSqr(pos) <= radius * radius)
if (consumer.apply(chunk.getTileEntity(tilePos))) if (consumer.apply(chunk.getBlockEntity(tilePos)))
return true; return true;
} }
} }
@ -77,99 +67,86 @@ public final class Helper {
return false; return false;
} }
public static void getAuraChunksWithSpotsInArea(World world, BlockPos pos, int radius, Consumer<AuraChunk> consumer) { public static void getAuraChunksWithSpotsInArea(Level level, BlockPos pos, int radius, Consumer<AuraChunk> consumer) {
WorldData data = (WorldData) IWorldData.getWorldData(world); var data = (LevelData) ILevelData.getLevelData(level);
for (int x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) { for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (int z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) { for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
AuraChunk chunk = data.auraChunksWithSpots.get(ChunkPos.asLong(x, z)); var chunk = data.auraChunksWithSpots.get(ChunkPos.asLong(x, z));
if (chunk != null) if (chunk != null)
consumer.accept(chunk); consumer.accept(chunk);
} }
} }
} }
public static List<ItemFrameEntity> getAttachedItemFrames(World world, BlockPos pos) { public static List<ItemFrame> getAttachedItemFrames(Level level, BlockPos pos) {
List<ItemFrameEntity> frames = world.getEntitiesWithinAABB(ItemFrameEntity.class, new AxisAlignedBB(pos).grow(0.25)); var frames = level.getEntitiesOfClass(ItemFrame.class, new AABB(pos).inflate(0.25));
for (int i = frames.size() - 1; i >= 0; i--) { for (var i = frames.size() - 1; i >= 0; i--) {
ItemFrameEntity frame = frames.get(i); var frame = frames.get(i);
BlockPos framePos = frame.getHangingPosition().offset(frame.getHorizontalFacing().getOpposite()); var framePos = frame.getPos().relative(frame.getDirection().getOpposite());
if (!pos.equals(framePos)) if (!pos.equals(framePos))
frames.remove(i); frames.remove(i);
} }
return frames; return frames;
} }
public static Chunk getLoadedChunk(IWorld world, int x, int z) { public static LevelChunk getLoadedChunk(Level level, 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
AbstractChunkProvider provider = world.getChunkProvider(); var provider = level.getChunkSource();
if (provider.isChunkLoaded(new ChunkPos(x, z))) if (provider.hasChunk(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) {
int a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio)); var a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio));
int r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio)); var r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio));
int g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio)); var g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio));
int b = (int) ((c1 & 0xFF) * ratio + (c2 & 0xFF) * (1 - ratio)); var 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.areItemsEqual(first, second)) if (!ItemStack.isSame(first, second))
return false; return false;
return !nbt || ItemStack.areItemStackTagsEqual(first, second); return !nbt || ItemStack.tagMatches(first, second);
} }
@OnlyIn(Dist.CLIENT) public static InteractionResult putStackOnTile(Player player, InteractionHand hand, BlockPos pos, int slot, boolean sound) {
public static void renderItemInGui(ItemStack stack, int x, int y, float scale) { var tile = player.level.getBlockEntity(pos);
RenderSystem.pushMatrix(); if (tile instanceof BlockEntityImpl) {
GlStateManager.enableBlend(); var handler = ((BlockEntityImpl) tile).getItemHandler();
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) {
ItemStack handStack = player.getHeldItem(hand); var handStack = player.getItemInHand(hand);
if (!handStack.isEmpty()) { if (!handStack.isEmpty()) {
ItemStack remain = handler.insertItem(slot, handStack, player.world.isRemote); var remain = handler.insertItem(slot, handStack, player.level.isClientSide);
if (!ItemStack.areItemStacksEqual(remain, handStack)) { if (!ItemStack.isSame(remain, handStack)) {
if (sound) if (sound)
player.world.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, SoundCategory.PLAYERS, 0.75F, 1F); SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
if (!player.world.isRemote) if (!player.level.isClientSide)
player.setHeldItem(hand, remain); player.setItemInHand(hand, remain);
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
} }
if (!handler.getStackInSlot(slot).isEmpty()) { if (!handler.getStackInSlot(slot).isEmpty()) {
if (sound) if (sound)
player.world.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, SoundCategory.PLAYERS, 0.75F, 1F); SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
if (!player.world.isRemote) { if (!player.level.isClientSide) {
ItemStack stack = handler.getStackInSlot(slot); var stack = handler.getStackInSlot(slot);
if (!player.addItemStackToInventory(stack)) { if (!player.addItem(stack)) {
ItemEntity item = new ItemEntity(player.world, player.getPosX(), player.getPosY(), player.getPosZ(), stack); var item = new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), stack);
player.world.addEntity(item); player.level.addFreshEntity(item);
} }
handler.setStackInSlot(slot, ItemStack.EMPTY); handler.setStackInSlot(slot, ItemStack.EMPTY);
} }
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
} }
} }
return ActionResultType.CONSUME; return InteractionResult.CONSUME;
} }
public static ICapabilityProvider makeRechargeProvider(ItemStack stack, boolean needsSelected) { public static ICapabilityProvider makeRechargeProvider(ItemStack stack, boolean needsSelected) {
@ -191,8 +168,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.getDamage() > 0 && container.drainAura(toDrain, true) >= toDrain) { if (stack.getDamageValue() > 0 && container.drainAura(toDrain, true) >= toDrain) {
stack.setDamage(stack.getDamage() - 1); stack.setDamageValue(stack.getDamageValue() - 1);
container.drainAura(toDrain, false); container.drainAura(toDrain, false);
return true; return true;
} }
@ -200,15 +177,15 @@ public final class Helper {
} }
public static BlockState getStateFromString(String raw) { public static BlockState getStateFromString(String raw) {
String[] split = raw.split("\\["); var split = raw.split("\\[");
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0])); var block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0]));
if (block != null) { if (block != null) {
BlockState state = block.getDefaultState(); var state = block.defaultBlockState();
if (split.length > 1) { if (split.length > 1) {
for (String part : split[1].replace("]", "").split(",")) { for (var part : split[1].replace("]", "").split(",")) {
String[] keyValue = part.split("="); var keyValue = part.split("=");
for (Property<?> prop : state.getProperties()) { for (var prop : state.getProperties()) {
BlockState changed = findProperty(state, prop, keyValue[0], keyValue[1]); var changed = findProperty(state, prop, keyValue[0], keyValue[1]);
if (changed != null) { if (changed != null) {
state = changed; state = changed;
break; break;
@ -223,39 +200,23 @@ 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 (T value : prop.getAllowedValues()) for (var value : prop.getPossibleValues())
if (prop.getName(value).equals(newValue)) if (prop.getName(value).equals(newValue))
return state.with(prop, value); return state.setValue(prop, value);
return null; return null;
} }
public static <T> void registerCap(Class<T> type) { public static void addAdvancement(Player player, ResourceLocation advancement, String criterion) {
CapabilityManager.INSTANCE.register(type, new Capability.IStorage<T>() { if (!(player instanceof ServerPlayer playerMp))
@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;
ServerPlayerEntity playerMp = (ServerPlayerEntity) player; var adv = playerMp.getLevel().getServer().getAdvancements().getAdvancement(advancement);
Advancement adv = playerMp.getServerWorld().getServer().getAdvancementManager().getAdvancement(advancement);
if (adv != null) if (adv != null)
playerMp.getAdvancements().grantCriterion(adv, criterion); playerMp.getAdvancements().award(adv, criterion);
} }
public static int getIngredientAmount(Ingredient ingredient) { public static int getIngredientAmount(Ingredient ingredient) {
int highestAmount = 0; var highestAmount = 0;
for (ItemStack stack : ingredient.getMatchingStacks()) for (var stack : ingredient.getItems())
if (stack.getCount() > highestAmount) if (stack.getCount() > highestAmount)
highestAmount = stack.getCount(); highestAmount = stack.getCount();
return highestAmount; return highestAmount;
@ -289,9 +250,9 @@ public final class Helper {
GL11.glVertex3d(x, y, z); GL11.glVertex3d(x, y, z);
} }
public static boolean isHoldingItem(PlayerEntity player, Item item) { public static boolean isHoldingItem(Player player, Item item) {
for (Hand hand : Hand.values()) { for (var hand : InteractionHand.values()) {
ItemStack stack = player.getHeldItem(hand); var stack = player.getItemInHand(hand);
if (!stack.isEmpty() && stack.getItem() == item) if (!stack.isEmpty() && stack.getItem() == item)
return true; return true;
} }
@ -299,22 +260,22 @@ public final class Helper {
} }
public static boolean isEmpty(IItemHandler handler) { public static boolean isEmpty(IItemHandler handler) {
for (int i = 0; i < handler.getSlots(); i++) for (var 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 AxisAlignedBB aabb(Vector3d pos) { public static AABB aabb(Vec3 pos) {
return new AxisAlignedBB(pos.x, pos.y, pos.z, pos.x, pos.y, pos.z); return new AABB(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 (Field entry : clazz.getFields()) { for (var entry : clazz.getFields()) {
if (!Modifier.isStatic(entry.getModifiers())) if (!Modifier.isStatic(entry.getModifiers()))
continue; continue;
ResourceLocation location = new ResourceLocation(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT)); var 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;
@ -327,14 +288,15 @@ public final class Helper {
} }
} }
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, PlayerEntity player) { public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, Player player) {
if (Compat.hasCompat("curios")) { // TODO 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 (int i = 0; i < player.inventory.getSizeInventory(); i++) { for (var i = 0; i < player.getInventory().getContainerSize(); i++) {
ItemStack slot = player.inventory.getStackInSlot(i); var slot = player.getInventory().getItem(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.IWorldData; import de.ellpeck.naturesaura.api.misc.ILevelData;
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.WorldData; import de.ellpeck.naturesaura.misc.LevelData;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.Player;
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.world.World; import net.minecraft.level.Level;
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(PlayerEntity player, int amount, boolean simulate) { public boolean extractAuraFromPlayer(Player player, int amount, boolean simulate) {
return this.auraPlayerInteraction(player, amount, true, simulate); return this.auraPlayerInteraction(player, amount, true, simulate);
} }
@Override @Override
public boolean insertAuraIntoPlayer(PlayerEntity player, int amount, boolean simulate) { public boolean insertAuraIntoPlayer(Player player, int amount, boolean simulate) {
return this.auraPlayerInteraction(player, amount, false, simulate); return this.auraPlayerInteraction(player, amount, false, simulate);
} }
private boolean auraPlayerInteraction(PlayerEntity player, int amount, boolean extract, boolean simulate) { private boolean auraPlayerInteraction(Player 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(World world, AxisAlignedBB area, ResourceLocation name) { public List<Tuple<Vector3d, Integer>> getActiveEffectPowders(Level level, AxisAlignedBB area, ResourceLocation name) {
List<Tuple<Vector3d, Integer>> found = new ArrayList<>(); List<Tuple<Vector3d, Integer>> found = new ArrayList<>();
for (Tuple<Vector3d, Integer> powder : ((WorldData) IWorldData.getWorldData(world)).effectPowders.get(name)) for (Tuple<Vector3d, Integer> powder : ((LevelData) ILevelData.getLevelData(level)).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(World world, BlockPos pos, ResourceLocation name) { public boolean isEffectPowderActive(Level level, 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(world, new AxisAlignedBB(pos).grow(64), name); List<Tuple<Vector3d, Integer>> powders = this.getActiveEffectPowders(level, 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(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) { public void getAuraSpotsInArea(Level level, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
Helper.getAuraChunksWithSpotsInArea(world, pos, radius, chunk -> chunk.getSpotsInArea(pos, radius, consumer)); Helper.getAuraChunksWithSpotsInArea(level, pos, radius, chunk -> chunk.getSpotsInArea(pos, radius, consumer));
} }
@Override @Override
public int getSpotAmountInArea(World world, BlockPos pos, int radius) { public int getSpotAmountInArea(Level level, BlockPos pos, int radius) {
MutableInt result = new MutableInt(); MutableInt result = new MutableInt();
this.getAuraSpotsInArea(world, pos, radius, (blockpos, drainSpot) -> result.increment()); this.getAuraSpotsInArea(level, pos, radius, (blockpos, drainSpot) -> result.increment());
return result.intValue(); return result.intValue();
} }
@Override @Override
public int getAuraInArea(World world, BlockPos pos, int radius) { public int getAuraInArea(Level level, BlockPos pos, int radius) {
MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA); MutableInt result = new MutableInt(IAuraChunk.DEFAULT_AURA);
this.getAuraSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot)); this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> result.add(drainSpot));
return result.intValue(); return result.intValue();
} }
@Override @Override
public Pair<Integer, Integer> getAuraAndSpotAmountInArea(World world, BlockPos pos, int radius) { public Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, 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(world, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(level, 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(World world, BlockPos pos, int radius) { public int triangulateAuraInArea(Level level, BlockPos pos, int radius) {
MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA); MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA);
IAuraChunk.getSpotsInArea(world, pos, radius, (blockPos, spot) -> { IAuraChunk.getSpotsInArea(level, 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(World world, BlockPos pos, int radius, BlockPos defaultSpot) { public BlockPos getLowestAuraDrainSpot(Level level, 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(world, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(level, 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(World world, BlockPos pos, int radius, BlockPos defaultSpot) { public BlockPos getHighestAuraDrainSpot(Level level, 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(world, pos, radius, (blockPos, drainSpot) -> { this.getAuraSpotsInArea(level, 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> debugWorld; public ConfigValue<Boolean> debugLevel;
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 world") .comment("If Aura Blooms and Aura Cacti should generate in the level")
.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.debugWorld = builder this.debugLevel = 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 world 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 level for debug purposes")
.translation("config." + NaturesAura.MOD_ID + ".debugWorld") .translation("config." + NaturesAura.MOD_ID + ".debugLevel")
.define("debugWorld", false); .define("debugLevel", 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.IWorldData; import de.ellpeck.naturesaura.api.misc.ILevelData;
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,11 +17,10 @@ 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.item.ItemGroup; import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.item.ItemStack; import net.minecraft.world.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;
@ -37,9 +36,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 ItemGroup CREATIVE_TAB = new ItemGroup(MOD_ID) { public static final CreativeModeTab CREATIVE_TAB = new CreativeModeTab(MOD_ID) {
@Override @Override
public ItemStack createIcon() { public ItemStack makeIcon() {
return new ItemStack(ModItems.GOLD_LEAF); return new ItemStack(ModItems.GOLD_LEAF);
} }
}; };
@ -65,7 +64,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(IWorldData.class); Helper.registerCap(ILevelData.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.IWorldData; import de.ellpeck.naturesaura.api.misc.ILevelData;
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.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.entity.EntityType; import net.minecraft.resources.ResourceLocation;
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.util.math.AxisAlignedBB; import net.minecraft.world.entity.EntityType;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.IWorld; import net.minecraft.world.level.Level;
import net.minecraft.world.World; import net.minecraft.world.level.block.state.BlockState;
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.CapabilityInject; import net.minecraftforge.common.capabilities.CapabilityManager;
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 of the block states that the Botanist's Pickaxe can convert * A map of all 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 worlds. {@link BasicAuraType} instances can be * in different types of levels. {@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"), World.field_234918_g_, 0x89cc37, 0).register(); public static final BasicAuraType TYPE_OVERWORLD = new BasicAuraType(new ResourceLocation(MOD_ID, "overworld"), Level.OVERWORLD, 0x89cc37, 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_NETHER = new BasicAuraType(new ResourceLocation(MOD_ID, "nether"), Level.NETHER, 0x871c0c, 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_END = new BasicAuraType(new ResourceLocation(MOD_ID, "end"), Level.END, 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
* world. These effects include things like vegetational increase and * level. 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(World, * powder is active in any given area, use {@link IInternalHooks#isEffectPowderActive(Level,
* 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,48 +90,50 @@ 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 of netherrack blocks in the nether * spawn inside 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 of the entities' registry names to the amounts of aura they * A map of all 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 of the items that cause the {@link WeatherType} to be * A map of all the items that cause the {@link WeatherType} to be changed
* changed using the weather changer * 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}
*/ */
@CapabilityInject(IAuraContainer.class) public static Capability<IAuraContainer> capAuraContainer = CapabilityManager.get(new CapabilityToken<>() {
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
*/ */
@CapabilityInject(IAuraRecharge.class) public static Capability<IAuraRecharge> capAuraRecharge = CapabilityManager.get(new CapabilityToken<>() {
public static Capability<IAuraRecharge> capAuraRecharge; });
/** /**
* The capability that any chunk in a world has to store Aura in it. As this * The capability that any chunk in a level has to store Aura in it. As this
* is only applicable to chunks and all chunks in the world automatically * is only applicable to chunks and all chunks in the level 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(IWorld, BlockPos)}. * helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level,
* BlockPos)}.
*/ */
@CapabilityInject(IAuraChunk.class) public static Capability<IAuraChunk> capAuraChunk = CapabilityManager.get(new CapabilityToken<>() {
public static Capability<IAuraChunk> capAuraChunk; });
/** /**
* The capability that any world has to store Nature's Aura specific data in * The capability that any level has to store Nature's Aura specific data in
* it. To retrieve this capability from any world, use the helper methods * it. To retrieve this capability from any level, use the helper methods
* {@link IWorldData#getWorldData(World)} or {@link IWorldData#getOverworldData(World)}. * {@link ILevelData#getLevelData(net.minecraft.world.level.Level)} or
* {@link ILevelData#getOverworldData(net.minecraft.world.level.Level)}.
*/ */
@CapabilityInject(IWorldData.class) public static Capability<ILevelData> capLevelData = CapabilityManager.get(new CapabilityToken<>() {
public static Capability<IWorldData> capWorldData; });
private static final IInternalHooks INSTANCE; private static final IInternalHooks INSTANCE;
static { static {
@ -169,7 +171,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(PlayerEntity player, int amount, boolean simulate); boolean extractAuraFromPlayer(Player 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
@ -181,7 +183,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(PlayerEntity player, int amount, boolean simulate); boolean insertAuraIntoPlayer(Player 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
@ -262,65 +264,65 @@ public final class NaturesAuraAPI {
IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers); IMultiblock createMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers);
/** /**
* Get all of the active effect powders in the given area and consume * Get all the active effect powders in the given area and consume the
* the position and the range that they have. To register a powder with * position and the range that they have. To register a powder with the
* the supplied name, use {@link #EFFECT_POWDERS} * supplied name, use {@link #EFFECT_POWDERS}
* *
* @param world The world * @param level The level
* @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<Vector3d, Integer>> getActiveEffectPowders(World world, AxisAlignedBB area, ResourceLocation name); List<Tuple<Vec3, Integer>> getActiveEffectPowders(Level level, AABB 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(World, * shorthand function of {@link #getActiveEffectPowders(Level,
* AxisAlignedBB, ResourceLocation)} that returns true if the list is * net.minecraft.world.phys.AABB, ResourceLocation)} that returns true
* non-empty * if the list is non-empty
* *
* @param world The world * @param level The level
* @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(World world, BlockPos pos, ResourceLocation name); boolean isEffectPowderActive(Level level, BlockPos pos, ResourceLocation name);
/** /**
* @see IAuraChunk#getSpotsInArea(IWorld, BlockPos, int, BiConsumer) * @see IAuraChunk#getSpotsInArea(Level, BlockPos, int, BiConsumer)
*/ */
void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer); void getAuraSpotsInArea(Level level, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer);
/** /**
* @see IAuraChunk#getSpotAmountInArea(IWorld, BlockPos, int) * @see IAuraChunk#getSpotAmountInArea(Level, BlockPos, int)
*/ */
int getSpotAmountInArea(World world, BlockPos pos, int radius); int getSpotAmountInArea(Level level, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#getAuraInArea(IWorld, BlockPos, int) * @see IAuraChunk#getAuraInArea(Level, BlockPos, int)
*/ */
int getAuraInArea(World world, BlockPos pos, int radius); int getAuraInArea(Level level, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#getAuraAndSpotAmountInArea(World, BlockPos, int) * @see IAuraChunk#getAuraAndSpotAmountInArea(Level, BlockPos, int)
*/ */
Pair<Integer, Integer> getAuraAndSpotAmountInArea(World world, BlockPos pos, int radius); Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#triangulateAuraInArea(IWorld, BlockPos, int) * @see IAuraChunk#triangulateAuraInArea(Level, BlockPos, int)
*/ */
int triangulateAuraInArea(World world, BlockPos pos, int radius); int triangulateAuraInArea(Level level, BlockPos pos, int radius);
/** /**
* @see IAuraChunk#getLowestSpot(IWorld, BlockPos, int, BlockPos) * @see IAuraChunk#getLowestSpot(Level, BlockPos, int, BlockPos)
*/ */
BlockPos getLowestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot); BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot);
/** /**
* @see IAuraChunk#getHighestSpot(IWorld, BlockPos, int, BlockPos) * @see IAuraChunk#getHighestSpot(Level, BlockPos, int, BlockPos)
*/ */
BlockPos getHighestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot); BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot);
} }
} }

View file

@ -2,11 +2,10 @@ 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.nbt.CompoundNBT; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.IWorld; import net.minecraft.world.level.Level;
import net.minecraft.world.World; import net.minecraft.world.level.chunk.LevelChunk;
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;
@ -14,13 +13,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 Chunk}. To get an instance for a chunk, use {@link * {@link net.minecraft.world.level.chunk.LevelChunk}. To get an instance for a
* #getAuraChunk(IWorld, BlockPos)}. * chunk, use {@link #getAuraChunk(Level, 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<CompoundNBT> { public interface IAuraChunk extends INBTSerializable<CompoundTag> {
/** /**
* The default amount of Aura that a chunk has stored * The default amount of Aura that a chunk has stored
@ -31,12 +30,12 @@ public interface IAuraChunk extends INBTSerializable<CompoundNBT> {
* 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 world The world * @param level The level
* @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(IWorld world, BlockPos pos) { static IAuraChunk getAuraChunk(Level level, BlockPos pos) {
Chunk chunk = (Chunk) world.getChunk(pos); LevelChunk chunk = (LevelChunk) level.getChunk(pos);
return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); return chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
} }
@ -45,78 +44,78 @@ public interface IAuraChunk extends INBTSerializable<CompoundNBT> {
* 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 world The world * @param level The level
* @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(IWorld world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) { static void getSpotsInArea(Level level, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
NaturesAuraAPI.instance().getAuraSpotsInArea((World) world, pos, radius, consumer); NaturesAuraAPI.instance().getAuraSpotsInArea(level, 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(IWorld, BlockPos, int, BiConsumer)} and returns it. * #getSpotsInArea(Level, BlockPos, int, BiConsumer)} and returns it.
* *
* @param world The world * @param level The level
* @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(IWorld world, BlockPos pos, int radius) { static int getSpotAmountInArea(Level level, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().getSpotAmountInArea((World) world, pos, radius); return NaturesAuraAPI.instance().getSpotAmountInArea(level, 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(IWorld, BlockPos, int, BiConsumer)} and * {@link #getSpotsInArea(Level, 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(IWorld, BlockPos, int)}. * increase, use {@link #triangulateAuraInArea(Level, BlockPos, int)}.
* *
* @param world The world * @param level The level
* @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(IWorld world, BlockPos pos, int radius) { static int getAuraInArea(Level level, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().getAuraInArea((World) world, pos, radius); return NaturesAuraAPI.instance().getAuraInArea(level, pos, radius);
} }
/** /**
* Convenience method that combines {@link #getAuraInArea(IWorld, BlockPos, * Convenience method that combines {@link #getAuraInArea(Level, BlockPos,
* int)} and {@link #getSpotAmountInArea(IWorld, BlockPos, int)} to increase * int)} and {@link #getSpotAmountInArea(Level, BlockPos, int)} to increase
* performance. * performance.
* *
* @param world The world * @param level The level
* @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(World world, BlockPos pos, int radius) { static Pair<Integer, Integer> getAuraAndSpotAmountInArea(Level level, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().getAuraAndSpotAmountInArea(world, pos, radius); return NaturesAuraAPI.instance().getAuraAndSpotAmountInArea(level, 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(IWorld, BlockPos, int, BiConsumer)}, but * {@link #getSpotsInArea(Level, BlockPos, int, BiConsumer)}, but multiplies
* multiplies their amount by the percentual distance to the supplied * their amount by the percentual distance to the supplied position. This
* position. This will cause for a lot more gradual of an increase and * will cause for a lot more gradual of an increase and decrease of Aura
* decrease of Aura when moving closer to actual spots. This should be used * when moving closer to actual spots. This should be used for visual
* for visual purposes as it is more performance intensive than {@link * purposes as it is more performance intensive than {@link
* #getAuraInArea(IWorld, BlockPos, int)}. * #getAuraInArea(Level, BlockPos, int)}.
* *
* @param world The world * @param level The level
* @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(IWorld world, BlockPos pos, int radius) { static int triangulateAuraInArea(Level level, BlockPos pos, int radius) {
return NaturesAuraAPI.instance().triangulateAuraInArea((World) world, pos, radius); return NaturesAuraAPI.instance().triangulateAuraInArea(level, pos, radius);
} }
/** /**
@ -126,15 +125,15 @@ public interface IAuraChunk extends INBTSerializable<CompoundNBT> {
* 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 world The world * @param level The level
* @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(IWorld world, BlockPos pos, int radius, BlockPos defaultSpot) { static BlockPos getLowestSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
return NaturesAuraAPI.instance().getLowestAuraDrainSpot((World) world, pos, radius, defaultSpot); return NaturesAuraAPI.instance().getLowestAuraDrainSpot(level, pos, radius, defaultSpot);
} }
/** /**
@ -144,15 +143,15 @@ public interface IAuraChunk extends INBTSerializable<CompoundNBT> {
* 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 world The world * @param level The level
* @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(IWorld world, BlockPos pos, int radius, BlockPos defaultSpot) { static BlockPos getHighestSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
return NaturesAuraAPI.instance().getHighestAuraDrainSpot((World) world, pos, radius, defaultSpot); return NaturesAuraAPI.instance().getHighestAuraDrainSpot(level, 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.entity.player.PlayerEntity; import net.minecraft.core.BlockPos;
import net.minecraft.item.ItemStack; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.level.Level;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.level.chunk.LevelChunk;
public interface IDrainSpotEffect { public interface IDrainSpotEffect {
void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot); void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot);
boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type); boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type);
ResourceLocation getName(); ResourceLocation getName();
default ActiveType isActiveHere(PlayerEntity player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { default ActiveType isActiveHere(Player player, LevelChunk 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
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(CompoundNBT compound) { public void writeNBT(CompoundTag compound) {
compound.putInt("aura", this.aura); compound.putInt("aura", this.aura);
} }
public void readNBT(CompoundNBT compound) { public void readNBT(CompoundTag 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
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 CompoundNBT()); this.stack.setTag(new CompoundTag());
} }
this.stack.getTag().putInt("aura", amount); this.stack.getTag().putInt("aura", amount);
} }

View file

@ -1,10 +1,9 @@
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.util.RegistryKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.IWorld; import net.minecraft.world.level.Level;
import net.minecraft.world.World;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -16,12 +15,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, RegistryKey<World> dimension, int color, int priority) { public BasicAuraType(ResourceLocation name, ResourceKey<Level> 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.func_240901_a_()); this.dimensions.add(dimension.location());
} }
public BasicAuraType register() { public BasicAuraType register() {
@ -35,8 +34,8 @@ public class BasicAuraType implements IAuraType {
} }
@Override @Override
public boolean isPresentInWorld(IWorld world) { public boolean isPresentInLevel(Level level) {
return this.dimensions.isEmpty() || this.dimensions.contains(((World) world).func_234923_W_().func_240901_a_()); return this.dimensions.isEmpty() || this.dimensions.contains(level.dimension().location());
} }
@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.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.IWorld; import net.minecraft.world.level.Level;
public interface IAuraType { public interface IAuraType {
static IAuraType forWorld(IWorld world) { static IAuraType forLevel(Level level) {
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.isPresentInWorld(world) && type.getPriority() > highestType.getPriority()) if (type.isPresentInLevel(level) && type.getPriority() > highestType.getPriority())
highestType = type; highestType = type;
return highestType; return highestType;
} }
ResourceLocation getName(); ResourceLocation getName();
boolean isPresentInWorld(IWorld world); boolean isPresentInLevel(Level level);
int getColor(); int getColor();

View file

@ -0,0 +1,25 @@
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

@ -1,25 +0,0 @@
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.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.WeightedRandom; import net.minecraft.util.random.WeightedEntry;
public class WeightedOre extends WeightedRandom.Item { public class WeightedOre extends WeightedEntry.IntrusiveBase {
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.util.ResourceLocation; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.level.Level;
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(World world, BlockPos center); boolean isComplete(Level level, 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.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.tags.Tag;
import net.minecraft.block.Blocks; import net.minecraft.world.level.Level;
import net.minecraft.tags.ITag; import net.minecraft.world.level.block.Block;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.World; import net.minecraft.world.level.block.state.BlockState;
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.getDefaultState(), null); return new Matcher(Blocks.AIR.defaultBlockState(), null);
} }
public static Matcher tag(Block defaultBlock, ITag.INamedTag tag) { public static Matcher tag(Block defaultBlock, Tag.Named<?> tag) {
return new Matcher(defaultBlock.getDefaultState(), (world, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName())); return new Matcher(defaultBlock.defaultBlockState(), (level, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName()));
} }
public BlockState getDefaultState() { public BlockState getDefaultState() {
@ -34,6 +34,7 @@ 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.PlayerEntity; import net.minecraft.entity.player.Player;
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, PlayerEntity player, RenderType type, MatrixStack matrices, IRenderTypeBuffer buffer, int packedLight, boolean isHolding); void render(ItemStack stack, Player 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.world.World; import net.minecraft.level.Level;
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(World world, BlockPos pos); AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos);
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
int getVisualizationColor(World world, BlockPos pos); int getVisualizationColor(Level level, 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.TileEntityAncientLeaves; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAncientLeaves;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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<>(TileEntityAncientLeaves::new, this)); ModRegistry.add(new ModTileType<>(BlockEntityAncientLeaves::new, this));
} }
@Override @Override
@ -37,19 +37,19 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
@Nullable @Nullable
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createBlockEntity(BlockState state, IBlockReader level) {
return new TileEntityAncientLeaves(); return new BlockEntityAncientLeaves();
} }
@Override @Override
public boolean hasTileEntity(BlockState state) { public boolean hasBlockEntity(BlockState state) {
return true; return true;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public IBlockColor getBlockColor() {
return (state, worldIn, pos, tintIndex) -> 0xE55B97; return (state, levelIn, 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, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
super.animateTick(stateIn, worldIn, pos, rand); super.animateTick(stateIn, levelIn, pos, rand);
if (rand.nextFloat() >= 0.95F && !worldIn.getBlockState(pos.down()).isOpaqueCube(worldIn, pos)) { if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.down()).isOpaqueCube(levelIn, pos)) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityAncientLeaves) { if (tile instanceof BlockEntityAncientLeaves) {
if (((TileEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) { if (((BlockEntityAncientLeaves) 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, ServerWorld worldIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.randomTick(state, worldIn, pos, random); super.randomTick(state, levelIn, pos, random);
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityAncientLeaves) { if (tile instanceof BlockEntityAncientLeaves) {
if (((TileEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) { if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) {
worldIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState()); levelIn.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.WorldGenAncientTree; import de.ellpeck.naturesaura.gen.LevelGenAncientTree;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random random) {
if (!world.isRemote) { if (!level.isClientSide) {
super.randomTick(state, world, pos, random); super.randomTick(state, level, pos, random);
if (world.getLight(pos.up()) >= 9 && random.nextInt(7) == 0) { if (level.getLight(pos.up()) >= 9 && random.nextInt(7) == 0) {
this.grow(world, random, pos, state); this.grow(level, random, pos, state);
} }
} }
} }
@ -55,21 +55,21 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
} }
@Override @Override
public boolean canGrow(IBlockReader worldIn, BlockPos pos, BlockState state, boolean isClient) { public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) {
return true; return true;
} }
@Override @Override
public boolean canUseBonemeal(World world, Random rand, BlockPos pos, BlockState state) { public boolean canUseBonemeal(Level level, Random rand, BlockPos pos, BlockState state) {
return world.rand.nextFloat() < 0.45F; return level.rand.nextFloat() < 0.45F;
} }
@Override @Override
public void grow(ServerWorld world, Random rand, BlockPos pos, BlockState state) { public void grow(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
if (state.get(SaplingBlock.STAGE) == 0) { if (state.get(SaplingBlock.STAGE) == 0) {
world.setBlockState(pos, state.func_235896_a_(SaplingBlock.STAGE), 4); level.setBlockState(pos, state.func_235896_a_(SaplingBlock.STAGE), 4);
} else if (ForgeEventFactory.saplingGrowTree(world, rand, pos)) { } else if (ForgeEventFactory.saplingGrowTree(level, rand, pos)) {
ModFeatures.ANCIENT_TREE.func_241855_a(world, world.getChunkProvider().getChunkGenerator(), rand, pos, WorldGenAncientTree.CONFIG); ModFeatures.ANCIENT_TREE.func_241855_a(level, level.getChunkProvider().getChunkGenerator(), rand, pos, LevelGenAncientTree.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.TileEntityAnimalContainer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalContainer;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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", TileEntityAnimalContainer::new, Properties.from(Blocks.STONE)); super("animal_container", BlockEntityAnimalContainer::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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos); BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof TileEntityAnimalContainer) { if (tile instanceof BlockEntityAnimalContainer) {
int radius = ((TileEntityAnimalContainer) tile).getRadius(); int radius = ((BlockEntityAnimalContainer) 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntityAnimalGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalGenerator;
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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
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.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.world.World; import net.minecraft.level.Level;
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", TileEntityAnimalGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("animal_generator", BlockEntityAnimalGenerator::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.world.isRemote || entity.world.getGameTime() % 40 != 0 || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC) if (entity.level.isClientSide || entity.level.getGameTime() % 40 != 0 || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC)
return; return;
CompoundNBT data = entity.getPersistentData(); CompoundTag 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.world.isRemote || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC) if (entity.level.isClientSide || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC)
return; return;
BlockPos pos = entity.getPosition(); BlockPos pos = entity.getPosition();
Helper.getTileEntitiesInArea(entity.world, pos, 5, tile -> { Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> {
if (!(tile instanceof TileEntityAnimalGenerator)) if (!(tile instanceof BlockEntityAnimalGenerator))
return false; return false;
TileEntityAnimalGenerator gen = (TileEntityAnimalGenerator) tile; BlockEntityAnimalGenerator gen = (BlockEntityAnimalGenerator) tile;
CompoundNBT data = entity.getPersistentData(); CompoundTag 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(MathHelper.floor((timeAlive - 15000) / 500F * timeMod), 200); int time = Math.min(Mth.floor((timeAlive - 15000) / 500F * timeMod), 200);
int amount = Math.min(MathHelper.floor((timeAlive - 8000) / 2F * amountMod), 25000); int amount = Math.min(Mth.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.world, pos, 32, new PacketParticles( PacketHandler.sendToAllAround(entity.level, 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(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntityAnimalSpawner; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalSpawner;
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", TileEntityAnimalSpawner::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("animal_spawner", BlockEntityAnimalSpawner::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.TileEntityAuraBloom; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.IWorldReader; import net.minecraft.level.ILevelReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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, IWorldReader worldIn, BlockPos pos) { public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) {
BlockPos down = pos.down(); BlockPos down = pos.down();
return this.isValidGround(worldIn.getBlockState(down), worldIn, down); return this.isValidGround(levelIn.getBlockState(down), levelIn, down);
} }
@Override @Override
protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) { protected boolean isValidGround(BlockState state, IBlockReader levelIn, 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, World worldIn, BlockPos pos, Entity entityIn) { public void onEntityCollision(BlockState state, Level levelIn, 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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
Vector3d vec3d = state.getOffset(worldIn, pos); Vector3d vec3d = state.getOffset(levelIn, 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 TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createBlockEntity(BlockState state, IBlockReader level) {
return new TileEntityAuraBloom(); return new BlockEntityAuraBloom();
} }
@Override @Override
public boolean hasTileEntity(BlockState state) { public boolean hasBlockEntity(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.TileEntityAuraDetector; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraDetector;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.level.Level;
public class BlockAuraDetector extends BlockContainerImpl { public class BlockAuraDetector extends BlockContainerImpl {
public BlockAuraDetector() { public BlockAuraDetector() {
super("aura_detector", TileEntityAuraDetector::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("aura_detector", BlockEntityAuraDetector::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, World worldIn, BlockPos pos) { public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityAuraDetector) if (tile instanceof BlockEntityAuraDetector)
return ((TileEntityAuraDetector) tile).redstonePower; return ((BlockEntityAuraDetector) 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.TileEntityAuraTimer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer;
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.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.entity.player.Player;
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.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.ActionResultType; import net.minecraft.util.InteractionResult;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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<TileEntityAuraTimer>, ICustomRenderType { public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<BlockEntityAuraTimer>, 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", TileEntityAuraTimer::new, Properties.from(Blocks.SMOOTH_STONE)); super("aura_timer", BlockEntityAuraTimer::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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public Tuple<TileEntityType<TileEntityAuraTimer>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityAuraTimer>>>> getTESR() { public Tuple<BlockEntityType<BlockEntityAuraTimer>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityAuraTimer>>>> 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 ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) { public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player 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 world, BlockPos pos, Direction side) { public int getWeakPower(BlockState state, IBlockReader level, 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, ServerWorld worldIn, BlockPos pos, Random random) { public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.tick(state, worldIn, pos, random); super.tick(state, levelIn, pos, random);
if (state.get(BlockStateProperties.POWERED)) if (state.get(BlockStateProperties.POWERED))
worldIn.setBlockState(pos, state.with(BlockStateProperties.POWERED, false)); levelIn.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.TileEntityAutoCrafter; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAutoCrafter;
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", TileEntityAutoCrafter::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD)); super("auto_crafter", BlockEntityAutoCrafter::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.TileEntityBlastFurnaceBooster; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityBlastFurnaceBooster;
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.VoxelShapes; import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.world.IBlockReader; import net.minecraft.level.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 = VoxelShapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F); private static final VoxelShape SHAPE = Shapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F);
public BlockBlastFurnaceBooster() { public BlockBlastFurnaceBooster() {
super("blast_furnace_booster", TileEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE).setLightLevel(s -> 0)); super("blast_furnace_booster", BlockEntityBlastFurnaceBooster::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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, 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.forWorld(context.getWorld()).isSimilar(NaturesAuraAPI.TYPE_NETHER); boolean nether = IAuraType.forLevel(context.getLevel()).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.TileEntityChorusGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChorusGenerator;
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", TileEntityChorusGenerator::new, Properties.from(Blocks.END_STONE)); super("chorus_generator", BlockEntityChorusGenerator::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.TileEntityChunkLoader; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChunkLoader;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.MathHelper; import net.minecraft.util.math.Mth;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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", TileEntityChunkLoader::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("chunk_loader", BlockEntityChunkLoader::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(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos); BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof TileEntityChunkLoader) { if (tile instanceof BlockEntityChunkLoader) {
int range = ((TileEntityChunkLoader) tile).range(); int range = ((BlockEntityChunkLoader) 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,
world.getHeight(), level.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, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
if (!ModConfig.instance.chunkLoader.get()) if (!ModConfig.instance.chunkLoader.get())
return; return;
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityChunkLoader) { if (tile instanceof BlockEntityChunkLoader) {
int range = ((TileEntityChunkLoader) tile).range(); int range = ((BlockEntityChunkLoader) tile).range();
for (int i = MathHelper.ceil(range / 8F); i > 0; i--) { for (int i = Mth.ceil(range / 8F); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + worldIn.rand.nextFloat(), pos.getY() + worldIn.rand.nextFloat(), pos.getZ() + worldIn.rand.nextFloat(), pos.getX() + levelIn.rand.nextFloat(), pos.getY() + levelIn.rand.nextFloat(), pos.getZ() + levelIn.rand.nextFloat(),
0, 0, 0, 0xa12dff, 1F + worldIn.rand.nextFloat(), 100, 0, false, true); 0, 0, 0, 0xa12dff, 1F + levelIn.rand.nextFloat(), 100, 0, false, true);
} }
} }
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public int getVisualizationColor(World world, BlockPos pos) { public int getVisualizationColor(Level level, BlockPos pos) {
return 0xc159f9; return 0xc159f9;
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, 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 worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { public void addInformation(ItemStack stack, @Nullable IBlockReader levelIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn); super.addInformation(stack, levelIn, tooltip, flagIn);
} }
@Override @Override

View file

@ -1,40 +1,42 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
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.PlayerEntity; import net.minecraft.entity.player.Player;
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.IBlockReader; import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.IWorld; import net.minecraft.world.level.block.Block;
import net.minecraft.world.World; import net.minecraft.world.level.block.entity.BlockEntity;
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 ContainerBlock implements IModItem { public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
private final String baseName; private final String baseName;
private final ModTileType<? extends TileEntity> tileType; private final ModTileType<? extends BlockEntity> tileType;
public BlockContainerImpl(String baseName, Supplier<TileEntity> tileSupplier, Block.Properties properties) { public BlockContainerImpl(String baseName, Supplier<BlockEntity> tileSupplier, Block.Properties properties) {
super(properties); super(properties);
this.baseName = baseName; this.baseName = baseName;
@ -63,17 +65,17 @@ public class BlockContainerImpl extends ContainerBlock implements IModItem {
} }
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, ILevel levelIn, BlockPos currentPos, BlockPos facingPos) {
if (this.hasWaterlogging() && stateIn.get(BlockStateProperties.WATERLOGGED)) if (this.hasWaterlogging() && stateIn.get(BlockStateProperties.WATERLOGGED))
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); levelIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(levelIn));
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); return super.updatePostPlacement(stateIn, facing, facingState, levelIn, 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.getWorld().getFluidState(context.getPos()); FluidState state = context.getLevel().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);
@ -81,7 +83,7 @@ public class BlockContainerImpl extends ContainerBlock implements IModItem {
@Nullable @Nullable
@Override @Override
public TileEntity createNewTileEntity(IBlockReader worldIn) { public BlockEntity createNewBlockEntity(IBlockReader levelIn) {
return this.tileType.type.create(); return this.tileType.type.create();
} }
@ -96,20 +98,20 @@ public class BlockContainerImpl extends ContainerBlock implements IModItem {
} }
@Override @Override
public void onPlayerDestroy(IWorld worldIn, BlockPos pos, BlockState state) { public void onPlayerDestroy(ILevel levelIn, BlockPos pos, BlockState state) {
super.onPlayerDestroy(worldIn, pos, state); super.onPlayerDestroy(levelIn, 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);
TileEntity tile = builder.get(LootParameters.BLOCK_ENTITY); BlockEntity tile = builder.get(LootParameters.BLOCK_ENTITY);
if (tile instanceof TileEntityImpl) { if (tile instanceof BlockEntityImpl) {
for (ItemStack stack : drops) { for (ItemStack stack : drops) {
if (stack.getItem() != this.asItem()) if (stack.getItem() != this.asItem())
continue; continue;
((TileEntityImpl) tile).modifyDrop(stack); ((BlockEntityImpl) tile).modifyDrop(stack);
break; break;
} }
} }
@ -117,57 +119,57 @@ public class BlockContainerImpl extends ContainerBlock implements IModItem {
} }
@Override @Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { public void onReplaced(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) { if (state.getBlock() != newState.getBlock()) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityImpl) if (tile instanceof BlockEntityImpl)
((TileEntityImpl) tile).dropInventory(); ((BlockEntityImpl) tile).dropInventory();
} }
super.onReplaced(state, worldIn, pos, newState, isMoving); super.onReplaced(state, levelIn, pos, newState, isMoving);
} }
@Override @Override
public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) { public void harvestBlock(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack); super.harvestBlock(levelIn, player, pos, state, te, stack);
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); levelIn.setBlockState(pos, Blocks.AIR.getDefaultState());
} }
@Override @Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { public void onBlockPlacedBy(Level levelIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityImpl) if (tile instanceof BlockEntityImpl)
((TileEntityImpl) tile).loadDataOnPlace(stack); ((BlockEntityImpl) tile).loadDataOnPlace(stack);
} }
@Override @Override
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { public void onBlockAdded(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) {
this.updateRedstoneState(worldIn, pos); this.updateRedstoneState(levelIn, pos);
} }
@Override @Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { public void neighborChanged(BlockState state, Level levelIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
this.updateRedstoneState(worldIn, pos); this.updateRedstoneState(levelIn, pos);
} }
private void updateRedstoneState(World world, BlockPos pos) { private void updateRedstoneState(Level level, BlockPos pos) {
if (!world.isRemote) { if (!level.isClientSide) {
TileEntity tile = world.getTileEntity(pos); BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof TileEntityImpl) { if (tile instanceof BlockEntityImpl) {
TileEntityImpl impl = (TileEntityImpl) tile; BlockEntityImpl impl = (BlockEntityImpl) tile;
int newPower = world.getRedstonePowerFromNeighbors(pos); int newPower = level.getRedstonePowerFromNeighbors(pos);
if (impl.redstonePower != newPower) if (impl.redstonePower != newPower)
world.getPendingBlockTicks().scheduleTick(pos, this, 4); level.getPendingBlockTicks().scheduleTick(pos, this, 4);
} }
} }
} }
@Override @Override
public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) { public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityImpl) { if (tile instanceof BlockEntityImpl) {
TileEntityImpl impl = (TileEntityImpl) tile; BlockEntityImpl impl = (BlockEntityImpl) tile;
int newPower = worldIn.getRedstonePowerFromNeighbors(pos); int newPower = levelIn.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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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, ServerWorld world, BlockPos pos, Random random) { public void tick(BlockState state, ServerLevel level, BlockPos pos, Random random) {
if (!world.isRemote) { if (!level.isClientSide) {
world.setBlockState(pos, Blocks.AIR.getDefaultState()); level.setBlockState(pos, Blocks.AIR.getDefaultState());
} }
} }
@ -34,7 +34,7 @@ public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState,
} }
@Override @Override
public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) { public int getOpacity(BlockState state, IBlockReader levelIn, 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.PlayerEntity; import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraft.world.gen.Heightmap; import net.minecraft.level.gen.Heightmap;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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<World> goalDim; private final RegistryKey<Level> goalDim;
private final RegistryKey<World>[] canUseDims; private final RegistryKey<Level>[] canUseDims;
public BlockDimensionRail(String name, RegistryKey<World> goalDim, RegistryKey<World>... canUseDims) { public BlockDimensionRail(String name, RegistryKey<Level> goalDim, RegistryKey<Level>... 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<World> dimension) { private boolean canUseHere(RegistryKey<Level> dimension) {
for (RegistryKey<World> dim : this.canUseDims) for (RegistryKey<Level> dim : this.canUseDims)
if (dim == dimension) if (dim == dimension)
return true; return true;
return false; return false;
} }
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player 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 (!worldIn.isRemote) { if (!levelIn.isClientSide) {
BlockPos goalPos = this.getGoalCoords(worldIn, pos); BlockPos goalPos = this.getGoalCoords(levelIn, pos);
CompoundNBT data = new CompoundNBT(); CompoundTag data = new CompoundTag();
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 ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
return ActionResultType.FAIL; return InteractionResult.FAIL;
} }
@Override @Override
public void onMinecartPass(BlockState state, World world, BlockPos pos, AbstractMinecartEntity cart) { public void onMinecartPass(BlockState state, Level level, BlockPos pos, AbstractMinecartEntity cart) {
if (world.isRemote) if (level.isClientSide)
return; return;
if (cart.isBeingRidden()) if (cart.isBeingRidden())
return; return;
if (!this.canUseHere(world.func_234923_W_())) if (!this.canUseHere(level.func_234923_W_()))
return; return;
AxisAlignedBB box = cart.getBoundingBox(); AxisAlignedBB box = cart.getBoundingBox();
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))); 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)));
world.playSound(null, pos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 1F); level.playSound(null, pos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 1F);
BlockPos goalCoords = this.getGoalCoords(world, pos); BlockPos goalCoords = this.getGoalCoords(level, pos);
cart.changeDimension(world.getServer().getWorld(this.goalDim), new ITeleporter() { cart.changeDimension(level.getServer().getLevel(this.goalDim), new ITeleporter() {
@Override @Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) { public Entity placeEntity(Entity entity, ServerLevel currentLevel, ServerLevel destLevel, 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.world.getProfiler().endStartSection("reloading"); entity.level.getProfiler().endStartSection("reloading");
Entity result = entity.getType().create(destWorld); Entity result = entity.getType().create(destLevel);
if (result != null) { if (result != null) {
result.copyDataFromOld(entity); result.copyDataFromOld(entity);
destWorld.addFromAnotherDimension(result); destLevel.addFromAnotherDimension(result);
result.moveToBlockPosAndAngles(goalCoords, yaw, result.rotationPitch); result.moveToBlockPosAndAngles(goalCoords, yaw, result.rotationPitch);
} }
return result; return result;
} }
}); });
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, 35, pos); BlockPos spot = IAuraChunk.getHighestSpot(level, pos, 35, pos);
IAuraChunk.getAuraChunk(world, spot).drainAura(spot, 50000); IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 50000);
} }
private BlockPos getGoalCoords(World world, BlockPos pos) { private BlockPos getGoalCoords(Level level, BlockPos pos) {
MinecraftServer server = world.getServer(); MinecraftServer server = level.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 ServerWorld.field_241108_a_.up(8); return ServerLevel.field_241108_a_.up(8);
} else { } else {
if (world.func_234923_W_() == World.field_234919_h_) { if (level.func_234923_W_() == Level.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
ServerWorld overworld = server.getWorld(this.goalDim); ServerLevel overworld = server.getLevel(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 world, BlockPos pos) { public boolean isFlexibleRail(BlockState state, IBlockReader level, BlockPos pos) {
return false; return false;
} }
@Override @Override
public boolean canMakeSlopes(BlockState state, IBlockReader world, BlockPos pos) { public boolean canMakeSlopes(BlockState state, IBlockReader level, 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.TileEntityEndFlower; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEndFlower;
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.PlayerEntity; import net.minecraft.entity.player.Player;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.IWorldReader; import net.minecraft.level.ILevelReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraft.world.gen.Heightmap; import net.minecraft.level.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<>(TileEntityEndFlower::new, this)); ModRegistry.add(new ModTileType<>(BlockEntityEndFlower::new, this));
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
Vector3d vec3d = state.getOffset(worldIn, pos); Vector3d vec3d = state.getOffset(levelIn, 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.world.isRemote || !(living instanceof EnderDragonEntity)) if (living.level.isClientSide || !(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.world.rand.nextInt(256) - 128; int x = dragon.level.rand.nextInt(256) - 128;
int z = dragon.world.rand.nextInt(256) - 128; int z = dragon.level.rand.nextInt(256) - 128;
BlockPos pos = new BlockPos(x, dragon.world.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z); BlockPos pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z);
if (!dragon.world.isBlockLoaded(pos)) if (!dragon.level.isBlockLoaded(pos))
continue; continue;
if (dragon.world.getBlockState(pos.down()).getBlock() != Blocks.END_STONE) if (dragon.level.getBlockState(pos.down()).getBlock() != Blocks.END_STONE)
continue; continue;
dragon.world.setBlockState(pos, this.getDefaultState()); dragon.level.setBlockState(pos, this.getDefaultState());
} }
} }
@Override @Override
protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) { protected boolean isValidGround(BlockState state, IBlockReader levelIn, BlockPos pos) {
return state.getBlock() == Blocks.END_STONE; return state.getBlock() == Blocks.END_STONE;
} }
@Override @Override
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) { public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) {
return worldIn.getBlockState(pos.down()).getBlock() == Blocks.END_STONE; return levelIn.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 TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createBlockEntity(BlockState state, IBlockReader level) {
return new TileEntityEndFlower(); return new BlockEntityEndFlower();
} }
@Override @Override
public boolean hasTileEntity(BlockState state) { public boolean hasBlockEntity(BlockState state) {
return true; return true;
} }
@Override @Override
public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, FluidState fluid) { public boolean removedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest, fluid); return willHarvest || super.removedByPlayer(state, level, pos, player, willHarvest, fluid);
} }
@Override @Override
public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) { public void harvestBlock(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack); super.harvestBlock(levelIn, player, pos, state, te, stack);
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); levelIn.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) {
TileEntity tile = builder.get(LootParameters.BLOCK_ENTITY); BlockEntity tile = builder.get(LootParameters.BLOCK_ENTITY);
if (tile instanceof TileEntityEndFlower && ((TileEntityEndFlower) tile).isDrainMode) if (tile instanceof BlockEntityEndFlower && ((BlockEntityEndFlower) 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.IWorldData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities; import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityEnderCrate; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate;
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.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.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.PlayerEntity; import net.minecraft.entity.player.Player;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayer;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.ActionResultType; import net.minecraft.util.InteractionResult;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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<TileEntityEnderCrate>, ICustomBlockState { public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider<BlockEntityEnderCrate>, 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<World>> CACHED_WORLD = new ThreadLocal<>(); private static final ThreadLocal<WeakReference<Level>> CACHED_WORLD = new ThreadLocal<>();
public BlockEnderCrate() { public BlockEnderCrate() {
super("ender_crate", TileEntityEnderCrate::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).setLightLevel(s -> 7).sound(SoundType.STONE)); super("ender_crate", BlockEntityEnderCrate::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) {
World world = event.getWorld(); Level level = event.getLevel();
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
BlockState state = world.getBlockState(pos); BlockState state = level.getBlockState(pos);
if (state.getBlock() instanceof AnvilBlock) { if (state.getBlock() instanceof AnvilBlock) {
CACHED_WORLD.set(new WeakReference<>(world)); CACHED_WORLD.set(new WeakReference<>(level));
} }
} }
@SubscribeEvent @SubscribeEvent
public void onAnvilUpdate(AnvilUpdateEvent event) { public void onAnvilUpdate(AnvilUpdateEvent event) {
WeakReference<World> world = CACHED_WORLD.get(); WeakReference<Level> level = CACHED_WORLD.get();
if (world == null || world.get() == null) if (level == null || level.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 (IWorldData.getOverworldData(world.get()).isEnderStorageLocked(name)) if (ILevelData.getOverworldData(level.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 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) {
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityEnderCrate) { if (tile instanceof BlockEntityEnderCrate) {
TileEntityEnderCrate crate = (TileEntityEnderCrate) tile; BlockEntityEnderCrate crate = (BlockEntityEnderCrate) tile;
if (crate.canOpen()) { if (crate.canOpen()) {
crate.drainAura(2500); crate.drainAura(2500);
NetworkHooks.openGui((ServerPlayerEntity) player, crate, pos); NetworkHooks.openGui((ServerPlayer) player, crate, pos);
} }
} }
} }
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { public void addInformation(ItemStack stack, @Nullable IBlockReader levelIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
addEnderNameInfo(stack, tooltip); addEnderNameInfo(stack, tooltip);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, 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;
worldIn.addParticle(ParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5); levelIn.addParticle(ParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5);
} }
} }
@Override @Override
public Tuple<TileEntityType<TileEntityEnderCrate>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityEnderCrate>>>> getTESR() { public Tuple<BlockEntityType<BlockEntityEnderCrate>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityEnderCrate>>>> 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.TileEntityFieldCreator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFieldCreator;
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.PlayerEntity; import net.minecraft.entity.player.Player;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.ActionResultType; import net.minecraft.util.InteractionResult;
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.world.World; import net.minecraft.level.Level;
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", TileEntityFieldCreator::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE)); super("field_creator", BlockEntityFieldCreator::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE));
} }
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) { public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityFieldCreator) { if (tile instanceof BlockEntityFieldCreator) {
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
String key = NaturesAura.MOD_ID + ":field_creator_pos"; String key = NaturesAura.MOD_ID + ":field_creator_pos";
CompoundNBT compound = player.getPersistentData(); CompoundTag 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));
TileEntityFieldCreator creator = (TileEntityFieldCreator) tile; BlockEntityFieldCreator creator = (BlockEntityFieldCreator) tile;
if (!pos.equals(stored)) { if (!pos.equals(stored)) {
if (creator.isCloseEnough(stored)) { if (creator.isCloseEnough(stored)) {
TileEntity otherTile = worldIn.getTileEntity(stored); BlockEntity otherTile = levelIn.getBlockEntity(stored);
if (otherTile instanceof TileEntityFieldCreator) { if (otherTile instanceof BlockEntityFieldCreator) {
creator.connectionOffset = stored.subtract(pos); creator.connectionOffset = stored.subtract(pos);
creator.isMain = true; creator.isMain = true;
creator.sendToClients(); creator.sendToClients();
TileEntityFieldCreator otherCreator = (TileEntityFieldCreator) otherTile; BlockEntityFieldCreator otherCreator = (BlockEntityFieldCreator) 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 ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} else } else
return ActionResultType.FAIL; return InteractionResult.FAIL;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityFieldCreator) { if (tile instanceof BlockEntityFieldCreator) {
TileEntityFieldCreator creator = (TileEntityFieldCreator) tile; BlockEntityFieldCreator creator = (BlockEntityFieldCreator) 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.TileEntityFireworkGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFireworkGenerator;
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.world.World; import net.minecraft.level.Level;
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", TileEntityFireworkGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("firework_generator", BlockEntityFireworkGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntityFlowerGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFlowerGenerator;
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.world.World; import net.minecraft.level.Level;
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", TileEntityFlowerGenerator::new, Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(2F)); super("flower_generator", BlockEntityFlowerGenerator::new, Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(2F));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntityFurnaceHeater; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFurnaceHeater;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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", TileEntityFurnaceHeater::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("furnace_heater", BlockEntityFurnaceHeater::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, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityFurnaceHeater && ((TileEntityFurnaceHeater) tile).isActive) { if (tile instanceof BlockEntityFurnaceHeater && ((BlockEntityFurnaceHeater) 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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, 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.TileEntityGeneratorLimitRemover; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover;
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.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.tileentity.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
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<TileEntityGeneratorLimitRemover>, ICustomBlockState { public class BlockGeneratorLimitRemover extends BlockContainerImpl implements ITESRProvider<BlockEntityGeneratorLimitRemover>, ICustomBlockState {
public BlockGeneratorLimitRemover() { public BlockGeneratorLimitRemover() {
super("generator_limit_remover", TileEntityGeneratorLimitRemover::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("generator_limit_remover", BlockEntityGeneratorLimitRemover::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
} }
@Override @Override
public Tuple<TileEntityType<TileEntityGeneratorLimitRemover>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityGeneratorLimitRemover>>>> getTESR() { public Tuple<BlockEntityType<BlockEntityGeneratorLimitRemover>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityGeneratorLimitRemover>>>> 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.VoxelShapes; import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.IWorld; import net.minecraft.level.ILevel;
import net.minecraft.world.IWorldReader; import net.minecraft.level.ILevelReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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, worldIn, pos, tintIndex) -> 0xf4cb42; return (state, levelIn, pos, tintIndex) -> 0xf4cb42;
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, 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.getWorld(); IBlockReader iblockreader = context.getLevel();
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, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, ILevel levelIn, 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(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)); 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));
} }
} }
private RedstoneSide getSide(IBlockReader worldIn, BlockPos pos, Direction face) { private RedstoneSide getSide(IBlockReader levelIn, BlockPos pos, Direction face) {
BlockPos blockpos = pos.offset(face); BlockPos blockpos = pos.offset(face);
BlockState blockstate = worldIn.getBlockState(blockpos); BlockState blockstate = levelIn.getBlockState(blockpos);
BlockPos blockpos1 = pos.up(); BlockPos blockpos1 = pos.up();
BlockState blockstate1 = worldIn.getBlockState(blockpos1); BlockState blockstate1 = levelIn.getBlockState(blockpos1);
if (!blockstate1.isNormalCube(worldIn, blockpos1)) { if (!blockstate1.isNormalCube(levelIn, blockpos1)) {
boolean flag = blockstate.isSolidSide(worldIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER; boolean flag = blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
if (flag && this.canConnectTo(worldIn.getBlockState(blockpos.up()))) { if (flag && this.canConnectTo(levelIn.getBlockState(blockpos.up()))) {
if (blockstate.hasOpaqueCollisionShape(worldIn, blockpos)) { if (blockstate.hasOpaqueCollisionShape(levelIn, blockpos)) {
return RedstoneSide.UP; return RedstoneSide.UP;
} }
@ -111,7 +111,7 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
} }
return !this.canConnectTo(blockstate) && (blockstate.isNormalCube(worldIn, blockpos) || !this.canConnectTo(worldIn.getBlockState(blockpos.down()))) ? RedstoneSide.NONE : RedstoneSide.SIDE; return !this.canConnectTo(blockstate) && (blockstate.isNormalCube(levelIn, blockpos) || !this.canConnectTo(levelIn.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, IWorldReader worldIn, BlockPos pos) { public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) {
BlockPos blockpos = pos.down(); BlockPos blockpos = pos.down();
BlockState blockstate = worldIn.getBlockState(blockpos); BlockState blockstate = levelIn.getBlockState(blockpos);
return blockstate.isSolidSide(worldIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER; return blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
} }
@Override @Override
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getCollisionShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return VoxelShapes.empty(); return Shapes.empty();
} }
@Override @Override
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { public void onBlockAdded(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) {
if (oldState.getBlock() != state.getBlock() && !worldIn.isRemote) { if (oldState.getBlock() != state.getBlock() && !levelIn.isClientSide) {
for (Direction direction : Direction.Plane.VERTICAL) { for (Direction direction : Direction.Plane.VERTICAL) {
worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this); levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (Direction direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(direction1)); this.notifyWireNeighborsOfStateChange(levelIn, 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 (worldIn.getBlockState(blockpos).isNormalCube(worldIn, blockpos)) { if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up());
} else { } else {
this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down());
} }
} }
@ -153,22 +153,22 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
@Override @Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { public void onReplaced(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (!isMoving && state.getBlock() != newState.getBlock()) { if (!isMoving && state.getBlock() != newState.getBlock()) {
super.onReplaced(state, worldIn, pos, newState, isMoving); super.onReplaced(state, levelIn, pos, newState, isMoving);
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
for (Direction direction : Direction.values()) { for (Direction direction : Direction.values()) {
worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this); levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
} }
for (Direction direction1 : Direction.Plane.HORIZONTAL) { for (Direction direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(direction1)); this.notifyWireNeighborsOfStateChange(levelIn, 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 (worldIn.getBlockState(blockpos).isNormalCube(worldIn, blockpos)) { if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up());
} else { } else {
this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down()); this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down());
} }
} }
@ -177,47 +177,47 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
} }
@Override @Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { public void neighborChanged(BlockState state, Level levelIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
if (!state.isValidPosition(worldIn, pos)) { if (!state.isValidPosition(levelIn, pos)) {
spawnDrops(state, worldIn, pos); spawnDrops(state, levelIn, pos);
worldIn.removeBlock(pos, false); levelIn.removeBlock(pos, false);
} }
} }
} }
@Override @Override
public void updateDiagonalNeighbors(BlockState state, IWorld worldIn, BlockPos pos, int flags, int recursionLeft) { public void updateDiagonalNeighbors(BlockState state, ILevel levelIn, 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 && worldIn.getBlockState(pool.setPos(pos).move(direction)).getBlock() != this) { if (redstoneside != RedstoneSide.NONE && levelIn.getBlockState(pool.setPos(pos).move(direction)).getBlock() != this) {
pool.move(Direction.DOWN); pool.move(Direction.DOWN);
BlockState blockstate = worldIn.getBlockState(pool); BlockState blockstate = levelIn.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(), worldIn.getBlockState(blockpos), worldIn, pool, blockpos); BlockState blockstate1 = blockstate.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos);
replaceBlock(blockstate, blockstate1, worldIn, pool, flags); replaceBlock(blockstate, blockstate1, levelIn, pool, flags);
} }
pool.setPos(pos).move(direction).move(Direction.UP); pool.setPos(pos).move(direction).move(Direction.UP);
BlockState blockstate3 = worldIn.getBlockState(pool); BlockState blockstate3 = levelIn.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(), worldIn.getBlockState(blockpos1), worldIn, pool, blockpos1); BlockState blockstate2 = blockstate3.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1);
replaceBlock(blockstate3, blockstate2, worldIn, pool, flags); replaceBlock(blockstate3, blockstate2, levelIn, pool, flags);
} }
} }
} }
} }
private void notifyWireNeighborsOfStateChange(World worldIn, BlockPos pos) { private void notifyWireNeighborsOfStateChange(Level levelIn, BlockPos pos) {
if (worldIn.getBlockState(pos).getBlock() == this) { if (levelIn.getBlockState(pos).getBlock() == this) {
worldIn.notifyNeighborsOfStateChange(pos, this); levelIn.notifyNeighborsOfStateChange(pos, this);
for (Direction direction : Direction.values()) { for (Direction direction : Direction.values()) {
worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this); levelIn.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.world.World; import net.minecraft.level.Level;
import net.minecraft.world.biome.BiomeColors; import net.minecraft.level.biome.BiomeColors;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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(World world, BlockPos pos) { public static boolean convert(Level level, BlockPos pos) {
BlockState state = world.getBlockState(pos); BlockState state = level.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 (!world.isRemote) { if (!level.isClientSide) {
world.setBlockState(pos, ModBlocks.GOLDEN_LEAVES.getDefaultState() level.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, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, 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, worldIn, pos, tintIndex) -> { return (state, levelIn, pos, tintIndex) -> {
int color = 0xF2FF00; int color = 0xF2FF00;
if (state != null && worldIn != null && pos != null) { if (state != null && levelIn != null && pos != null) {
int foliage = BiomeColors.getFoliageColor(worldIn, pos); int foliage = BiomeColors.getFoliageColor(levelIn, 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, ServerWorld worldIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.randomTick(state, worldIn, pos, random); super.randomTick(state, levelIn, pos, random);
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
int stage = state.get(STAGE); int stage = state.get(STAGE);
if (stage < HIGHEST_STAGE) { if (stage < HIGHEST_STAGE) {
worldIn.setBlockState(pos, state.with(STAGE, stage + 1)); levelIn.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 (worldIn.isBlockLoaded(offset)) if (levelIn.isBlockLoaded(offset))
convert(worldIn, offset); convert(levelIn, offset);
} }
} }
} }

View file

@ -1,31 +1,31 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityGratedChute; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGratedChute;
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.PlayerEntity; import net.minecraft.entity.player.Player;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.ActionResultType; import net.minecraft.util.InteractionResult;
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.MathHelper; import net.minecraft.util.math.Mth;
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.VoxelShapes; import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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 = VoxelShapes.or(MIDDLE_SHAPE, INPUT_SHAPE); private static final VoxelShape INPUT_MIDDLE_SHAPE = Shapes.or(MIDDLE_SHAPE, INPUT_SHAPE);
private static final VoxelShape COMBINED_SHAPE = VoxelShapes.combineAndSimplify(INPUT_MIDDLE_SHAPE, IHopper.INSIDE_BOWL_SHAPE, IBooleanFunction.ONLY_FIRST); private static final VoxelShape COMBINED_SHAPE = Shapes.combineAndSimplify(INPUT_MIDDLE_SHAPE, IHopper.INSIDE_BOWL_SHAPE, IBooleanFunction.ONLY_FIRST);
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 DOWN_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 10.0D, 4.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 EAST_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.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 NORTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.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 SOUTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.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 WEST_SHAPE = Shapes.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 = VoxelShapes.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 = Shapes.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 = VoxelShapes.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 = Shapes.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 = VoxelShapes.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 = Shapes.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 = VoxelShapes.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 = Shapes.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", TileEntityGratedChute::new, Properties.create(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL)); super("grated_chute", BlockEntityGratedChute::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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, 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 worldIn, BlockPos pos) { public VoxelShape getRaytraceShape(BlockState state, IBlockReader levelIn, 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 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) {
if (!player.isSneaking()) if (!player.isSneaking())
return ActionResultType.FAIL; return InteractionResult.FAIL;
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof TileEntityGratedChute)) if (!(tile instanceof BlockEntityGratedChute))
return ActionResultType.FAIL; return InteractionResult.FAIL;
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
TileEntityGratedChute chute = (TileEntityGratedChute) tile; BlockEntityGratedChute chute = (BlockEntityGratedChute) tile;
chute.isBlacklist = !chute.isBlacklist; chute.isBlacklist = !chute.isBlacklist;
chute.sendToClients(); chute.sendToClients();
} }
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
@Nullable @Nullable
@ -128,14 +128,14 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
} }
@Override @Override
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntityGratedChute) { if (tile instanceof BlockEntityGratedChute) {
IItemHandler handler = ((TileEntityGratedChute) tile).getItemHandler(); IItemHandler handler = ((BlockEntityGratedChute) tile).getItemHandler();
ItemStack stack = handler.getStackInSlot(0); ItemStack stack = handler.getStackInSlot(0);
if (stack.isEmpty()) if (stack.isEmpty())
return 0; return 0;
return MathHelper.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15); return Mth.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.TileEntityHopperUpgrade; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityHopperUpgrade;
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.world.World; import net.minecraft.level.Level;
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", TileEntityHopperUpgrade::new, Properties.create(Material.IRON).hardnessAndResistance(2.5F).sound(SoundType.METAL)); super("hopper_upgrade", BlockEntityHopperUpgrade::new, Properties.create(Material.IRON).hardnessAndResistance(2.5F).sound(SoundType.METAL));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.block.Block; import net.minecraft.world.level.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.TileEntityItemDistributor; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityItemDistributor;
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.PlayerEntity; import net.minecraft.entity.player.Player;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.ActionResultType; import net.minecraft.util.InteractionResult;
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.world.World; import net.minecraft.level.Level;
public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState { public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState {
public BlockItemDistributor() { public BlockItemDistributor() {
super("item_distributor", TileEntityItemDistributor::new, Properties.from(Blocks.STONE_BRICKS)); super("item_distributor", BlockEntityItemDistributor::new, Properties.from(Blocks.STONE_BRICKS));
} }
@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) {
if (!player.isSneaking()) if (!player.isSneaking())
return ActionResultType.FAIL; return InteractionResult.FAIL;
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof TileEntityItemDistributor)) if (!(tile instanceof BlockEntityItemDistributor))
return ActionResultType.FAIL; return InteractionResult.FAIL;
if (!worldIn.isRemote) { if (!levelIn.isClientSide) {
TileEntityItemDistributor distributor = (TileEntityItemDistributor) tile; BlockEntityItemDistributor distributor = (BlockEntityItemDistributor) tile;
distributor.isRandomMode = !distributor.isRandomMode; distributor.isRandomMode = !distributor.isRandomMode;
distributor.sendToClients(); distributor.sendToClients();
} }
return ActionResultType.SUCCESS; return InteractionResult.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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, Level levelIn, 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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, 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.TileEntityMossGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityMossGenerator;
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.world.World; import net.minecraft.level.Level;
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", TileEntityMossGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("moss_generator", BlockEntityMossGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, BlockPos pos) {
return 0x15702d; return 0x15702d;
} }
} }

View file

@ -3,45 +3,46 @@ 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.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
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.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
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.util.math.shapes.ISelectionContext; import net.minecraft.world.InteractionResult;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.level.Level;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.World; import net.minecraft.world.level.block.state.properties.BooleanProperty;
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<TileEntityNatureAltar>, ICustomBlockState { public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvider<BlockEntityNatureAltar>, ICustomBlockState {
private static final VoxelShape SHAPE = VoxelShapes.create(0, 0, 0, 1, 12 / 16F, 1); private static final VoxelShape SHAPE = Shapes.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", TileEntityNatureAltar::new, Properties.create(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("nature_altar", BlockEntityNatureAltar::new, Block.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));
} }
@ -51,17 +52,18 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext 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<TileEntityType<TileEntityNatureAltar>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityNatureAltar>>>> getTESR() { public Tuple<BlockEntityType<BlockEntityNatureAltar>, Supplier<Function<? super BlockEntityRenderDispatcher, ? extends BlockEntityRenderer<? super BlockEntityNatureAltar>>>> getTESR() {
return new Tuple<>(ModTileEntities.NATURE_ALTAR, () -> RenderNatureAltar::new); return new Tuple<>(ModTileEntities.NATURE_ALTAR, () -> RenderNatureAltar::new);
} }
@ -79,7 +81,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.forWorld(context.getWorld()).isSimilar(NaturesAuraAPI.TYPE_NETHER); boolean nether = IAuraType.forLevel(context.getLevel()).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.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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, ServerWorld worldIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
BlockPos up = pos.up(); BlockPos up = pos.up();
BlockState upState = worldIn.getBlockState(up); BlockState upState = levelIn.getBlockState(up);
if (upState.isSolidSide(worldIn, up, Direction.DOWN)) if (upState.isSolidSide(levelIn, up, Direction.DOWN))
worldIn.setBlockState(pos, Blocks.NETHERRACK.getDefaultState()); levelIn.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 worldIn, BlockPos pos, BlockState state, boolean isClient) { public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) {
return worldIn.getBlockState(pos.up()).isAir(worldIn, pos.up()); return levelIn.getBlockState(pos.up()).isAir(levelIn, pos.up());
} }
@Override @Override
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, BlockState state) { public boolean canUseBonemeal(Level levelIn, Random rand, BlockPos pos, BlockState state) {
return true; return true;
} }
@Override @Override
public void grow(ServerWorld world, Random rand, BlockPos pos, BlockState state) { public void grow(ServerLevel level, 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 = world.getBlockState(blockpos1); BlockState blockstate2 = level.getBlockState(blockpos1);
if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) { if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
((IGrowable) blockstate.getBlock()).grow(world, rand, blockpos1, blockstate2); ((IGrowable) blockstate.getBlock()).grow(level, rand, blockpos1, blockstate2);
} }
if (!blockstate2.isAir()) { if (!blockstate2.isAir()) {
break; break;
} }
if (blockstate.isValidPosition(world, blockpos1)) { if (blockstate.isValidPosition(level, blockpos1)) {
world.setBlockState(blockpos1, blockstate, 3); level.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 (world.getBlockState(blockpos1.down()).getBlock() != this || world.getBlockState(blockpos1).hasOpaqueCollisionShape(world, blockpos1)) { if (level.getBlockState(blockpos1.down()).getBlock() != this || level.getBlockState(blockpos1).hasOpaqueCollisionShape(level, 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.TileEntityOakGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOakGenerator;
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.world.IWorld; import net.minecraft.level.ILevel;
import net.minecraft.world.World; import net.minecraft.level.Level;
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.world.SaplingGrowTreeEvent; import net.minecraftforge.event.level.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", TileEntityOakGenerator::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); super("oak_generator", BlockEntityOakGenerator::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) {
IWorld world = event.getWorld(); ILevel level = event.getLevel();
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
if (world instanceof World && !world.isRemote() && IAuraType.forWorld(world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel(level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
&& world.getBlockState(pos).getBlock() instanceof SaplingBlock) { && level.getBlockState(pos).getBlock() instanceof SaplingBlock) {
Helper.getTileEntitiesInArea(world, pos, 10, tile -> { Helper.getBlockEntitiesInArea(level, pos, 10, tile -> {
if (!(tile instanceof TileEntityOakGenerator)) if (!(tile instanceof BlockEntityOakGenerator))
return false; return false;
Random rand = event.getRand(); Random rand = event.getRand();
if (rand.nextInt(10) == 0) if (rand.nextInt(10) == 0)
((TileEntityOakGenerator) tile).scheduledBigTrees.add(pos); ((BlockEntityOakGenerator) 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(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntityOfferingTable; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable;
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.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.entity.player.Player;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.ActionResultType; import net.minecraft.util.InteractionResult;
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.VoxelShapes; import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.World; import net.minecraft.level.Level;
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<TileEntityOfferingTable>, ICustomBlockState { public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvider<BlockEntityOfferingTable>, ICustomBlockState {
private static final VoxelShape SHAPE = VoxelShapes.create(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F); private static final VoxelShape SHAPE = Shapes.create(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F);
public BlockOfferingTable() { public BlockOfferingTable() {
super("offering_table", TileEntityOfferingTable::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); super("offering_table", BlockEntityOfferingTable::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 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 VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
public Tuple<TileEntityType<TileEntityOfferingTable>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityOfferingTable>>>> getTESR() { public Tuple<BlockEntityType<BlockEntityOfferingTable>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityOfferingTable>>>> 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.TileEntityPickupStopper; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPickupStopper;
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.PlayerEntity; import net.minecraft.entity.player.Player;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.world.World; import net.minecraft.level.Level;
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", TileEntityPickupStopper::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("pickup_stopper", BlockEntityPickupStopper::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) {
PlayerEntity player = event.getPlayer(); Player 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.getTileEntitiesInArea(item.world, pos, 8, tile -> { Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> {
if (!(tile instanceof TileEntityPickupStopper)) if (!(tile instanceof BlockEntityPickupStopper))
return false; return false;
TileEntityPickupStopper stopper = (TileEntityPickupStopper) tile; BlockEntityPickupStopper stopper = (BlockEntityPickupStopper) 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.world.getGameTime() % 3 == 0) if (item.level.getGameTime() % 3 == 0)
PacketHandler.sendToAllAround(item.world, pos, 32, PacketHandler.sendToAllAround(item.level, 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(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos); BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof TileEntityPickupStopper) { if (tile instanceof BlockEntityPickupStopper) {
double radius = ((TileEntityPickupStopper) tile).getRadius(); double radius = ((BlockEntityPickupStopper) 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntityPlacer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPlacer;
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.world.World; import net.minecraft.level.Level;
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", TileEntityPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("placer", BlockEntityPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntityPotionGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPotionGenerator;
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", TileEntityPotionGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).harvestTool(ToolType.PICKAXE).harvestLevel(1)); super("potion_generator", BlockEntityPotionGenerator::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.TileEntityPowderPlacer; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPowderPlacer;
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.VoxelShapes; import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.world.IBlockReader; import net.minecraft.level.IBlockReader;
public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState { public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState {
private static final VoxelShape SHAPE = VoxelShapes.create(0F, 0F, 0F, 1F, 4 / 16F, 1F); private static final VoxelShape SHAPE = Shapes.create(0F, 0F, 0F, 1F, 4 / 16F, 1F);
public BlockPowderPlacer() { public BlockPowderPlacer() {
super("powder_placer", TileEntityPowderPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE)); super("powder_placer", BlockEntityPowderPlacer::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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, 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.TileEntityProjectileGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator;
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.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.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.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
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.world.World; import net.minecraft.level.Level;
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<TileEntityProjectileGenerator>, ICustomBlockState { public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider<BlockEntityProjectileGenerator>, ICustomBlockState {
public BlockProjectileGenerator() { public BlockProjectileGenerator() {
super("projectile_generator", TileEntityProjectileGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("projectile_generator", BlockEntityProjectileGenerator::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(World worldIn, IPosition position, ItemStack stackIn) { protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) {
EnderPearlEntity ret = new EnderPearlEntity(EntityType.ENDER_PEARL, worldIn); EnderPearlEntity ret = new EnderPearlEntity(EntityType.ENDER_PEARL, levelIn);
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(World worldIn, IPosition position, ItemStack stackIn) { protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) {
TridentEntity ret = new TridentEntity(EntityType.TRIDENT, worldIn); TridentEntity ret = new TridentEntity(EntityType.TRIDENT, levelIn);
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.world.isRemote) if (entity.level.isClientSide)
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;
TileEntity tile = entity.world.getTileEntity(pos); BlockEntity tile = entity.level.getBlockEntity(pos);
if (!(tile instanceof TileEntityProjectileGenerator)) if (!(tile instanceof BlockEntityProjectileGenerator))
return; return;
TileEntityProjectileGenerator generator = (TileEntityProjectileGenerator) tile; BlockEntityProjectileGenerator generator = (BlockEntityProjectileGenerator) 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.world, pos, 32, PacketHandler.sendToAllAround(entity.level, 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.world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ENDER_EYE_LAUNCH, SoundCategory.BLOCKS, 0.8F, 1F); entity.level.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<TileEntityType<TileEntityProjectileGenerator>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityProjectileGenerator>>>> getTESR() { public Tuple<BlockEntityType<BlockEntityProjectileGenerator>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityProjectileGenerator>>>> 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.TileEntityRFConverter; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityRFConverter;
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", TileEntityRFConverter::new, Properties.create(Material.ROCK).sound(SoundType.STONE).hardnessAndResistance(3)); super("rf_converter", BlockEntityRFConverter::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.TileEntitySlimeSplitGenerator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySlimeSplitGenerator;
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.world.World; import net.minecraft.level.Level;
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", TileEntitySlimeSplitGenerator::new, Properties.from(Blocks.SLIME_BLOCK).hardnessAndResistance(2)); super("slime_split_generator", BlockEntitySlimeSplitGenerator::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(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.world.isRemote) if (!(entity instanceof SlimeEntity) || entity.level.isClientSide)
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.getTileEntitiesInArea(entity.world, entity.getPosition(), 8, tile -> { Helper.getBlockEntitiesInArea(entity.level, entity.getPosition(), 8, tile -> {
if (!(tile instanceof TileEntitySlimeSplitGenerator)) if (!(tile instanceof BlockEntitySlimeSplitGenerator))
return false; return false;
TileEntitySlimeSplitGenerator gen = (TileEntitySlimeSplitGenerator) tile; BlockEntitySlimeSplitGenerator gen = (BlockEntitySlimeSplitGenerator) 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.TileEntitySnowCreator; import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySnowCreator;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.world.World; import net.minecraft.level.Level;
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", TileEntitySnowCreator::new, Properties.from(Blocks.STONE_BRICKS)); super("snow_creator", BlockEntitySnowCreator::new, Properties.from(Blocks.STONE_BRICKS));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos); BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof TileEntitySnowCreator) { if (tile instanceof BlockEntitySnowCreator) {
int radius = ((TileEntitySnowCreator) tile).getRange(); int radius = ((BlockEntitySnowCreator) 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.IWorldData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp; import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySpawnLamp;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.misc.WorldData; import de.ellpeck.naturesaura.misc.LevelData;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
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.VoxelShapes; import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.IWorld; import net.minecraft.level.ILevel;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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 = VoxelShapes.create(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F); private static final VoxelShape SHAPE = Shapes.create(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F);
public BlockSpawnLamp() { public BlockSpawnLamp() {
super("spawn_lamp", TileEntitySpawnLamp::new, Properties.create(Material.IRON).hardnessAndResistance(3F).setLightLevel(s -> 15).sound(SoundType.METAL)); super("spawn_lamp", BlockEntitySpawnLamp::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;
IWorld world = event.getWorld(); ILevel level = event.getLevel();
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ()); BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ());
if (!(world instanceof World)) if (!(level instanceof Level))
return; return;
WorldData data = (WorldData) IWorldData.getWorldData((World) world); LevelData data = (LevelData) ILevelData.getLevelData((Level) level);
for (TileEntitySpawnLamp lamp : data.spawnLamps) { for (BlockEntitySpawnLamp 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(world, event.getSpawnReason()) && entity.isNotColliding(world)) { if (entity.canSpawn(level, event.getSpawnReason()) && entity.isNotColliding(level)) {
BlockPos spot = IAuraChunk.getHighestSpot(world, lampPos, 32, lampPos); BlockPos spot = IAuraChunk.getHighestSpot(level, lampPos, 32, lampPos);
IAuraChunk.getAuraChunk(world, spot).drainAura(spot, 200); IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 200);
PacketHandler.sendToAllAround((ServerWorld) world, lampPos, 32, PacketHandler.sendToAllAround((ServerLevel) level, 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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos); BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof TileEntitySpawnLamp) { if (tile instanceof BlockEntitySpawnLamp) {
int radius = ((TileEntitySpawnLamp) tile).getRadius(); int radius = ((BlockEntitySpawnLamp) 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(World world, BlockPos pos) { public int getVisualizationColor(Level level, 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.TileEntitySpring; import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySpring;
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.PlayerEntity; import net.minecraft.entity.player.Player;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld; import net.minecraft.level.ILevel;
import net.minecraft.world.biome.BiomeColors; import net.minecraft.level.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", TileEntitySpring::new, Properties.from(Blocks.STONE_BRICKS)); super("spring", BlockEntitySpring::new, Properties.from(Blocks.STONE_BRICKS));
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() { public IBlockColor getBlockColor() {
return (state, world, pos, i) -> BiomeColors.getWaterColor(world, pos); return (state, level, pos, i) -> BiomeColors.getWaterColor(level, 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) {
PlayerEntity player = Minecraft.getInstance().player; Player player = Minecraft.getInstance().player;
return BiomeColors.getWaterColor(player.world, player.getPosition()); return BiomeColors.getWaterColor(player.level, player.getPosition());
} }
}; };
} }
@ -56,10 +56,10 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
} }
@Override @Override
public Fluid pickupFluid(IWorld worldIn, BlockPos pos, BlockState state) { public Fluid pickupFluid(ILevel levelIn, BlockPos pos, BlockState state) {
TileEntity tile = worldIn.getTileEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof TileEntitySpring) if (tile instanceof BlockEntitySpring)
((TileEntitySpring) tile).consumeAura(2500); ((BlockEntitySpring) 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.TileEntityTimeChanger; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityTimeChanger;
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", TileEntityTimeChanger::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE)); super("time_changer", BlockEntityTimeChanger::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.TileEntityWeatherChanger; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWeatherChanger;
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", TileEntityWeatherChanger::new, Properties.from(Blocks.STONE_BRICKS)); super("weather_changer", BlockEntityWeatherChanger::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.TileEntityWoodStand; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand;
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.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.entity.player.Player;
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.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.ActionResultType; import net.minecraft.util.InteractionResult;
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.VoxelShapes; import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.world.IBlockReader; import net.minecraft.level.IBlockReader;
import net.minecraft.world.IWorld; import net.minecraft.level.ILevel;
import net.minecraft.world.World; import net.minecraft.level.Level;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ToolType; import net.minecraftforge.common.ToolType;
import net.minecraftforge.event.world.SaplingGrowTreeEvent; import net.minecraftforge.event.level.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<TileEntityWoodStand>, ICustomBlockState { public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<BlockEntityWoodStand>, ICustomBlockState {
private static final VoxelShape SHAPE = VoxelShapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F); private static final VoxelShape SHAPE = Shapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F);
public BlockWoodStand() { public BlockWoodStand() {
super("wood_stand", TileEntityWoodStand::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD).harvestLevel(0).harvestTool(ToolType.AXE)); super("wood_stand", BlockEntityWoodStand::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 worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
} }
@SubscribeEvent @SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) { public void onTreeGrow(SaplingGrowTreeEvent event) {
IWorld world = event.getWorld(); ILevel level = event.getLevel();
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
if (!world.isRemote() && world instanceof World) { if (!level.isClientSide() && level instanceof Level) {
if (Multiblocks.TREE_RITUAL.isComplete((World) world, pos)) { if (Multiblocks.TREE_RITUAL.isComplete((Level) level, pos)) {
BlockState sapling = world.getBlockState(pos); BlockState sapling = level.getBlockState(pos);
ItemStack saplingStack = sapling.getBlock().getItem(world, pos, sapling); ItemStack saplingStack = sapling.getBlock().getItem(level, pos, sapling);
if (!saplingStack.isEmpty()) { if (!saplingStack.isEmpty()) {
for (TreeRitualRecipe recipe : ((World) world).getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null)) { for (TreeRitualRecipe recipe : ((Level) level).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<TileEntityWoodStand> toPick = new MutableObject<>(); MutableObject<BlockEntityWoodStand> toPick = new MutableObject<>();
boolean fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> { boolean fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> {
TileEntity tile = world.getTileEntity(tilePos); BlockEntity tile = level.getBlockEntity(tilePos);
if (tile instanceof TileEntityWoodStand) { if (tile instanceof BlockEntityWoodStand) {
TileEntityWoodStand stand = (TileEntityWoodStand) tile; BlockEntityWoodStand stand = (BlockEntityWoodStand) 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 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<TileEntityType<TileEntityWoodStand>, Supplier<Function<? super TileEntityRendererDispatcher, ? extends TileEntityRenderer<? super TileEntityWoodStand>>>> getTESR() { public Tuple<BlockEntityType<BlockEntityWoodStand>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityWoodStand>>>> 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.block.Block; import net.minecraft.world.level.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.world.World; import net.minecraft.level.Level;
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,
(world, start, offset, pos, other, otherC) -> other == state)); (level, 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(),
(world, start, offset, pos, state, otherC) -> state.getBlock() == block)); (level, 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(World world, BlockPos center) { public boolean isComplete(Level level, 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(world, start, offset, pos, world.getBlockState(pos), this.getChar(offset)); return matcher.getCheck().matches(level, start, offset, pos, level.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.block.Blocks; import net.minecraft.resources.ResourceLocation;
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.util.ResourceLocation; import net.minecraft.world.item.ItemStack;
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.getDefaultState().with(BlockNatureAltar.NETHER, true), '0', ModBlocks.NATURE_ALTAR.defaultBlockState().setValue(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.getDefaultState(), 'W', new Matcher(ModBlocks.WOOD_STAND.defaultBlockState(),
(world, start, offset, pos, state, c) -> world != null || state.getBlock() == ModBlocks.WOOD_STAND), (level, start, offset, pos, state, c) -> level != null || state.getBlock() == ModBlocks.WOOD_STAND),
'G', ModBlocks.GOLD_POWDER, 'G', ModBlocks.GOLD_POWDER,
'0', new Matcher(Blocks.OAK_SAPLING.getDefaultState(), '0', new Matcher(Blocks.OAK_SAPLING.defaultBlockState(),
(world, start, offset, pos, state, c) -> { (level, 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().getItem(world, pos, state); ItemStack stack = state.getBlock().getCloneItemStack(level, pos, state);
return !stack.isEmpty() && world.getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null).stream().anyMatch(r -> r.saplingType.test(stack)); return !stack.isEmpty() && level.getRecipeManager().getRecipesFor(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.getDefaultState(), 'R', new Matcher(Blocks.POPPY.defaultBlockState(),
(world, start, offset, pos, state, c) -> BlockTags.SMALL_FLOWERS.contains(state.getBlock())), (level, 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

@ -3,9 +3,11 @@ 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.nbt.CompoundNBT; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.state.BlockState;
public class TileEntityAncientLeaves extends TileEntityImpl { public class BlockEntityAncientLeaves extends BlockEntityImpl {
private final NaturalAuraContainer container = new NaturalAuraContainer(NaturesAuraAPI.TYPE_OVERWORLD, 2000, 500) { private final NaturalAuraContainer container = new NaturalAuraContainer(NaturesAuraAPI.TYPE_OVERWORLD, 2000, 500) {
@Override @Override
@ -17,14 +19,14 @@ public class TileEntityAncientLeaves extends TileEntityImpl {
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) {
TileEntityAncientLeaves.this.sendToClients(); BlockEntityAncientLeaves.this.sendToClients();
} }
return amount; return amount;
} }
}; };
public TileEntityAncientLeaves() { public BlockEntityAncientLeaves(BlockPos pos, BlockState state) {
super(ModTileEntities.ANCIENT_LEAVES); super(ModTileEntities.ANCIENT_LEAVES, pos, state);
} }
@Override @Override
@ -33,14 +35,14 @@ public class TileEntityAncientLeaves extends TileEntityImpl {
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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,51 @@
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,24 +1,23 @@
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.tileentity.ITickableTileEntity; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
public class TileEntityAnimalGenerator extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityAnimalGenerator extends BlockEntityImpl implements ITickableBlockEntity {
private int timeRemaining; private int timeRemaining;
private int amountToRelease; private int amountToRelease;
public TileEntityAnimalGenerator() { public BlockEntityAnimalGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.ANIMAL_GENERATOR); super(ModTileEntities.ANIMAL_GENERATOR, pos, state);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote) { if (!this.level.isClientSide) {
if (this.world.getGameTime() % 10 != 0) if (this.level.getGameTime() % 10 != 0)
return; return;
if (this.timeRemaining <= 0) if (this.timeRemaining <= 0)
return; return;
@ -26,8 +25,8 @@ public class TileEntityAnimalGenerator extends TileEntityImpl implements ITickab
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.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ANIMAL_GEN_CREATE)); new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.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.entity.Entity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.nbt.CompoundTag;
import net.minecraft.item.ItemStack; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.Mth;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.world.entity.Entity;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.MathHelper; import net.minecraft.world.phys.AABB;
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 TileEntityAnimalSpawner extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickableBlockEntity {
private AnimalSpawnerRecipe currentRecipe; private AnimalSpawnerRecipe currentRecipe;
private double spawnX; private double spawnX;
@ -32,16 +32,16 @@ public class TileEntityAnimalSpawner extends TileEntityImpl implements ITickable
private int time; private int time;
private Entity entityClient; private Entity entityClient;
public TileEntityAnimalSpawner() { public BlockEntityAnimalSpawner(BlockPos pos, BlockState state) {
super(ModTileEntities.ANIMAL_SPAWNER); super(ModTileEntities.ANIMAL_SPAWNER, pos, state);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote) { if (!this.level.isClientSide) {
if (this.world.getGameTime() % 10 != 0) if (this.level.getGameTime() % 10 != 0)
return; return;
if (!Multiblocks.ANIMAL_SPAWNER.isComplete(this.world, this.pos)) { if (!Multiblocks.ANIMAL_SPAWNER.isComplete(this.level, this.worldPosition)) {
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 TileEntityAnimalSpawner extends TileEntityImpl implements ITickable
} }
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
int drain = MathHelper.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F); int drain = Mth.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F);
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, drain); IAuraChunk.getAuraChunk(this.level, 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.world, new BlockPos(this.spawnX, this.pos.getY() + 1, this.spawnZ)); Entity entity = this.currentRecipe.makeEntity(this.level, new BlockPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ));
this.world.addEntity(entity); this.level.addFreshEntity(entity);
this.currentRecipe = null; this.currentRecipe = null;
this.time = 0; this.time = 0;
this.sendToClients(); this.sendToClients();
} }
} else { } else {
List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class,
new AxisAlignedBB(this.pos).grow(2)); new AABB(this.worldPosition).inflate(2));
for (AnimalSpawnerRecipe recipe : this.world.getRecipeManager().getRecipes(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null)) { for (AnimalSpawnerRecipe recipe : this.level.getRecipeManager().getRecipesFor(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.cannotPickup()) if (!item.isAlive() || item.hasPickUpDelay())
break; break;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (stack.isEmpty()) if (stack.isEmpty())
@ -89,20 +89,20 @@ public class TileEntityAnimalSpawner extends TileEntityImpl implements ITickable
continue; continue;
for (ItemEntity item : items) { for (ItemEntity item : items) {
item.remove(); item.remove(Entity.RemovalReason.KILLED);
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.ANIMAL_SPAWNER)); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.ANIMAL_SPAWNER));
} }
this.currentRecipe = recipe; this.currentRecipe = recipe;
this.spawnX = this.pos.getX() + 0.5 + this.world.rand.nextFloat() * 4 - 2; this.spawnX = this.worldPosition.getX() + 0.5 + this.level.random.nextFloat() * 4 - 2;
this.spawnZ = this.pos.getZ() + 0.5 + this.world.rand.nextFloat() * 4 - 2; this.spawnZ = this.worldPosition.getZ() + 0.5 + this.level.random.nextFloat() * 4 - 2;
this.sendToClients(); this.sendToClients();
break; break;
} }
} }
} else { } else {
if (this.world.getGameTime() % 5 != 0) if (this.level.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 TileEntityAnimalSpawner extends TileEntityImpl implements ITickable
} }
NaturesAuraAPI.instance().spawnParticleStream( NaturesAuraAPI.instance().spawnParticleStream(
this.pos.getX() + (float) this.world.rand.nextGaussian() * 5F, this.worldPosition.getX() + (float) this.level.random.nextGaussian() * 5F,
this.pos.getY() + 1 + this.world.rand.nextFloat() * 5F, this.worldPosition.getY() + 1 + this.level.random.nextFloat() * 5F,
this.pos.getZ() + (float) this.world.rand.nextGaussian() * 5F, this.worldPosition.getZ() + (float) this.level.random.nextGaussian() * 5F,
this.pos.getX() + this.world.rand.nextFloat(), this.worldPosition.getX() + this.level.random.nextFloat(),
this.pos.getY() + this.world.rand.nextFloat(), this.worldPosition.getY() + this.level.random.nextFloat(),
this.pos.getZ() + this.world.rand.nextFloat(), this.worldPosition.getZ() + this.level.random.nextFloat(),
this.world.rand.nextFloat() * 0.07F + 0.07F, this.level.random.nextFloat() * 0.07F + 0.07F,
IAuraType.forWorld(this.world).getColor(), IAuraType.forLevel(this.level).getColor(),
this.world.rand.nextFloat() + 0.5F); this.level.random.nextFloat() + 0.5F);
if (this.entityClient == null) { if (this.entityClient == null) {
this.entityClient = this.currentRecipe.makeEntity(this.world, BlockPos.ZERO); this.entityClient = this.currentRecipe.makeEntity(this.level, BlockPos.ZERO);
this.entityClient.setPosition(this.spawnX, this.pos.getY() + 1, this.spawnZ); this.entityClient.setPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ);
} }
AxisAlignedBB bounds = this.entityClient.getBoundingBox(); AABB bounds = this.entityClient.getBoundingBox();
for (int i = this.world.rand.nextInt(5) + 5; i >= 0; i--) for (int i = this.level.random.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
bounds.minX + this.world.rand.nextFloat() * (bounds.maxX - bounds.minX), bounds.minX + this.level.random.nextFloat() * (bounds.maxX - bounds.minX),
bounds.minY + this.world.rand.nextFloat() * (bounds.maxY - bounds.minY), bounds.minY + this.level.random.nextFloat() * (bounds.maxY - bounds.minY),
bounds.minZ + this.world.rand.nextFloat() * (bounds.maxZ - bounds.minZ), bounds.minZ + this.level.random.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(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityAnimalSpawner extends TileEntityImpl implements ITickable
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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.hasWorld()) { if (this.hasLevel()) {
ResourceLocation name = new ResourceLocation(compound.getString("recipe")); ResourceLocation name = new ResourceLocation(compound.getString("recipe"));
this.currentRecipe = (AnimalSpawnerRecipe) this.world.getRecipeManager().getRecipe(name).orElse(null); this.currentRecipe = (AnimalSpawnerRecipe) this.level.getRecipeManager().byKey(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

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

View file

@ -5,21 +5,20 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticleStream;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.recipes.TreeRitualRecipe; import de.ellpeck.naturesaura.recipes.TreeRitualRecipe;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.Blocks; import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.LeavesBlock; import net.minecraft.resources.ResourceLocation;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.sounds.SoundEvents;
import net.minecraft.item.ItemStack; import net.minecraft.sounds.SoundSource;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.util.SoundCategory; import net.minecraft.world.level.Level;
import net.minecraft.util.SoundEvents; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.World; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
@ -27,7 +26,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class TileEntityWoodStand extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBlockEntity {
public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) { public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) {
@Override @Override
@ -40,8 +39,8 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
private BlockPos ritualPos; private BlockPos ritualPos;
private int timer; private int timer;
public TileEntityWoodStand() { public BlockEntityWoodStand(BlockPos pos, BlockState state) {
super(ModTileEntities.WOOD_STAND); super(ModTileEntities.WOOD_STAND, pos, state);
} }
public void setRitual(BlockPos pos, TreeRitualRecipe recipe) { public void setRitual(BlockPos pos, TreeRitualRecipe recipe) {
@ -51,9 +50,9 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote) { if (!this.level.isClientSide) {
if (this.ritualPos != null && this.recipe != null) { if (this.ritualPos != null && this.recipe != null) {
if (this.world.getGameTime() % 5 == 0) { if (this.level.getGameTime() % 5 == 0) {
if (this.isRitualOkay()) { if (this.isRitualOkay()) {
boolean wasOverHalf = this.timer >= this.recipe.time / 2; boolean wasOverHalf = this.timer >= this.recipe.time / 2;
this.timer += 5; this.timer += 5;
@ -61,57 +60,54 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
if (!isOverHalf) if (!isOverHalf)
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
TileEntity tile = this.world.getTileEntity(pos); BlockEntity tile = this.level.getBlockEntity(pos);
if (tile instanceof TileEntityWoodStand && !((TileEntityWoodStand) tile).items.getStackInSlot(0).isEmpty()) { if (tile instanceof BlockEntityWoodStand && !((BlockEntityWoodStand) tile).items.getStackInSlot(0).isEmpty()) {
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream(
(float) pos.getX() + 0.2F + this.world.rand.nextFloat() * 0.6F, (float) pos.getX() + 0.2F + this.level.random.nextFloat() * 0.6F,
(float) pos.getY() + 0.85F, (float) pos.getY() + 0.85F,
(float) pos.getZ() + 0.2F + this.world.rand.nextFloat() * 0.6F, (float) pos.getZ() + 0.2F + this.level.random.nextFloat() * 0.6F,
this.ritualPos.getX() + 0.5F, this.ritualPos.getY() + this.world.rand.nextFloat() * 3F + 2F, this.ritualPos.getZ() + 0.5F, this.ritualPos.getX() + 0.5F, this.ritualPos.getY() + this.level.random.nextFloat() * 3F + 2F, this.ritualPos.getZ() + 0.5F,
this.world.rand.nextFloat() * 0.04F + 0.04F, 0x89cc37, this.world.rand.nextFloat() * 1F + 1F this.level.random.nextFloat() * 0.04F + 0.04F, 0x89cc37, this.level.random.nextFloat() + 1F
)); ));
} }
return true; return true;
}); });
PacketHandler.sendToAllAround(this.world, this.ritualPos, 32, PacketHandler.sendToAllAround(this.level, this.ritualPos, 32,
new PacketParticles(this.ritualPos.getX(), this.ritualPos.getY(), this.ritualPos.getZ(), PacketParticles.Type.TR_GOLD_POWDER)); new PacketParticles(this.ritualPos.getX(), this.ritualPos.getY(), this.ritualPos.getZ(), PacketParticles.Type.TR_GOLD_POWDER));
if (this.timer >= this.recipe.time) { if (this.timer >= this.recipe.time) {
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'G', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'G', (pos, matcher) -> {
this.world.setBlockState(pos, Blocks.AIR.getDefaultState()); this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
return true; return true;
}); });
recurseTreeDestruction(this.world, this.ritualPos, this.ritualPos, true, false); recurseTreeDestruction(this.level, this.ritualPos, this.ritualPos, true, false);
ItemEntity item = new ItemEntity(this.world, ItemEntity item = new ItemEntity(this.level,
this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5, this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5,
this.recipe.result.copy()); this.recipe.result.copy());
this.world.addEntity(item); this.level.addFreshEntity(item);
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.TR_SPAWN_RESULT)); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.TR_SPAWN_RESULT));
this.world.playSound(null, this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5, this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5,
SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 0.65F, 1F); SoundEvents.ENDERMAN_TELEPORT, SoundSource.BLOCKS, 0.65F, 1F);
this.ritualPos = null; this.ritualPos = null;
this.recipe = null; this.recipe = null;
this.timer = 0; this.timer = 0;
} else if (isOverHalf && !wasOverHalf) { } else if (isOverHalf && !wasOverHalf) {
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
TileEntity tile = this.world.getTileEntity(pos); BlockEntity tile = this.level.getBlockEntity(pos);
if (tile instanceof TileEntityWoodStand) { if (tile instanceof BlockEntityWoodStand stand && !stand.items.getStackInSlot(0).isEmpty()) {
TileEntityWoodStand stand = (TileEntityWoodStand) tile; PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
if (!stand.items.getStackInSlot(0).isEmpty()) { new PacketParticles(stand.worldPosition.getX(), stand.worldPosition.getY(), stand.worldPosition.getZ(), PacketParticles.Type.TR_CONSUME_ITEM));
PacketHandler.sendToAllAround(this.world, this.pos, 32, this.level.playSound(null, stand.worldPosition.getX() + 0.5, stand.worldPosition.getY() + 0.5, stand.worldPosition.getZ() + 0.5,
new PacketParticles(stand.pos.getX(), stand.pos.getY(), stand.pos.getZ(), PacketParticles.Type.TR_CONSUME_ITEM)); SoundEvents.WOOD_STEP, SoundSource.BLOCKS, 0.5F, 1F);
this.world.playSound(null, stand.pos.getX() + 0.5, stand.pos.getY() + 0.5, stand.pos.getZ() + 0.5,
SoundEvents.BLOCK_WOOD_STEP, SoundCategory.BLOCKS, 0.5F, 1F);
stand.items.setStackInSlot(0, ItemStack.EMPTY); stand.items.setStackInSlot(0, ItemStack.EMPTY);
stand.sendToClients(); stand.sendToClients();
} }
}
return true; return true;
}); });
} }
@ -126,7 +122,7 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
} }
public static void recurseTreeDestruction(World world, BlockPos pos, BlockPos start, boolean includeLeaves, boolean drop) { public static void recurseTreeDestruction(Level level, BlockPos pos, BlockPos start, boolean includeLeaves, boolean drop) {
if (Math.abs(pos.getX() - start.getX()) >= 6 if (Math.abs(pos.getX() - start.getX()) >= 6
|| Math.abs(pos.getZ() - start.getZ()) >= 6 || Math.abs(pos.getZ() - start.getZ()) >= 6
|| Math.abs(pos.getY() - start.getY()) >= 32) { || Math.abs(pos.getY() - start.getY()) >= 32) {
@ -136,17 +132,17 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
for (int x = -1; x <= 1; x++) { for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) { for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) { for (int z = -1; z <= 1; z++) {
BlockPos offset = pos.add(x, y, z); BlockPos offset = pos.offset(x, y, z);
BlockState state = world.getBlockState(offset); BlockState state = level.getBlockState(offset);
if (state.getBlock().getTags().contains(BlockTags.LOGS.getName()) || includeLeaves && state.getBlock() instanceof LeavesBlock) { if (state.getBlock().getTags().contains(BlockTags.LOGS.getName()) || includeLeaves && state.getBlock() instanceof LeavesBlock) {
if (drop) { if (drop) {
world.destroyBlock(offset, true); level.destroyBlock(offset, true);
} else { } else {
// in this case we don't want the particles, so we can't use destroyBlock // in this case we don't want the particles, so we can't use destroyBlock
world.setBlockState(offset, Blocks.AIR.getDefaultState()); level.setBlockAndUpdate(offset, Blocks.AIR.defaultBlockState());
PacketHandler.sendToAllAround(world, pos, 32, new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.TR_DISAPPEAR)); PacketHandler.sendToAllAround(level, pos, 32, new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.TR_DISAPPEAR));
} }
recurseTreeDestruction(world, offset, start, includeLeaves, drop); recurseTreeDestruction(level, offset, start, includeLeaves, drop);
} }
} }
} }
@ -154,20 +150,20 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
} }
private boolean isRitualOkay() { private boolean isRitualOkay() {
if (!Multiblocks.TREE_RITUAL.isComplete(this.world, this.ritualPos)) { if (!Multiblocks.TREE_RITUAL.isComplete(this.level, this.ritualPos)) {
return false; return false;
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
BlockState state = this.world.getBlockState(this.ritualPos.up(i)); BlockState state = this.level.getBlockState(this.ritualPos.above(i));
if (!(state.getBlock().getTags().contains(BlockTags.LOGS.getName()))) if (!(state.getBlock().getTags().contains(BlockTags.LOGS.getName())))
return false; return false;
} }
if (this.timer < this.recipe.time / 2) { if (this.timer < this.recipe.time / 2) {
List<Ingredient> required = new ArrayList<>(Arrays.asList(this.recipe.ingredients)); List<Ingredient> required = new ArrayList<>(Arrays.asList(this.recipe.ingredients));
boolean fine = Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { boolean fine = Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
TileEntity tile = this.world.getTileEntity(pos); BlockEntity tile = this.level.getBlockEntity(pos);
if (tile instanceof TileEntityWoodStand) { if (tile instanceof BlockEntityWoodStand) {
ItemStack stack = ((TileEntityWoodStand) tile).items.getStackInSlot(0); ItemStack stack = ((BlockEntityWoodStand) tile).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--) {
Ingredient req = required.get(i); Ingredient req = required.get(i);
@ -187,14 +183,14 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) if (type != SaveType.BLOCK)
compound.put("items", this.items.serializeNBT()); compound.put("items", this.items.serializeNBT());
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
if (this.ritualPos != null && this.recipe != null) { if (this.ritualPos != null && this.recipe != null) {
compound.putLong("ritual_pos", this.ritualPos.toLong()); compound.putLong("ritual_pos", this.ritualPos.asLong());
compound.putInt("timer", this.timer); compound.putInt("timer", this.timer);
compound.putString("recipe", this.recipe.name.toString()); compound.putString("recipe", this.recipe.name.toString());
} }
@ -202,17 +198,17 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
if (type != SaveType.BLOCK) if (type != SaveType.BLOCK)
this.items.deserializeNBT(compound.getCompound("items")); this.items.deserializeNBT(compound.getCompound("items"));
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
this.ritualPos = BlockPos.fromLong(compound.getLong("ritual_pos")); this.ritualPos = BlockPos.of(compound.getLong("ritual_pos"));
this.timer = compound.getInt("timer"); this.timer = compound.getInt("timer");
if (this.hasWorld()) if (this.hasLevel())
this.recipe = (TreeRitualRecipe) this.world.getRecipeManager().getRecipe(new ResourceLocation(compound.getString("recipe"))).orElse(null); this.recipe = (TreeRitualRecipe) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null);
} }
} }
} }

View file

@ -0,0 +1,7 @@
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 TileEntityImpl tile; private final BlockEntityImpl 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, TileEntityImpl tile, boolean sendToClients) { public ItemStackHandlerNA(int size, BlockEntityImpl 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.getWorld().isRemote) if (this.sendToClients && !this.tile.getLevel().isClientSide)
this.tile.sendToClients(); this.tile.sendToClients();
} }
} }

View file

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

View file

@ -1,52 +0,0 @@
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,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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.BlockEntityType;
public class TileEntityAuraBloom extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityAuraBloom extends BlockEntityImpl implements ITickableBlockEntity {
public boolean justGenerated; public boolean justGenerated;
public TileEntityAuraBloom() { public BlockEntityAuraBloom() {
this(ModTileEntities.AURA_BLOOM); this(ModTileEntities.AURA_BLOOM);
} }
protected TileEntityAuraBloom(TileEntityType<TileEntityAuraBloom> type) { protected BlockEntityAuraBloom(BlockEntityType<BlockEntityAuraBloom> 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.world.isRemote || !this.justGenerated) if (this.level.isClientSide || !this.justGenerated)
return; return;
this.generateAura(150000); this.generateAura(150000);
this.justGenerated = false; this.justGenerated = false;
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
public class TileEntityAuraDetector extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityAuraDetector extends BlockEntityImpl implements ITickableBlockEntity {
public int redstonePower; public int redstonePower;
public TileEntityAuraDetector() { public BlockEntityAuraDetector() {
super(ModTileEntities.AURA_DETECTOR); super(ModTileEntities.AURA_DETECTOR);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote && this.world.getGameTime() % 20 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) {
int totalAmount = IAuraChunk.triangulateAuraInArea(this.world, this.pos, 25); int totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 25);
int power = MathHelper.clamp(MathHelper.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15); int power = Mth.clamp(Mth.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15);
if (this.redstonePower != power) { if (this.redstonePower != power) {
this.redstonePower = power; this.redstonePower = power;
this.world.updateComparatorOutputLevel(this.pos, this.getBlockState().getBlock()); this.level.updateComparatorOutputLevel(this.worldPosition, 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import java.util.Map; import java.util.Map;
public class TileEntityAuraTimer extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBlockEntity {
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 TileEntityAuraTimer extends TileEntityImpl implements ITickableTile
}; };
private int timer; private int timer;
public TileEntityAuraTimer() { public BlockEntityAuraTimer() {
super(ModTileEntities.AURA_TIMER); super(ModTileEntities.AURA_TIMER);
} }
@ -39,7 +39,7 @@ public class TileEntityAuraTimer extends TileEntityImpl implements ITickableTile
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.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.TIMER_RESET, color)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.TIMER_RESET, color));
this.sendToClients(); this.sendToClients();
} }
super.onRedstonePowerChange(newPower); super.onRedstonePowerChange(newPower);
@ -53,14 +53,14 @@ public class TileEntityAuraTimer extends TileEntityImpl implements ITickableTile
return; return;
} }
if (this.world.isRemote) { if (this.level.isClientSide) {
if (this.world.getGameTime() % 8 == 0) { if (this.level.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.pos.getX() + 1 / 16F + this.world.rand.nextFloat() * 14 / 16F, this.worldPosition.getX() + 1 / 16F + this.level.rand.nextFloat() * 14 / 16F,
this.pos.getY() + 1 / 16F + this.world.rand.nextFloat() * 14 / 16F, this.worldPosition.getY() + 1 / 16F + this.level.rand.nextFloat() * 14 / 16F,
this.pos.getZ() + 1 / 16F + this.world.rand.nextFloat() * 14 / 16F, this.worldPosition.getZ() + 1 / 16F + this.level.rand.nextFloat() * 14 / 16F,
0, 0, 0, color, 1, 80 + this.world.rand.nextInt(50), 0, false, true); 0, 0, 0, color, 1, 80 + this.level.rand.nextInt(50), 0, false, true);
} }
return; return;
} }
@ -70,11 +70,11 @@ public class TileEntityAuraTimer extends TileEntityImpl implements ITickableTile
this.timer = 0; this.timer = 0;
BlockState state = this.getBlockState(); BlockState state = this.getBlockState();
this.world.setBlockState(this.pos, state.with(BlockStateProperties.POWERED, true), 1); this.level.setBlockState(this.worldPosition, state.with(BlockStateProperties.POWERED, true), 1);
this.world.getPendingBlockTicks().scheduleTick(this.pos, state.getBlock(), 4); this.level.getPendingBlockTicks().scheduleTick(this.worldPosition, state.getBlock(), 4);
int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor(); int color = ItemAuraBottle.getType(this.itemHandler.getStackInSlot(0)).getColor();
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.TIMER_RESET, color)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.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 TileEntityAuraTimer extends TileEntityImpl implements ITickableTile
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityAuraTimer extends TileEntityImpl implements ITickableTile
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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.PlayerEntity; import net.minecraft.entity.player.Player;
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.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
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 TileEntityAutoCrafter extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickableBlockEntity {
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(PlayerEntity playerIn) { public boolean canInteractWith(Player playerIn) {
return false; return false;
} }
}, 3, 3); }, 3, 3);
public TileEntityAutoCrafter() { public BlockEntityAutoCrafter() {
super(ModTileEntities.AUTO_CRAFTER); super(ModTileEntities.AUTO_CRAFTER);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote) { if (!this.level.isClientSide) {
if (this.world.getGameTime() % 60 != 0) if (this.level.getGameTime() % 60 != 0)
return; return;
if (!Multiblocks.AUTO_CRAFTER.isComplete(this.world, this.pos)) if (!Multiblocks.AUTO_CRAFTER.isComplete(this.level, this.worldPosition))
return; return;
this.crafting.clear(); this.crafting.clear();
BlockState state = this.world.getBlockState(this.pos); BlockState state = this.level.getBlockState(this.worldPosition);
Direction facing = state.get(BlockAutoCrafter.FACING); Direction facing = state.get(BlockAutoCrafter.FACING);
BlockPos middlePos = this.pos.up(); BlockPos middlePos = this.worldPosition.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 TileEntityAutoCrafter extends TileEntityImpl implements ITickableTi
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.world.getEntitiesWithinAABB( List<ItemEntity> entities = this.level.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 TileEntityAutoCrafter extends TileEntityImpl implements ITickableTi
this.crafting.setInventorySlotContents(i, stack.copy()); this.crafting.setInventorySlotContents(i, stack.copy());
} }
IRecipe recipe = this.world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, this.crafting, this.world).orElse(null); IRecipe recipe = this.level.getRecipeManager().getRecipe(IRecipeType.CRAFTING, this.crafting, this.level).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.world, ItemEntity resultItem = new ItemEntity(this.level,
this.pos.getX() + 0.5F, this.pos.getY() - 0.35F, this.pos.getZ() + 0.5F, result.copy()); this.worldPosition.getX() + 0.5F, this.worldPosition.getY() - 0.35F, this.worldPosition.getZ() + 0.5F, result.copy());
resultItem.setMotion(0, 0, 0); resultItem.setMotion(0, 0, 0);
this.world.addEntity(resultItem); this.level.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 TileEntityAutoCrafter extends TileEntityImpl implements ITickableTi
ItemStack remain = remainingItems.get(i); ItemStack remain = remainingItems.get(i);
if (!remain.isEmpty()) { if (!remain.isEmpty()) {
ItemEntity remItem = new ItemEntity(this.world, item.getPosX(), item.getPosY(), item.getPosZ(), remain.copy()); ItemEntity remItem = new ItemEntity(this.level, item.getPosX(), item.getPosY(), item.getPosZ(), remain.copy());
remItem.setMotion(0, 0, 0); remItem.setMotion(0, 0, 0);
this.world.addEntity(remItem); this.level.addEntity(remItem);
} }
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 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.BlastFurnaceTileEntity; import net.minecraft.tileentity.BlastFurnaceBlockEntity;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.BlockEntity;
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 TileEntityBlastFurnaceBooster extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityBlastFurnaceBooster extends BlockEntityImpl implements ITickableBlockEntity {
public TileEntityBlastFurnaceBooster() { public BlockEntityBlastFurnaceBooster() {
super(ModTileEntities.BLAST_FURNACE_BOOSTER); super(ModTileEntities.BLAST_FURNACE_BOOSTER);
} }
@Override @Override
public void tick() { public void tick() {
if (this.world.isRemote) if (this.level.isClientSide)
return; return;
TileEntity below = this.world.getTileEntity(this.pos.down()); BlockEntity below = this.level.getBlockEntity(this.worldPosition.down());
if (!(below instanceof BlastFurnaceTileEntity)) if (!(below instanceof BlastFurnaceBlockEntity))
return; return;
BlastFurnaceTileEntity tile = (BlastFurnaceTileEntity) below; BlastFurnaceBlockEntity tile = (BlastFurnaceBlockEntity) below;
IRecipe<?> recipe = this.world.getRecipeManager().getRecipe(TileEntityFurnaceHeater.getRecipeType(tile), tile, this.world).orElse(null); IRecipe<?> recipe = this.level.getRecipeManager().getRecipe(BlockEntityFurnaceHeater.getRecipeType(tile), tile, this.level).orElse(null);
if (recipe == null) if (recipe == null)
return; return;
if (!this.isApplicable(recipe.getIngredients())) if (!this.isApplicable(recipe.getIngredients()))
return; return;
IIntArray data = TileEntityFurnaceHeater.getFurnaceData(tile); IIntArray data = BlockEntityFurnaceHeater.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.world.rand.nextFloat() > 0.45F) { if (this.level.rand.nextFloat() > 0.45F) {
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.BLAST_FURNACE_BOOSTER, 0)); new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.BLAST_FURNACE_BOOSTER, 0));
return; return;
} }
@ -62,11 +62,11 @@ public class TileEntityBlastFurnaceBooster extends TileEntityImpl implements ITi
output.grow(1); output.grow(1);
} }
BlockPos pos = IAuraChunk.getHighestSpot(this.world, this.pos, 30, this.pos); BlockPos pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 30, this.worldPosition);
IAuraChunk.getAuraChunk(this.world, pos).drainAura(pos, 6500); IAuraChunk.getAuraChunk(this.level, pos).drainAura(pos, 6500);
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.BLAST_FURNACE_BOOSTER, 1)); new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.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 TileEntityBlastFurnaceBooster extends TileEntityImpl implements ITi
@Override @Override
public IItemHandlerModifiable getItemHandler() { public IItemHandlerModifiable getItemHandler() {
TileEntity below = this.world.getTileEntity(this.pos.down()); BlockEntity below = this.level.getBlockEntity(this.worldPosition.down());
if (!(below instanceof BlastFurnaceTileEntity)) if (!(below instanceof BlastFurnaceBlockEntity))
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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
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 TileEntityChorusGenerator extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityChorusGenerator extends BlockEntityImpl implements ITickableBlockEntity {
private final Deque<BlockPos> currentlyBreaking = new ArrayDeque<>(); private final Deque<BlockPos> currentlyBreaking = new ArrayDeque<>();
private int auraPerBlock; private int auraPerBlock;
public TileEntityChorusGenerator() { public BlockEntityChorusGenerator() {
super(ModTileEntities.CHORUS_GENERATOR); super(ModTileEntities.CHORUS_GENERATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (this.world.isRemote) if (this.level.isClientSide)
return; return;
if (this.world.getGameTime() % 5 != 0) if (this.level.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.world.getBlockState(pos); BlockState state = this.level.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.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())); 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()));
this.world.removeBlock(pos, false); this.level.removeBlock(pos, false);
this.world.playSound(null, this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5, this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.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 TileEntityChorusGenerator extends TileEntityImpl implements ITickab
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.pos.add(x, y, z); BlockPos offset = this.worldPosition.add(x, y, z);
BlockState below = this.world.getBlockState(offset.down()); BlockState below = this.level.getBlockState(offset.down());
if (below.getBlock() != Blocks.END_STONE) if (below.getBlock() != Blocks.END_STONE)
continue; continue;
BlockState state = this.world.getBlockState(offset); BlockState state = this.level.getBlockState(offset);
if (state.getBlock() != Blocks.CHORUS_PLANT) if (state.getBlock() != Blocks.CHORUS_PLANT)
continue; continue;
@ -90,7 +90,7 @@ public class TileEntityChorusGenerator extends TileEntityImpl implements ITickab
BlockPos offset = pos.offset(dir); BlockPos offset = pos.offset(dir);
if (blocks.contains(offset)) if (blocks.contains(offset))
continue; continue;
BlockState state = this.world.getBlockState(offset); BlockState state = this.level.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 TileEntityChorusGenerator extends TileEntityImpl implements ITickab
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityChorusGenerator extends TileEntityImpl implements ITickab
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
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.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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 TileEntityChunkLoader extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickableBlockEntity {
private final List<ChunkPos> forcedChunks = new ArrayList<>(); private final List<ChunkPos> forcedChunks = new ArrayList<>();
private boolean firstTick = true; private boolean firstTick = true;
public TileEntityChunkLoader() { public BlockEntityChunkLoader() {
super(ModTileEntities.CHUNK_LOADER); super(ModTileEntities.CHUNK_LOADER);
} }
@ -32,7 +32,7 @@ public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTi
@Override @Override
public void onRedstonePowerChange(int newPower) { public void onRedstonePowerChange(int newPower) {
super.onRedstonePowerChange(newPower); super.onRedstonePowerChange(newPower);
if (!this.world.isRemote) { if (!this.level.isClientSide) {
this.loadChunks(false); this.loadChunks(false);
this.sendToClients(); this.sendToClients();
} }
@ -43,19 +43,19 @@ public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTi
} }
private void loadChunks(boolean unload) { private void loadChunks(boolean unload) {
if (this.world.isRemote || !ModConfig.instance.chunkLoader.get()) if (this.level.isClientSide || !ModConfig.instance.chunkLoader.get())
return; return;
ServerWorld world = (ServerWorld) this.world; ServerLevel level = (ServerLevel) this.level;
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.pos.getX() - range) >> 4; x <= (this.pos.getX() + range) >> 4; x++) { for (int x = (this.worldPosition.getX() - range) >> 4; x <= (this.worldPosition.getX() + range) >> 4; x++) {
for (int z = (this.pos.getZ() - range) >> 4; z <= (this.pos.getZ() + range) >> 4; z++) { for (int z = (this.worldPosition.getZ() - range) >> 4; z <= (this.worldPosition.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) || !world.getForcedChunks().contains(pos.asLong())) if (this.forcedChunks.contains(pos) || !level.getForcedChunks().contains(pos.asLong()))
shouldBeForced.add(pos); shouldBeForced.add(pos);
} }
} }
@ -65,20 +65,20 @@ public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTi
// 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))
world.forceChunk(pos.x, pos.z, false); level.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) {
world.forceChunk(pos.x, pos.z, true); level.forceChunk(pos.x, pos.z, true);
this.forcedChunks.add(pos); this.forcedChunks.add(pos);
} }
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote && ModConfig.instance.chunkLoader.get()) { if (!this.level.isClientSide && 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 TileEntityChunkLoader extends TileEntityImpl implements ITickableTi
this.firstTick = false; this.firstTick = false;
} }
if (this.world.getGameTime() % 20 != 0) if (this.level.getGameTime() % 20 != 0)
return; return;
int toUse = MathHelper.ceil(this.range() / 2F); int toUse = Mth.ceil(this.range() / 2F);
if (toUse > 0) { if (toUse > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, toUse); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, toUse);
} }
} }
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
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 TileEntityEndFlower extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBlockEntity {
private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) { private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) {
{ {
@ -34,7 +34,7 @@ public class TileEntityEndFlower extends TileEntityImpl implements ITickableTile
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)
TileEntityEndFlower.this.sendToClients(); BlockEntityEndFlower.this.sendToClients();
return amount; return amount;
} }
@ -46,19 +46,19 @@ public class TileEntityEndFlower extends TileEntityImpl implements ITickableTile
public boolean isDrainMode; public boolean isDrainMode;
public TileEntityEndFlower() { public BlockEntityEndFlower() {
super(ModTileEntities.END_FLOWER); super(ModTileEntities.END_FLOWER);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote) { if (!this.level.isClientSide) {
if (this.world.getGameTime() % 10 != 0) if (this.level.getGameTime() % 10 != 0)
return; return;
if (!this.isDrainMode) { if (!this.isDrainMode) {
List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class,
new AxisAlignedBB(this.pos).grow(1), EntityPredicates.IS_ALIVE); new AxisAlignedBB(this.worldPosition).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 TileEntityEndFlower extends TileEntityImpl implements ITickableTile
this.isDrainMode = true; this.isDrainMode = true;
item.remove(); item.remove();
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 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 TileEntityEndFlower extends TileEntityImpl implements ITickableTile
this.generateAura(toDrain); this.generateAura(toDrain);
if (this.container.getStoredAura() <= 0) { if (this.container.getStoredAura() <= 0) {
this.world.setBlockState(this.pos, Blocks.DEAD_BUSH.getDefaultState()); this.level.setBlockState(this.worldPosition, Blocks.DEAD_BUSH.getDefaultState());
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.END_FLOWER_DECAY, this.container.getAuraColor())); new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.END_FLOWER_DECAY, this.container.getAuraColor()));
} }
} }
} else { } else {
if (this.isDrainMode && this.world.getGameTime() % 5 == 0) if (this.isDrainMode && this.level.getGameTime() % 5 == 0)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
this.pos.getX() + 0.25F + this.world.rand.nextFloat() * 0.5F, this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F,
this.pos.getY() + 0.25F + this.world.rand.nextFloat() * 0.5F, this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F,
this.pos.getZ() + 0.25F + this.world.rand.nextFloat() * 0.5F, this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F,
this.world.rand.nextGaussian() * 0.05F, this.level.rand.nextGaussian() * 0.05F,
this.world.rand.nextFloat() * 0.1F, this.level.rand.nextFloat() * 0.1F,
this.world.rand.nextGaussian() * 0.05F, this.level.rand.nextGaussian() * 0.05F,
this.container.getAuraColor(), this.world.rand.nextFloat() * 2F + 1F, 50, 0F, false, true); this.container.getAuraColor(), this.level.rand.nextFloat() * 2F + 1F, 50, 0F, false, true);
} }
} }
@ -105,7 +105,7 @@ public class TileEntityEndFlower extends TileEntityImpl implements ITickableTile
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityEndFlower extends TileEntityImpl implements ITickableTile
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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.IWorldData; import de.ellpeck.naturesaura.api.misc.ILevelData;
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.PlayerEntity; import net.minecraft.entity.player.Player;
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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
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 TileEntityEnderCrate extends TileEntityImpl implements INamedContainerProvider { public class BlockEntityEnderCrate extends BlockEntityImpl 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 TileEntityEnderCrate extends TileEntityImpl implements INamedContai
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)
TileEntityEnderCrate.this.drainAura((stack.getCount() - remain.getCount()) * 20); BlockEntityEnderCrate.this.drainAura((stack.getCount() - remain.getCount()) * 20);
return remain; return remain;
} }
@ -55,7 +55,7 @@ public class TileEntityEnderCrate extends TileEntityImpl implements INamedContai
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)
TileEntityEnderCrate.this.drainAura(extracted.getCount() * 20); BlockEntityEnderCrate.this.drainAura(extracted.getCount() * 20);
return extracted; return extracted;
} }
@ -70,11 +70,11 @@ public class TileEntityEnderCrate extends TileEntityImpl implements INamedContai
} }
private IItemHandlerModifiable getStorage() { private IItemHandlerModifiable getStorage() {
return IWorldData.getOverworldData(TileEntityEnderCrate.this.world).getEnderStorage(TileEntityEnderCrate.this.name); return ILevelData.getOverworldData(BlockEntityEnderCrate.this.level).getEnderStorage(BlockEntityEnderCrate.this.name);
} }
}; };
public TileEntityEnderCrate() { public BlockEntityEnderCrate() {
super(ModTileEntities.ENDER_CRATE); super(ModTileEntities.ENDER_CRATE);
} }
@ -97,7 +97,7 @@ public class TileEntityEnderCrate extends TileEntityImpl implements INamedContai
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 CompoundNBT()); regularItem.setTag(new CompoundTag());
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 TileEntityEnderCrate extends TileEntityImpl implements INamedContai
@Override @Override
public void loadDataOnPlace(ItemStack stack) { public void loadDataOnPlace(ItemStack stack) {
super.loadDataOnPlace(stack); super.loadDataOnPlace(stack);
if (!this.world.isRemote) { if (!this.level.isClientSide) {
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 TileEntityEnderCrate extends TileEntityImpl implements INamedContai
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityEnderCrate extends TileEntityImpl implements INamedContai
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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 TileEntityEnderCrate extends TileEntityImpl implements INamedContai
public void drainAura(int amount) { public void drainAura(int amount) {
if (amount > 0) { if (amount > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, amount); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, amount);
} }
} }
@ -144,7 +144,7 @@ public class TileEntityEnderCrate extends TileEntityImpl implements INamedContai
@Nullable @Nullable
@Override @Override
public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) { public Container createMenu(int window, PlayerInventory inv, Player 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.server.ServerWorld; import net.minecraft.level.server.ServerLevel;
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.world.BlockEvent; import net.minecraftforge.event.level.BlockEvent;
import java.util.List; import java.util.List;
public class TileEntityFieldCreator extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickableBlockEntity {
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 TileEntityFieldCreator() { public BlockEntityFieldCreator() {
super(ModTileEntities.FIELD_CREATOR); super(ModTileEntities.FIELD_CREATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (this.world.isRemote || this.world.getGameTime() % 10 != 0) if (this.level.isClientSide || this.level.getGameTime() % 10 != 0)
return; return;
BlockPos connectedPos = this.getConnectedPos(); BlockPos connectedPos = this.getConnectedPos();
if (connectedPos == null || !this.world.isBlockLoaded(connectedPos)) if (connectedPos == null || !this.level.isBlockLoaded(connectedPos))
return; return;
TileEntity other = this.world.getTileEntity(connectedPos); BlockEntity other = this.level.getBlockEntity(connectedPos);
if (!this.isCloseEnough(connectedPos) if (!this.isCloseEnough(connectedPos)
|| !(other instanceof TileEntityFieldCreator) || !(other instanceof BlockEntityFieldCreator)
|| !this.pos.equals(((TileEntityFieldCreator) other).getConnectedPos())) { || !this.worldPosition.equals(((BlockEntityFieldCreator) 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 TileEntityFieldCreator extends TileEntityImpl implements ITickableT
if (!this.isMain) if (!this.isMain)
return; return;
TileEntityFieldCreator creator = (TileEntityFieldCreator) other; BlockEntityFieldCreator creator = (BlockEntityFieldCreator) 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 TileEntityFieldCreator extends TileEntityImpl implements ITickableT
return; return;
} }
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 32, this.pos); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 32, this.worldPosition);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.world, spot); IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot);
if (!this.isCharged) { if (!this.isCharged) {
this.chargeTimer += 10; this.chargeTimer += 10;
@ -91,41 +91,41 @@ public class TileEntityFieldCreator extends TileEntityImpl implements ITickableT
chunk.drainAura(spot, 300); chunk.drainAura(spot, 300);
this.sendParticles(); this.sendParticles();
} else { } else {
if (this.world.getGameTime() % 40 == 0) if (this.level.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.pos.getX() - connectedPos.getX(), this.worldPosition.getX() - connectedPos.getX(),
this.pos.getY() - connectedPos.getY(), this.worldPosition.getY() - connectedPos.getY(),
this.pos.getZ() - connectedPos.getZ() this.worldPosition.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 = MathHelper.floor(length); i > 0; i -= 0.5F) { for (float i = Mth.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(
MathHelper.floor(scaled.x + 0.5F), Mth.floor(scaled.x + 0.5F),
MathHelper.floor(scaled.y + 0.5F), Mth.floor(scaled.y + 0.5F),
MathHelper.floor(scaled.z + 0.5F)); Mth.floor(scaled.z + 0.5F));
if (pos.equals(this.pos) || pos.equals(connectedPos)) if (pos.equals(this.worldPosition) || pos.equals(connectedPos))
continue; continue;
BlockState state = this.world.getBlockState(pos); BlockState state = this.level.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
if (!block.isAir(state, this.world, pos) && state.getBlockHardness(this.world, pos) >= 0F) { if (!block.isAir(state, this.level, pos) && state.getBlockHardness(this.level, pos) >= 0F) {
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerWorld) this.world); FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level);
if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.world, pos, state, fake))) { if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.level, pos, state, fake))) {
List<ItemStack> drops = state.getDrops(new LootContext.Builder((ServerWorld) this.world) List<ItemStack> drops = state.getDrops(new LootContext.Builder((ServerLevel) this.level)
.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.world.getTileEntity(pos))); .withNullableParameter(LootParameters.BLOCK_ENTITY, this.level.getBlockEntity(pos)));
this.world.destroyBlock(pos, false); this.level.destroyBlock(pos, false);
for (ItemStack stack : drops) for (ItemStack stack : drops)
Block.spawnAsEntity(this.world, pos, stack); Block.spawnAsEntity(this.level, 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 TileEntityFieldCreator extends TileEntityImpl implements ITickableT
} }
} }
private ItemStack getToolUsed(TileEntityFieldCreator other) { private ItemStack getToolUsed(BlockEntityFieldCreator 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.world.rand.nextBoolean() ? myTool : otherTool; return this.level.rand.nextBoolean() ? myTool : otherTool;
return myTool; return myTool;
} }
return otherTool; return otherTool;
} }
private ItemStack getMyTool() { private ItemStack getMyTool() {
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.world, this.pos); List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
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 TileEntityFieldCreator extends TileEntityImpl implements ITickableT
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.pos : this.getConnectedPos(); BlockPos p = j == 0 ? this.worldPosition : this.getConnectedPos();
PacketHandler.sendToAllAround(this.world, p, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, p, 32, new PacketParticleStream(
p.getX() + (float) this.world.rand.nextGaussian() * 3F, p.getX() + (float) this.level.rand.nextGaussian() * 3F,
p.getY() + 1 + this.world.rand.nextFloat() * 3F, p.getY() + 1 + this.level.rand.nextFloat() * 3F,
p.getZ() + (float) this.world.rand.nextGaussian() * 3F, p.getZ() + (float) this.level.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.world.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forWorld(this.world).getColor(), this.world.rand.nextFloat() + 0.5F this.level.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.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.pos.distanceSq(pos) <= range * range; return this.worldPosition.distanceSq(pos) <= range * range;
} }
public BlockPos getConnectedPos() { public BlockPos getConnectedPos() {
if (this.connectionOffset == null) if (this.connectionOffset == null)
return null; return null;
return this.pos.add(this.connectionOffset); return this.worldPosition.add(this.connectionOffset);
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityFieldCreator extends TileEntityImpl implements ITickableT
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.INBT;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListNBT;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
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.MathHelper; import net.minecraft.util.math.Mth;
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 TileEntityFireworkGenerator extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITickableBlockEntity {
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 TileEntityFireworkGenerator() { public BlockEntityFireworkGenerator() {
super(ModTileEntities.FIREWORK_GENERATOR); super(ModTileEntities.FIREWORK_GENERATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote) { if (!this.level.isClientSide) {
if (this.world.getGameTime() % 10 == 0) { if (this.level.getGameTime() % 10 == 0) {
List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class,
new AxisAlignedBB(this.pos).grow(4), EntityPredicates.IS_ALIVE); new AxisAlignedBB(this.worldPosition).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 TileEntityFireworkGenerator extends TileEntityImpl implements ITick
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.world, item.getPosX(), item.getPosY(), item.getPosZ(), stack); FireworkRocketEntity entity = new FireworkRocketEntity(this.level, item.getPosX(), item.getPosY(), item.getPosZ(), stack);
this.trackedEntity = entity; this.trackedEntity = entity;
this.trackedItem = stack.copy(); this.trackedItem = stack.copy();
this.world.addEntity(entity); this.level.addEntity(entity);
} }
stack.shrink(1); stack.shrink(1);
if (stack.isEmpty()) if (stack.isEmpty())
@ -64,8 +64,8 @@ public class TileEntityFireworkGenerator extends TileEntityImpl implements ITick
float generateFactor = 0; float generateFactor = 0;
Set<Integer> usedColors = new HashSet<>(); Set<Integer> usedColors = new HashSet<>();
CompoundNBT compound = this.trackedItem.getTag(); CompoundTag compound = this.trackedItem.getTag();
CompoundNBT fireworks = compound.getCompound("Fireworks"); CompoundTag 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 TileEntityFireworkGenerator extends TileEntityImpl implements ITick
generateFactor += flightTime; generateFactor += flightTime;
for (INBT base : explosions) { for (INBT base : explosions) {
CompoundNBT explosion = (CompoundNBT) base; CompoundTag explosion = (CompoundTag) base;
generateFactor += 1.5F; generateFactor += 1.5F;
boolean flicker = explosion.getBoolean("Flicker"); boolean flicker = explosion.getBoolean("Flicker");
@ -97,18 +97,18 @@ public class TileEntityFireworkGenerator extends TileEntityImpl implements ITick
} }
if (generateFactor > 0) { if (generateFactor > 0) {
int toAdd = MathHelper.ceil(generateFactor * 10000F); int toAdd = Mth.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.pos.getX()); data.add(this.worldPosition.getX());
data.add(this.pos.getY()); data.add(this.worldPosition.getY());
data.add(this.pos.getZ()); data.add(this.worldPosition.getZ());
data.addAll(usedColors); data.addAll(usedColors);
PacketHandler.sendToAllLoaded(this.world, this.pos, new PacketParticles( PacketHandler.sendToAllLoaded(this.level, this.worldPosition, 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 TileEntityFireworkGenerator extends TileEntityImpl implements ITick
this.generateAura(this.toRelease); this.generateAura(this.toRelease);
this.toRelease = 0; this.toRelease = 0;
PacketHandler.sendToAllLoaded(this.world, this.pos, PacketHandler.sendToAllLoaded(this.level, this.worldPosition,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION)); new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
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.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
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 TileEntityFlowerGenerator extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITickableBlockEntity {
private final Map<BlockState, MutableInt> consumedRecently = new HashMap<>(); private final Map<BlockState, MutableInt> consumedRecently = new HashMap<>();
public TileEntityFlowerGenerator() { public BlockEntityFlowerGenerator() {
super(ModTileEntities.FLOWER_GENERATOR); super(ModTileEntities.FLOWER_GENERATOR);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote && this.world.getGameTime() % 10 == 0) { if (!this.level.isClientSide && this.level.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.pos.add(x, y, z); BlockPos offset = this.worldPosition.add(x, y, z);
BlockState state = this.world.getBlockState(offset); BlockState state = this.level.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 TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
if (possible.isEmpty()) if (possible.isEmpty())
return; return;
BlockPos pos = possible.get(this.world.rand.nextInt(possible.size())); BlockPos pos = possible.get(this.level.rand.nextInt(possible.size()));
BlockState state = this.world.getBlockState(pos); BlockState state = this.level.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.forWorld(this.world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(toAdd)) { if (IAuraType.forLevel(this.level).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 TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
} }
curr.add(5); curr.add(5);
this.world.removeBlock(pos, false); this.level.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.world.rand.nextInt(5) + 5; i >= 0; i--) for (int i = this.level.rand.nextInt(5) + 5; i >= 0; i--)
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream(
pos.getX() + 0.25F + this.world.rand.nextFloat() * 0.5F, pos.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F,
pos.getY() + 0.25F + this.world.rand.nextFloat() * 0.5F, pos.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F,
pos.getZ() + 0.25F + this.world.rand.nextFloat() * 0.5F, pos.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F,
this.pos.getX() + 0.25F + this.world.rand.nextFloat() * 0.5F, this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F,
this.pos.getY() + 0.25F + this.world.rand.nextFloat() * 0.5F, this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F,
this.pos.getZ() + 0.25F + this.world.rand.nextFloat() * 0.5F, this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F,
this.world.rand.nextFloat() * 0.02F + 0.1F, color, 1F this.level.rand.nextFloat() * 0.02F + 0.1F, color, 1F
)); ));
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(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));
} }
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(pos.getX(), pos.getY(), pos.getZ(), PacketParticles.Type.FLOWER_GEN_CONSUME, color)); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(pos.getX(), pos.getY(), pos.getZ(), PacketParticles.Type.FLOWER_GEN_CONSUME, color));
} }
} }
@ -100,7 +100,7 @@ public class TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
BlockState state = entry.getKey(); BlockState state = entry.getKey();
Block block = state.getBlock(); Block block = state.getBlock();
CompoundNBT tag = new CompoundNBT(); CompoundTag tag = new CompoundTag();
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 TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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) {
CompoundNBT tag = (CompoundNBT) base; CompoundTag tag = (CompoundTag) 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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
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.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.lang.reflect.Field; import java.lang.reflect.Field;
public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickableBlockEntity {
private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceTileEntity.class, "field_214013_b"); private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceBlockEntity.class, "field_214013_b");
public boolean isActive; public boolean isActive;
public TileEntityFurnaceHeater() { public BlockEntityFurnaceHeater() {
super(ModTileEntities.FURNACE_HEATER); super(ModTileEntities.FURNACE_HEATER);
} }
public static IIntArray getFurnaceData(AbstractFurnaceTileEntity tile) { public static IIntArray getFurnaceData(AbstractFurnaceBlockEntity 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 TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
} }
} }
public static IRecipeType<? extends AbstractCookingRecipe> getRecipeType(AbstractFurnaceTileEntity furnace) { public static IRecipeType<? extends AbstractCookingRecipe> getRecipeType(AbstractFurnaceBlockEntity furnace) {
if (furnace instanceof BlastFurnaceTileEntity) { if (furnace instanceof BlastFurnaceBlockEntity) {
return IRecipeType.BLASTING; return IRecipeType.BLASTING;
} else if (furnace instanceof SmokerTileEntity) { } else if (furnace instanceof SmokerBlockEntity) {
return IRecipeType.SMOKING; return IRecipeType.SMOKING;
} else { } else {
return IRecipeType.SMELTING; return IRecipeType.SMELTING;
@ -51,38 +51,38 @@ public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote && this.world.getGameTime() % 5 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 5 == 0) {
boolean did = false; boolean did = false;
Direction facing = this.world.getBlockState(this.pos).get(BlockFurnaceHeater.FACING); Direction facing = this.level.getBlockState(this.worldPosition).get(BlockFurnaceHeater.FACING);
BlockPos tilePos = this.pos.offset(facing.getOpposite()); BlockPos tilePos = this.worldPosition.offset(facing.getOpposite());
TileEntity tile = this.world.getTileEntity(tilePos); BlockEntity tile = this.level.getBlockEntity(tilePos);
if (tile instanceof AbstractFurnaceTileEntity) { if (tile instanceof AbstractFurnaceBlockEntity) {
AbstractFurnaceTileEntity furnace = (AbstractFurnaceTileEntity) tile; AbstractFurnaceBlockEntity furnace = (AbstractFurnaceBlockEntity) 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.world.setBlockState(tilePos, this.world.getBlockState(tilePos).with(AbstractFurnaceBlock.LIT, true)); this.level.setBlockState(tilePos, this.level.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.world, this.pos, 20, this.pos); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.world, spot); IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot);
chunk.drainAura(spot, MathHelper.ceil((200 - burnTime) * 16.6F)); chunk.drainAura(spot, Mth.ceil((200 - burnTime) * 16.6F));
did = true; did = true;
if (this.world.getGameTime() % 15 == 0) { if (this.level.getGameTime() % 15 == 0) {
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream(
this.pos.getX() + (float) this.world.rand.nextGaussian() * 5F, this.worldPosition.getX() + (float) this.level.rand.nextGaussian() * 5F,
this.pos.getY() + 1 + this.world.rand.nextFloat() * 5F, this.worldPosition.getY() + 1 + this.level.rand.nextFloat() * 5F,
this.pos.getZ() + (float) this.world.rand.nextGaussian() * 5F, this.worldPosition.getZ() + (float) this.level.rand.nextGaussian() * 5F,
tilePos.getX() + this.world.rand.nextFloat(), tilePos.getX() + this.level.rand.nextFloat(),
tilePos.getY() + this.world.rand.nextFloat(), tilePos.getY() + this.level.rand.nextFloat(),
tilePos.getZ() + this.world.rand.nextFloat(), tilePos.getZ() + this.level.rand.nextFloat(),
this.world.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forWorld(this.world).getColor(), this.world.rand.nextFloat() + 0.5F this.level.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.rand.nextFloat() + 0.5F
)); ));
} }
} }
@ -95,13 +95,13 @@ public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
} }
} }
private boolean isReady(AbstractFurnaceTileEntity furnace) { private boolean isReady(AbstractFurnaceBlockEntity 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.world.getRecipeManager().getRecipe(getRecipeType(furnace), furnace, this.world).orElse(null); AbstractCookingRecipe recipe = this.level.getRecipeManager().getRecipe(getRecipeType(furnace), furnace, this.level).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 TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityFurnaceHeater extends TileEntityImpl implements ITickable
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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 TileEntityGeneratorLimitRemover extends TileEntityImpl { public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl {
public TileEntityGeneratorLimitRemover() { public BlockEntityGeneratorLimitRemover() {
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.pos, this.pos.add(1, 2, 1)); return new AxisAlignedBB(this.worldPosition, this.worldPosition.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.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.BlockEntity;
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 TileEntityGratedChute extends TileEntityImpl implements ITickableTileEntity { public class BlockEntityGratedChute extends BlockEntityImpl implements ITickableBlockEntity {
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 TileEntityGratedChute.this.redstonePower <= 0; return BlockEntityGratedChute.this.redstonePower <= 0;
} }
@Override @Override
protected boolean canInsert(ItemStack stack, int slot) { protected boolean canInsert(ItemStack stack, int slot) {
return TileEntityGratedChute.this.isBlacklist != TileEntityGratedChute.this.isItemInFrame(stack); return BlockEntityGratedChute.this.isBlacklist != BlockEntityGratedChute.this.isItemInFrame(stack);
} }
}; };
private int cooldown; private int cooldown;
public TileEntityGratedChute() { public BlockEntityGratedChute() {
super(ModTileEntities.GRATED_CHUTE); super(ModTileEntities.GRATED_CHUTE);
} }
@Override @Override
public void tick() { public void tick() {
if (!this.world.isRemote) { if (!this.level.isClientSide) {
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 TileEntityGratedChute extends TileEntityImpl implements ITickableTi
ItemStack curr = this.items.getStackInSlot(0); ItemStack curr = this.items.getStackInSlot(0);
push: push:
if (!curr.isEmpty()) { if (!curr.isEmpty()) {
BlockState state = this.world.getBlockState(this.pos); BlockState state = this.level.getBlockState(this.worldPosition);
Direction facing = state.get(BlockGratedChute.FACING); Direction facing = state.get(BlockGratedChute.FACING);
TileEntity tile = this.world.getTileEntity(this.pos.offset(facing)); BlockEntity tile = this.level.getBlockEntity(this.worldPosition.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 TileEntityGratedChute extends TileEntityImpl implements ITickableTi
} }
pull: pull:
if (curr.isEmpty() || curr.getCount() < curr.getMaxStackSize()) { if (curr.isEmpty() || curr.getCount() < curr.getMaxStackSize()) {
List<ItemEntity> items = this.world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB( List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(
this.pos.getX(), this.pos.getY() + 0.5, this.pos.getZ(), this.worldPosition.getX(), this.worldPosition.getY() + 0.5, this.worldPosition.getZ(),
this.pos.getX() + 1, this.pos.getY() + 2, this.pos.getZ() + 1)); this.worldPosition.getX() + 1, this.worldPosition.getY() + 2, this.worldPosition.getZ() + 1));
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (!item.isAlive()) if (!item.isAlive())
continue; continue;
@ -89,7 +89,7 @@ public class TileEntityGratedChute extends TileEntityImpl implements ITickableTi
} }
} }
TileEntity tileUp = this.world.getTileEntity(this.pos.up()); BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.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 TileEntityGratedChute extends TileEntityImpl implements ITickableTi
} }
private boolean isItemInFrame(ItemStack stack) { private boolean isItemInFrame(ItemStack stack) {
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.world, this.pos); List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
if (frames.isEmpty()) if (frames.isEmpty())
return false; return false;
for (ItemFrameEntity frame : frames) { for (ItemFrameEntity frame : frames) {
@ -125,7 +125,7 @@ public class TileEntityGratedChute extends TileEntityImpl implements ITickableTi
} }
@Override @Override
public void writeNBT(CompoundNBT compound, SaveType type) { public void writeNBT(CompoundTag 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 TileEntityGratedChute extends TileEntityImpl implements ITickableTi
} }
@Override @Override
public void readNBT(CompoundNBT compound, SaveType type) { public void readNBT(CompoundTag 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");

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