diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index eddd4b0..c3d4b35 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -33,6 +33,7 @@ body: attributes: label: What Minecraft version is this happening on? options: + - Minecraft 1.18.1 - Minecraft 1.16.5 - type: input id: forge diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a80204c..080dd9f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,45 +8,37 @@ jobs: strategy: matrix: java: [ - 8 + 17 ] os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Setup JDK ${{ matrix.java }} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - # https://docs.sonarqube.org/latest/analysis/github-integration/ - #- name: Cache SonarQube packages - # uses: actions/cache@v1 - # with: - # path: ~/.sonar/cache - # key: ${{ runner.os }}-sonar - # restore-keys: ${{ runner.os }}-sonar - - name: Cache Gradle packages - uses: actions/cache@v1 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - name: Make Gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: Build - run: ./gradlew build - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - name: Upload build artifacts - if: ${{ runner.os == 'Linux' && matrix.java == '8' }} - uses: actions/upload-artifact@v2 - with: - name: Artifacts - path: build/libs/ + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Setup JDK ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: Cache Gradle packages + uses: actions/cache@v1 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Make Gradle wrapper executable + if: ${{ runner.os != 'Windows' }} + run: chmod +x ./gradlew + - name: Build + run: ./gradlew build + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload build artifacts + if: ${{ runner.os == 'Linux' && matrix.java == '17' }} + uses: actions/upload-artifact@v2 + with: + name: Artifacts + path: build/libs/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e1f107f..369d1b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,69 +7,77 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Get tag name - uses: olegtarasov/get-tag@v2.1 - id: tagName - - name: Validate semver - run: | - echo $GIT_TAG_NAME | grep -oP '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' - - name: Checkout repository - uses: actions/checkout@v2 - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Setup JDK 8 - uses: actions/setup-java@v1 - with: - java-version: 8 - - name: Make Gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: Build - run: ./gradlew build - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - RELEASE: ${{ steps.tagName.outputs.tag }} - - name: Publish - run: ./gradlew publish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE: ${{ steps.tagName.outputs.tag }} - - name: Retrieve changelog - id: changelog_reader - uses: mindsers/changelog-reader-action@v2 - with: - version: 'Unreleased' - path: ./CHANGELOG.md - - name: Release on GitHub - uses: softprops/action-gh-release@v1 - id: ghRelease - with: - body: ${{ steps.changelog_reader.outputs.changes }} - name: ${{ steps.tagName.outputs.tag }} - files: | - build/libs/*.jar - - name: Release on CurseForge - run: ./gradlew curseforge - env: - RELEASE: ${{ steps.tagName.outputs.tag }} - CHANGELOG: ${{ steps.changelog_reader.outputs.changes }} - CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + - name: Get tag name + uses: olegtarasov/get-tag@v2.1 + id: tagName + - name: Validate semver + run: | + echo $GIT_TAG_NAME | grep -oP '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' + - name: Checkout repository + uses: actions/checkout@v2 + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Setup JDK 17 + uses: actions/setup-java@v1 + with: + java-version: 17 + - name: Make Gradle wrapper executable + if: ${{ runner.os != 'Windows' }} + run: chmod +x ./gradlew + - name: Build + run: ./gradlew build + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE: ${{ steps.tagName.outputs.tag }} + - name: Build documentation + run: ./gradlew javadoc + env: + RELEASE: ${{ steps.tagName.outputs.tag }} + - name: Publish documentation + uses: JamesIves/github-pages-deploy-action@4.1.5 + with: + branch: gh-pages + folder: build/docs/javadoc + - name: Publish + run: ./gradlew publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE: ${{ steps.tagName.outputs.tag }} + - name: Retrieve changelog + id: changelog_reader + uses: mindsers/changelog-reader-action@v2 + with: + version: 'Unreleased' + path: ./CHANGELOG.md + - name: Release on GitHub + uses: softprops/action-gh-release@v1 + id: ghRelease + with: + body: ${{ steps.changelog_reader.outputs.changes }} + name: ${{ steps.tagName.outputs.tag }} + files: | + build/libs/*.jar + - name: Release on CurseForge + run: ./gradlew curseforge + env: + RELEASE: ${{ steps.tagName.outputs.tag }} + CHANGELOG: ${{ steps.changelog_reader.outputs.changes }} + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} # This is necessary because the Discord action doesn't support GH actions variable expansion? - - name: Set release URL - run: | - echo "RELEASE_URL=${{ steps.ghRelease.outputs.url }}" >> $GITHUB_ENV - - name: Notify Discord - uses: Ilshidur/action-discord@0.3.2 - with: - args: 'Refined Pipes {{ GIT_TAG_NAME }} has been released! {{ RELEASE_URL }}' - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - - name: Notify Twitter - uses: ethomson/send-tweet-action@v1 - with: - status: Refined Pipes ${{ env.GIT_TAG_NAME }} has been released! ${{ env.RELEASE_URL }} - consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }} - consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} - access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} - access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} + - name: Set release URL + run: | + echo "RELEASE_URL=${{ steps.ghRelease.outputs.url }}" >> $GITHUB_ENV + - name: Notify Discord + uses: Ilshidur/action-discord@0.3.2 + with: + args: 'Refined Pipes {{ GIT_TAG_NAME }} has been released! {{ RELEASE_URL }}' + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + - name: Notify Twitter + uses: ethomson/send-tweet-action@v1 + with: + status: Refined Pipes ${{ env.GIT_TAG_NAME }} has been released! ${{ env.RELEASE_URL }} + consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }} + consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} + access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} + access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} diff --git a/CHANGELOG.md b/CHANGELOG.md index d094cda..86c7323 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added +- Ported to Minecraft 1.18.1. + +## [0.5.1] - 2021-11-28 + +### Added + - Added Italian translation by [@maicol07](https://github.com/maicol07). - Updated Russian translation by [@KnottyManatee55](https://github.com/KnottyManatee55). - Updated Spanish translations by [@d-l-n](https://github.com/d-l-n). diff --git a/build.gradle b/build.gradle index 6a13047..8be752c 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'maven-publish' group = 'com.refinedmods' archivesBaseName = 'refinedpipes' -version = '0.5.1' +version = '0.6.0' if (System.getenv('GITHUB_SHA') != null) { version += '+' + System.getenv('GITHUB_SHA').substring(0, 7) @@ -35,10 +35,10 @@ if (System.getenv('RELEASE') != null) { version = System.getenv('RELEASE').substring(1) // remove 'v' } -java.toolchain.languageVersion = JavaLanguageVersion.of(8) +java.toolchain.languageVersion = JavaLanguageVersion.of(17) minecraft { - mappings channel: 'snapshot', version: '20200723-1.16.1' + mappings channel: 'official', version: '1.18.1' runs { client { @@ -52,12 +52,6 @@ minecraft { } } - intellijClient { - parent runs.client - ideaModule "${project.name}.main" - environment 'MOD_CLASSES', "${project.file("out/production/resources").canonicalPath};${project.file("out/production/classes").canonicalPath}" - } - server { workingDirectory project.file('run') property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' @@ -92,8 +86,8 @@ processResources { } dependencies { - minecraft 'net.minecraftforge:forge:1.16.5-36.2.19' - runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.7.1.137") + minecraft 'net.minecraftforge:forge:1.18.1-39.0.0' + runtimeOnly fg.deobf("mezz.jei:jei-1.18.1:9.1.0.41") } jar { @@ -144,4 +138,8 @@ publishing { } } +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + jar.finalizedBy('reobfJar') diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..7454180 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 05679dc..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 index 4f906e0..c53aefa --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# 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. @@ -17,67 +17,101 @@ # ############################################################################## -## -## 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 + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 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. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi 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. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac 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 +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; 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 +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - 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\"" + 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 - i=`expr $i + 1` + # 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 - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $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. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/src/main/java/com/refinedmods/refinedpipes/RefinedPipes.java b/src/main/java/com/refinedmods/refinedpipes/RefinedPipes.java index 95f1b63..84a9150 100644 --- a/src/main/java/com/refinedmods/refinedpipes/RefinedPipes.java +++ b/src/main/java/com/refinedmods/refinedpipes/RefinedPipes.java @@ -1,14 +1,14 @@ package com.refinedmods.refinedpipes; import com.refinedmods.refinedpipes.config.ServerConfig; -import com.refinedmods.refinedpipes.item.group.MainItemGroup; +import com.refinedmods.refinedpipes.item.creativetab.MainCreativeModeTab; import com.refinedmods.refinedpipes.setup.ClientSetup; import com.refinedmods.refinedpipes.setup.CommonSetup; -import net.minecraft.block.Block; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.tileentity.TileEntityType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.DistExecutor; @@ -20,22 +20,25 @@ @Mod(RefinedPipes.ID) public class RefinedPipes { public static final String ID = "refinedpipes"; - public static final ItemGroup MAIN_GROUP = new MainItemGroup(); + public static final CreativeModeTab MAIN_GROUP = new MainCreativeModeTab(); public static final RefinedPipesNetwork NETWORK = new RefinedPipesNetwork(); public static final ServerConfig SERVER_CONFIG = new ServerConfig(); public RefinedPipes() { - CommonSetup commonSetup = new CommonSetup(); - - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> ClientSetup::new); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { + FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientSetup::onClientSetup); + FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientSetup::onModelBake); + }); ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG.getSpec()); - FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Block.class, commonSetup::onRegisterBlocks); - FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Item.class, commonSetup::onRegisterItems); - FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(TileEntityType.class, commonSetup::onRegisterTileEntities); - FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(ContainerType.class, commonSetup::onRegisterContainers); + FMLJavaModLoadingContext.get().getModEventBus().addListener(CommonSetup::onConstructMod); + FMLJavaModLoadingContext.get().getModEventBus().addListener(CommonSetup::onCommonSetup); + FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Block.class, CommonSetup::onRegisterBlocks); + FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Item.class, CommonSetup::onRegisterItems); + FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(BlockEntityType.class, CommonSetup::onRegisterBlockEntities); + FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(MenuType.class, CommonSetup::onRegisterContainerMenus); - MinecraftForge.EVENT_BUS.addListener(commonSetup::onWorldTick); + MinecraftForge.EVENT_BUS.addListener(CommonSetup::onLevelTick); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/RefinedPipesBlockEntities.java b/src/main/java/com/refinedmods/refinedpipes/RefinedPipesBlockEntities.java new file mode 100644 index 0000000..98bd26c --- /dev/null +++ b/src/main/java/com/refinedmods/refinedpipes/RefinedPipesBlockEntities.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedpipes; + +import com.refinedmods.refinedpipes.blockentity.EnergyPipeBlockEntity; +import com.refinedmods.refinedpipes.blockentity.FluidPipeBlockEntity; +import com.refinedmods.refinedpipes.blockentity.ItemPipeBlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraftforge.registries.ObjectHolder; + +public class RefinedPipesBlockEntities { + @ObjectHolder(RefinedPipes.ID + ":basic_item_pipe") + public static final BlockEntityType BASIC_ITEM_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":improved_item_pipe") + public static final BlockEntityType IMPROVED_ITEM_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":advanced_item_pipe") + public static final BlockEntityType ADVANCED_ITEM_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":basic_fluid_pipe") + public static final BlockEntityType BASIC_FLUID_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":improved_fluid_pipe") + public static final BlockEntityType IMPROVED_FLUID_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":advanced_fluid_pipe") + public static final BlockEntityType ADVANCED_FLUID_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":elite_fluid_pipe") + public static final BlockEntityType ELITE_FLUID_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":ultimate_fluid_pipe") + public static final BlockEntityType ULTIMATE_FLUID_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":basic_energy_pipe") + public static final BlockEntityType BASIC_ENERGY_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":improved_energy_pipe") + public static final BlockEntityType IMPROVED_ENERGY_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":advanced_energy_pipe") + public static final BlockEntityType ADVANCED_ENERGY_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":elite_energy_pipe") + public static final BlockEntityType ELITE_ENERGY_PIPE = null; + @ObjectHolder(RefinedPipes.ID + ":ultimate_energy_pipe") + public static final BlockEntityType ULTIMATE_ENERGY_PIPE = null; +} diff --git a/src/main/java/com/refinedmods/refinedpipes/RefinedPipesContainers.java b/src/main/java/com/refinedmods/refinedpipes/RefinedPipesContainerMenus.java similarity index 51% rename from src/main/java/com/refinedmods/refinedpipes/RefinedPipesContainers.java rename to src/main/java/com/refinedmods/refinedpipes/RefinedPipesContainerMenus.java index eef53ee..bbba57a 100644 --- a/src/main/java/com/refinedmods/refinedpipes/RefinedPipesContainers.java +++ b/src/main/java/com/refinedmods/refinedpipes/RefinedPipesContainerMenus.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes; -import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainer; -import net.minecraft.inventory.container.ContainerType; +import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainerMenu; +import net.minecraft.world.inventory.MenuType; import net.minecraftforge.registries.ObjectHolder; -public class RefinedPipesContainers { +public class RefinedPipesContainerMenus { @ObjectHolder(RefinedPipes.ID + ":extractor_attachment") - public static final ContainerType EXTRACTOR_ATTACHMENT = null; + public static final MenuType EXTRACTOR_ATTACHMENT = null; } diff --git a/src/main/java/com/refinedmods/refinedpipes/RefinedPipesNetwork.java b/src/main/java/com/refinedmods/refinedpipes/RefinedPipesNetwork.java index 0ac6567..60153f3 100644 --- a/src/main/java/com/refinedmods/refinedpipes/RefinedPipesNetwork.java +++ b/src/main/java/com/refinedmods/refinedpipes/RefinedPipesNetwork.java @@ -1,14 +1,14 @@ package com.refinedmods.refinedpipes; import com.refinedmods.refinedpipes.message.*; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.fml.network.NetworkDirection; -import net.minecraftforge.fml.network.NetworkRegistry; -import net.minecraftforge.fml.network.PacketDistributor; -import net.minecraftforge.fml.network.simple.SimpleChannel; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; +import net.minecraftforge.network.NetworkDirection; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; public class RefinedPipesNetwork { private final String protocolVersion = Integer.toString(1); @@ -32,13 +32,13 @@ public void register() { handler.registerMessage(id++, FluidFilterSlotUpdateMessage.class, FluidFilterSlotUpdateMessage::encode, FluidFilterSlotUpdateMessage::decode, FluidFilterSlotUpdateMessage::handle); } - public void sendInArea(World world, BlockPos pos, int radius, Object message) { + public void sendInArea(Level level, BlockPos pos, int radius, Object message) { handler.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint( pos.getX(), pos.getY(), pos.getZ(), radius, - world.func_234923_W_() + level.dimension() )), message); } @@ -46,7 +46,7 @@ public void sendToServer(Object message) { handler.sendToServer(message); } - public void sendToClient(ServerPlayerEntity player, Object message) { - handler.sendTo(message, player.connection.netManager, NetworkDirection.PLAY_TO_CLIENT); + public void sendToClient(ServerPlayer player, Object message) { + handler.sendTo(message, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/RefinedPipesTileEntities.java b/src/main/java/com/refinedmods/refinedpipes/RefinedPipesTileEntities.java deleted file mode 100644 index a41b305..0000000 --- a/src/main/java/com/refinedmods/refinedpipes/RefinedPipesTileEntities.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.refinedmods.refinedpipes; - -import com.refinedmods.refinedpipes.tile.EnergyPipeTileEntity; -import com.refinedmods.refinedpipes.tile.FluidPipeTileEntity; -import com.refinedmods.refinedpipes.tile.ItemPipeTileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraftforge.registries.ObjectHolder; - -public class RefinedPipesTileEntities { - @ObjectHolder(RefinedPipes.ID + ":basic_item_pipe") - public static final TileEntityType BASIC_ITEM_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":improved_item_pipe") - public static final TileEntityType IMPROVED_ITEM_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":advanced_item_pipe") - public static final TileEntityType ADVANCED_ITEM_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":basic_fluid_pipe") - public static final TileEntityType BASIC_FLUID_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":improved_fluid_pipe") - public static final TileEntityType IMPROVED_FLUID_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":advanced_fluid_pipe") - public static final TileEntityType ADVANCED_FLUID_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":elite_fluid_pipe") - public static final TileEntityType ELITE_FLUID_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":ultimate_fluid_pipe") - public static final TileEntityType ULTIMATE_FLUID_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":basic_energy_pipe") - public static final TileEntityType BASIC_ENERGY_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":improved_energy_pipe") - public static final TileEntityType IMPROVED_ENERGY_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":advanced_energy_pipe") - public static final TileEntityType ADVANCED_ENERGY_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":elite_energy_pipe") - public static final TileEntityType ELITE_ENERGY_PIPE = null; - @ObjectHolder(RefinedPipes.ID + ":ultimate_energy_pipe") - public static final TileEntityType ULTIMATE_ENERGY_PIPE = null; -} diff --git a/src/main/java/com/refinedmods/refinedpipes/block/EnergyPipeBlock.java b/src/main/java/com/refinedmods/refinedpipes/block/EnergyPipeBlock.java index 1b0d19c..1574a71 100644 --- a/src/main/java/com/refinedmods/refinedpipes/block/EnergyPipeBlock.java +++ b/src/main/java/com/refinedmods/refinedpipes/block/EnergyPipeBlock.java @@ -1,21 +1,20 @@ package com.refinedmods.refinedpipes.block; +import com.refinedmods.refinedpipes.blockentity.EnergyPipeBlockEntity; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeEnergyStorage; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeType; import com.refinedmods.refinedpipes.network.pipe.shape.PipeShapeCache; -import com.refinedmods.refinedpipes.tile.EnergyPipeTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; - -public class EnergyPipeBlock extends PipeBlock { +public class EnergyPipeBlock extends PipeBlock implements EntityBlock { private final EnergyPipeType type; public EnergyPipeBlock(PipeShapeCache shapeCache, EnergyPipeType type) { @@ -30,29 +29,18 @@ public EnergyPipeType getType() { } @Override - public boolean hasTileEntity(BlockState state) { - return true; - } - - @Nullable - @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return new EnergyPipeTileEntity(type); - } - - @Override - protected boolean hasConnection(IWorld world, BlockPos pos, Direction direction) { - TileEntity currentTile = world.getTileEntity(pos); - if (currentTile instanceof EnergyPipeTileEntity && - ((EnergyPipeTileEntity) currentTile).getAttachmentManager().hasAttachment(direction)) { + protected boolean hasConnection(LevelAccessor level, BlockPos pos, Direction direction) { + BlockEntity currentBlockEntity = level.getBlockEntity(pos); + if (currentBlockEntity instanceof EnergyPipeBlockEntity && + ((EnergyPipeBlockEntity) currentBlockEntity).getAttachmentManager().hasAttachment(direction)) { return false; } - BlockState facingState = world.getBlockState(pos.offset(direction)); - TileEntity facingTile = world.getTileEntity(pos.offset(direction)); + BlockState facingState = level.getBlockState(pos.relative(direction)); + BlockEntity facingBlockEntity = level.getBlockEntity(pos.relative(direction)); - if (facingTile instanceof EnergyPipeTileEntity && - ((EnergyPipeTileEntity) facingTile).getAttachmentManager().hasAttachment(direction.getOpposite())) { + if (facingBlockEntity instanceof EnergyPipeBlockEntity && + ((EnergyPipeBlockEntity) facingBlockEntity).getAttachmentManager().hasAttachment(direction.getOpposite())) { return false; } @@ -61,13 +49,13 @@ protected boolean hasConnection(IWorld world, BlockPos pos, Direction direction) } @Override - protected boolean hasInvConnection(IWorld world, BlockPos pos, Direction direction) { - TileEntity facingTile = world.getTileEntity(pos.offset(direction)); - if (facingTile == null) { + protected boolean hasInvConnection(LevelAccessor level, BlockPos pos, Direction direction) { + BlockEntity facingBlockEntityy = level.getBlockEntity(pos.relative(direction)); + if (facingBlockEntityy == null) { return false; } - IEnergyStorage energyStorage = facingTile.getCapability(CapabilityEnergy.ENERGY, direction.getOpposite()).orElse(null); + IEnergyStorage energyStorage = facingBlockEntityy.getCapability(CapabilityEnergy.ENERGY, direction.getOpposite()).orElse(null); if (energyStorage == null) { return false; } @@ -78,4 +66,10 @@ protected boolean hasInvConnection(IWorld world, BlockPos pos, Direction directi return true; } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new EnergyPipeBlockEntity(pos, state, type); + } } diff --git a/src/main/java/com/refinedmods/refinedpipes/block/FluidPipeBlock.java b/src/main/java/com/refinedmods/refinedpipes/block/FluidPipeBlock.java index 3e154fd..dc310d6 100644 --- a/src/main/java/com/refinedmods/refinedpipes/block/FluidPipeBlock.java +++ b/src/main/java/com/refinedmods/refinedpipes/block/FluidPipeBlock.java @@ -1,19 +1,17 @@ package com.refinedmods.refinedpipes.block; +import com.refinedmods.refinedpipes.blockentity.FluidPipeBlockEntity; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipeType; import com.refinedmods.refinedpipes.network.pipe.shape.PipeShapeCache; -import com.refinedmods.refinedpipes.tile.FluidPipeTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -import javax.annotation.Nullable; - -public class FluidPipeBlock extends PipeBlock { +public class FluidPipeBlock extends PipeBlock implements EntityBlock { private final FluidPipeType type; public FluidPipeBlock(PipeShapeCache shapeCache, FluidPipeType type) { @@ -28,29 +26,18 @@ public FluidPipeType getType() { } @Override - public boolean hasTileEntity(BlockState state) { - return true; - } - - @Nullable - @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return new FluidPipeTileEntity(type); - } - - @Override - protected boolean hasConnection(IWorld world, BlockPos pos, Direction direction) { - TileEntity currentTile = world.getTileEntity(pos); - if (currentTile instanceof FluidPipeTileEntity && - ((FluidPipeTileEntity) currentTile).getAttachmentManager().hasAttachment(direction)) { + protected boolean hasConnection(LevelAccessor level, BlockPos pos, Direction direction) { + BlockEntity currentBlockEntity = level.getBlockEntity(pos); + if (currentBlockEntity instanceof FluidPipeBlockEntity && + ((FluidPipeBlockEntity) currentBlockEntity).getAttachmentManager().hasAttachment(direction)) { return false; } - BlockState facingState = world.getBlockState(pos.offset(direction)); - TileEntity facingTile = world.getTileEntity(pos.offset(direction)); + BlockState facingState = level.getBlockState(pos.relative(direction)); + BlockEntity facingBlockEntity = level.getBlockEntity(pos.relative(direction)); - if (facingTile instanceof FluidPipeTileEntity && - ((FluidPipeTileEntity) facingTile).getAttachmentManager().hasAttachment(direction.getOpposite())) { + if (facingBlockEntity instanceof FluidPipeBlockEntity && + ((FluidPipeBlockEntity) facingBlockEntity).getAttachmentManager().hasAttachment(direction.getOpposite())) { return false; } @@ -59,10 +46,15 @@ protected boolean hasConnection(IWorld world, BlockPos pos, Direction direction) } @Override - protected boolean hasInvConnection(IWorld world, BlockPos pos, Direction direction) { - TileEntity facingTile = world.getTileEntity(pos.offset(direction)); + protected boolean hasInvConnection(LevelAccessor level, BlockPos pos, Direction direction) { + BlockEntity facingBlockEntity = level.getBlockEntity(pos.relative(direction)); - return facingTile != null - && facingTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite()).isPresent(); + return facingBlockEntity != null + && facingBlockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite()).isPresent(); + } + + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new FluidPipeBlockEntity(pos, state, type); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/block/ItemPipeBlock.java b/src/main/java/com/refinedmods/refinedpipes/block/ItemPipeBlock.java index 74ad557..f6cf705 100644 --- a/src/main/java/com/refinedmods/refinedpipes/block/ItemPipeBlock.java +++ b/src/main/java/com/refinedmods/refinedpipes/block/ItemPipeBlock.java @@ -1,19 +1,21 @@ package com.refinedmods.refinedpipes.block; +import com.refinedmods.refinedpipes.blockentity.ItemPipeBlockEntity; import com.refinedmods.refinedpipes.network.pipe.item.ItemPipeType; import com.refinedmods.refinedpipes.network.pipe.shape.PipeShapeCache; -import com.refinedmods.refinedpipes.tile.ItemPipeTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.items.CapabilityItemHandler; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; - -public class ItemPipeBlock extends PipeBlock { +public class ItemPipeBlock extends PipeBlock implements EntityBlock { private final ItemPipeType type; public ItemPipeBlock(PipeShapeCache shapeCache, ItemPipeType type) { @@ -28,29 +30,18 @@ public ItemPipeType getType() { } @Override - public boolean hasTileEntity(BlockState state) { - return true; - } - - @Nullable - @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return new ItemPipeTileEntity(type); - } - - @Override - protected boolean hasConnection(IWorld world, BlockPos pos, Direction direction) { - TileEntity currentTile = world.getTileEntity(pos); - if (currentTile instanceof ItemPipeTileEntity && - ((ItemPipeTileEntity) currentTile).getAttachmentManager().hasAttachment(direction)) { + protected boolean hasConnection(LevelAccessor world, BlockPos pos, Direction direction) { + BlockEntity currentBlockEntity = world.getBlockEntity(pos); + if (currentBlockEntity instanceof ItemPipeBlockEntity && + ((ItemPipeBlockEntity) currentBlockEntity).getAttachmentManager().hasAttachment(direction)) { return false; } - BlockState facingState = world.getBlockState(pos.offset(direction)); - TileEntity facingTile = world.getTileEntity(pos.offset(direction)); + BlockState facingState = world.getBlockState(pos.relative(direction)); + BlockEntity facingBlockEntity = world.getBlockEntity(pos.relative(direction)); - if (facingTile instanceof ItemPipeTileEntity && - ((ItemPipeTileEntity) facingTile).getAttachmentManager().hasAttachment(direction.getOpposite())) { + if (facingBlockEntity instanceof ItemPipeBlockEntity && + ((ItemPipeBlockEntity) facingBlockEntity).getAttachmentManager().hasAttachment(direction.getOpposite())) { return false; } @@ -58,10 +49,21 @@ protected boolean hasConnection(IWorld world, BlockPos pos, Direction direction) } @Override - protected boolean hasInvConnection(IWorld world, BlockPos pos, Direction direction) { - TileEntity facingTile = world.getTileEntity(pos.offset(direction)); + protected boolean hasInvConnection(LevelAccessor world, BlockPos pos, Direction direction) { + BlockEntity facingBlockEntity = world.getBlockEntity(pos.relative(direction)); - return facingTile != null - && facingTile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).isPresent(); + return facingBlockEntity != null + && facingBlockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).isPresent(); + } + + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new ItemPipeBlockEntity(pos, state, type); + } + + @Nullable + @Override + public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType type) { + return level.isClientSide ? (levelTicker, pos, stateTicker, blockEntity) -> ItemPipeBlockEntity.tick((ItemPipeBlockEntity) blockEntity) : null; } } diff --git a/src/main/java/com/refinedmods/refinedpipes/block/PipeBlock.java b/src/main/java/com/refinedmods/refinedpipes/block/PipeBlock.java index 6ff37fd..141f626 100644 --- a/src/main/java/com/refinedmods/refinedpipes/block/PipeBlock.java +++ b/src/main/java/com/refinedmods/refinedpipes/block/PipeBlock.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedpipes.block; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; import com.refinedmods.refinedpipes.item.AttachmentItem; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.pipe.Pipe; @@ -8,30 +9,29 @@ import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentManager; import com.refinedmods.refinedpipes.network.pipe.shape.PipeShapeCache; import com.refinedmods.refinedpipes.network.pipe.shape.PipeShapeProps; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; import com.refinedmods.refinedpipes.util.Raytracer; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.material.Material; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.item.ItemStack; -import net.minecraft.state.BooleanProperty; -import net.minecraft.state.StateContainer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import javax.annotation.Nullable; @@ -53,19 +53,19 @@ public abstract class PipeBlock extends Block { private final PipeShapeCache shapeCache; public PipeBlock(PipeShapeCache shapeCache) { - super(Block.Properties.create(Material.ROCK).hardnessAndResistance(0.35F)); + super(Block.Properties.of(Material.STONE).strength(0.35F)); this.shapeCache = shapeCache; - this.setDefaultState(getDefaultState() - .with(NORTH, false).with(EAST, false).with(SOUTH, false).with(WEST, false).with(UP, false).with(DOWN, false) - .with(INV_NORTH, false).with(INV_EAST, false).with(INV_SOUTH, false).with(INV_WEST, false).with(INV_UP, false).with(INV_DOWN, false) + this.registerDefaultState(defaultBlockState() + .setValue(NORTH, false).setValue(EAST, false).setValue(SOUTH, false).setValue(WEST, false).setValue(UP, false).setValue(DOWN, false) + .setValue(INV_NORTH, false).setValue(INV_EAST, false).setValue(INV_SOUTH, false).setValue(INV_WEST, false).setValue(INV_UP, false).setValue(INV_DOWN, false) ); } @Override - protected void fillStateContainer(StateContainer.Builder builder) { - super.fillStateContainer(builder); + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); builder.add( NORTH, EAST, SOUTH, WEST, UP, DOWN, @@ -75,54 +75,54 @@ protected void fillStateContainer(StateContainer.Builder buil @Override @SuppressWarnings("deprecation") - public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) { - super.neighborChanged(state, world, pos, block, fromPos, isMoving); + public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) { + super.neighborChanged(state, level, pos, block, fromPos, isMoving); - if (!world.isRemote) { - Pipe pipe = NetworkManager.get(world).getPipe(pos); + if (!level.isClientSide) { + Pipe pipe = NetworkManager.get(level).getPipe(pos); if (pipe != null && pipe.getNetwork() != null) { - pipe.getNetwork().scanGraph(world, pos); + pipe.getNetwork().scanGraph(level, pos); } } } @Override @SuppressWarnings("deprecation") - public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { - Direction dirClicked = getAttachmentDirectionClicked(pos, hit.getHitVec()); + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + Direction dirClicked = getAttachmentDirectionClicked(pos, hit.getLocation()); if (dirClicked != null) { - ItemStack held = player.getHeldItemMainhand(); - TileEntity tile = world.getTileEntity(pos); + ItemStack held = player.getMainHandItem(); + BlockEntity blockEntity = level.getBlockEntity(pos); if (held.isEmpty() && player.isCrouching()) { - return removeAttachment(world, pos, dirClicked); - } else if (tile instanceof PipeTileEntity && ((PipeTileEntity) tile).getAttachmentManager().hasAttachment(dirClicked)) { - return openAttachmentContainer(player, pos, ((PipeTileEntity) tile).getAttachmentManager(), dirClicked); + return removeAttachment(level, pos, dirClicked); + } else if (blockEntity instanceof PipeBlockEntity pipeBlockEntity && pipeBlockEntity.getAttachmentManager().hasAttachment(dirClicked)) { + return openAttachmentContainer(player, pos, pipeBlockEntity.getAttachmentManager(), dirClicked); } else if (held.getItem() instanceof AttachmentItem) { - return addAttachment(player, world, pos, held, dirClicked); + return addAttachment(player, level, pos, held, dirClicked); } } - return super.onBlockActivated(state, world, pos, player, hand, hit); + return super.use(state, level, pos, player, hand, hit); } - private ActionResultType addAttachment(PlayerEntity player, World world, BlockPos pos, ItemStack attachment, Direction dir) { - if (!world.isRemote) { - Pipe pipe = NetworkManager.get(world).getPipe(pos); + private InteractionResult addAttachment(Player player, Level level, BlockPos pos, ItemStack attachment, Direction dir) { + if (!level.isClientSide) { + Pipe pipe = NetworkManager.get(level).getPipe(pos); if (pipe != null && !pipe.getAttachmentManager().hasAttachment(dir)) { AttachmentFactory type = ((AttachmentItem) attachment.getItem()).getFactory(); if (!type.canPlaceOnPipe(this)) { - return ActionResultType.SUCCESS; + return InteractionResult.SUCCESS; } pipe.getAttachmentManager().setAttachmentAndScanGraph(dir, type.create(pipe, dir)); - NetworkManager.get(world).markDirty(); + NetworkManager.get(level).setDirty(); pipe.sendBlockUpdate(); - world.setBlockState(pos, getState(world.getBlockState(pos), world, pos)); + level.setBlockAndUpdate(pos, getState(level.getBlockState(pos), level, pos)); if (!player.isCreative()) { attachment.shrink(1); @@ -130,117 +130,117 @@ private ActionResultType addAttachment(PlayerEntity player, World world, BlockPo } } - return ActionResultType.SUCCESS; + return InteractionResult.SUCCESS; } - private ActionResultType removeAttachment(World world, BlockPos pos, Direction dir) { - if (!world.isRemote) { - Pipe pipe = NetworkManager.get(world).getPipe(pos); + private InteractionResult removeAttachment(Level level, BlockPos pos, Direction dir) { + if (!level.isClientSide) { + Pipe pipe = NetworkManager.get(level).getPipe(pos); if (pipe != null && pipe.getAttachmentManager().hasAttachment(dir)) { Attachment attachment = pipe.getAttachmentManager().getAttachment(dir); pipe.getAttachmentManager().removeAttachmentAndScanGraph(dir); - NetworkManager.get(world).markDirty(); + NetworkManager.get(level).setDirty(); pipe.sendBlockUpdate(); - world.setBlockState(pos, getState(world.getBlockState(pos), world, pos)); + level.setBlockAndUpdate(pos, getState(level.getBlockState(pos), level, pos)); - Block.spawnAsEntity(world, pos.offset(dir), attachment.getDrop()); + Block.popResource(level, pos.relative(dir), attachment.getDrop()); } - return ActionResultType.SUCCESS; + return InteractionResult.SUCCESS; } else { - return ((PipeTileEntity) world.getTileEntity(pos)).getAttachmentManager().hasAttachment(dir) ? ActionResultType.SUCCESS : ActionResultType.FAIL; + return ((PipeBlockEntity) level.getBlockEntity(pos)).getAttachmentManager().hasAttachment(dir) ? InteractionResult.SUCCESS : InteractionResult.FAIL; } } - private ActionResultType openAttachmentContainer(PlayerEntity player, BlockPos pos, AttachmentManager attachmentManager, Direction dir) { - if (player instanceof ServerPlayerEntity) { - attachmentManager.openAttachmentContainer(dir, (ServerPlayerEntity) player); + private InteractionResult openAttachmentContainer(Player player, BlockPos pos, AttachmentManager attachmentManager, Direction dir) { + if (player instanceof ServerPlayer) { + attachmentManager.openAttachmentContainer(dir, (ServerPlayer) player); } - return ActionResultType.SUCCESS; + return InteractionResult.SUCCESS; } @Nullable @Override - public BlockState getStateForPlacement(BlockItemUseContext ctx) { - return getState(getDefaultState(), ctx.getWorld(), ctx.getPos()); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return getState(defaultBlockState(), ctx.getLevel(), ctx.getClickedPos()); } @Override @SuppressWarnings("deprecation") - public BlockState updatePostPlacement(BlockState state, Direction dir, BlockState facingState, IWorld world, BlockPos pos, BlockPos facingPos) { + public BlockState updateShape(BlockState state, Direction dir, BlockState facingState, LevelAccessor world, BlockPos pos, BlockPos facingPos) { return getState(state, world, pos); } @Override @SuppressWarnings("deprecation") - public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext ctx) { return shapeCache.getShape(state, world, pos, ctx); } - private BlockState getState(BlockState currentState, IWorld world, BlockPos pos) { + private BlockState getState(BlockState currentState, LevelAccessor world, BlockPos pos) { return currentState - .with(NORTH, hasConnection(world, pos, Direction.NORTH)) - .with(EAST, hasConnection(world, pos, Direction.EAST)) - .with(SOUTH, hasConnection(world, pos, Direction.SOUTH)) - .with(WEST, hasConnection(world, pos, Direction.WEST)) - .with(UP, hasConnection(world, pos, Direction.UP)) - .with(DOWN, hasConnection(world, pos, Direction.DOWN)) - .with(INV_NORTH, hasInvConnection(world, pos, Direction.NORTH)) - .with(INV_EAST, hasInvConnection(world, pos, Direction.EAST)) - .with(INV_SOUTH, hasInvConnection(world, pos, Direction.SOUTH)) - .with(INV_WEST, hasInvConnection(world, pos, Direction.WEST)) - .with(INV_UP, hasInvConnection(world, pos, Direction.UP)) - .with(INV_DOWN, hasInvConnection(world, pos, Direction.DOWN)); + .setValue(NORTH, hasConnection(world, pos, Direction.NORTH)) + .setValue(EAST, hasConnection(world, pos, Direction.EAST)) + .setValue(SOUTH, hasConnection(world, pos, Direction.SOUTH)) + .setValue(WEST, hasConnection(world, pos, Direction.WEST)) + .setValue(UP, hasConnection(world, pos, Direction.UP)) + .setValue(DOWN, hasConnection(world, pos, Direction.DOWN)) + .setValue(INV_NORTH, hasInvConnection(world, pos, Direction.NORTH)) + .setValue(INV_EAST, hasInvConnection(world, pos, Direction.EAST)) + .setValue(INV_SOUTH, hasInvConnection(world, pos, Direction.SOUTH)) + .setValue(INV_WEST, hasInvConnection(world, pos, Direction.WEST)) + .setValue(INV_UP, hasInvConnection(world, pos, Direction.UP)) + .setValue(INV_DOWN, hasInvConnection(world, pos, Direction.DOWN)); } @Override - public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos, PlayerEntity player) { - Direction dirClicked = getAttachmentDirectionClicked(pos, target.getHitVec()); + public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter world, BlockPos pos, Player player) { + Direction dirClicked = getAttachmentDirectionClicked(pos, target.getLocation()); if (dirClicked != null) { - TileEntity tile = world.getTileEntity(pos); - if (tile instanceof PipeTileEntity) { - return ((PipeTileEntity) tile).getAttachmentManager().getPickBlock(dirClicked); + BlockEntity blockEntity = world.getBlockEntity(pos); + if (blockEntity instanceof PipeBlockEntity pipeBlockEntity) { + return pipeBlockEntity.getAttachmentManager().getPickBlock(dirClicked); } } - return super.getPickBlock(state, target, world, pos, player); + return super.getCloneItemStack(state, target, world, pos, player); } @Nullable - public Direction getAttachmentDirectionClicked(BlockPos pos, Vector3d hit) { - if (Raytracer.inclusiveContains(PipeShapeProps.NORTH_ATTACHMENT_SHAPE.getBoundingBox().offset(pos), hit)) { + public Direction getAttachmentDirectionClicked(BlockPos pos, Vec3 hit) { + if (Raytracer.inclusiveContains(PipeShapeProps.NORTH_ATTACHMENT_SHAPE.bounds().move(pos), hit)) { return Direction.NORTH; } - if (Raytracer.inclusiveContains(PipeShapeProps.EAST_ATTACHMENT_SHAPE.getBoundingBox().offset(pos), hit)) { + if (Raytracer.inclusiveContains(PipeShapeProps.EAST_ATTACHMENT_SHAPE.bounds().move(pos), hit)) { return Direction.EAST; } - if (Raytracer.inclusiveContains(PipeShapeProps.SOUTH_ATTACHMENT_SHAPE.getBoundingBox().offset(pos), hit)) { + if (Raytracer.inclusiveContains(PipeShapeProps.SOUTH_ATTACHMENT_SHAPE.bounds().move(pos), hit)) { return Direction.SOUTH; } - if (Raytracer.inclusiveContains(PipeShapeProps.WEST_ATTACHMENT_SHAPE.getBoundingBox().offset(pos), hit)) { + if (Raytracer.inclusiveContains(PipeShapeProps.WEST_ATTACHMENT_SHAPE.bounds().move(pos), hit)) { return Direction.WEST; } - if (Raytracer.inclusiveContains(PipeShapeProps.UP_ATTACHMENT_SHAPE.getBoundingBox().offset(pos), hit)) { + if (Raytracer.inclusiveContains(PipeShapeProps.UP_ATTACHMENT_SHAPE.bounds().move(pos), hit)) { return Direction.UP; } - if (Raytracer.inclusiveContains(PipeShapeProps.DOWN_ATTACHMENT_SHAPE.getBoundingBox().offset(pos), hit)) { + if (Raytracer.inclusiveContains(PipeShapeProps.DOWN_ATTACHMENT_SHAPE.bounds().move(pos), hit)) { return Direction.DOWN; } return null; } - protected abstract boolean hasConnection(IWorld world, BlockPos pos, Direction direction); + protected abstract boolean hasConnection(LevelAccessor world, BlockPos pos, Direction direction); - protected abstract boolean hasInvConnection(IWorld world, BlockPos pos, Direction direction); + protected abstract boolean hasInvConnection(LevelAccessor world, BlockPos pos, Direction direction); } diff --git a/src/main/java/com/refinedmods/refinedpipes/blockentity/BaseBlockEntity.java b/src/main/java/com/refinedmods/refinedpipes/blockentity/BaseBlockEntity.java new file mode 100644 index 0000000..704ffbd --- /dev/null +++ b/src/main/java/com/refinedmods/refinedpipes/blockentity/BaseBlockEntity.java @@ -0,0 +1,45 @@ +package com.refinedmods.refinedpipes.blockentity; + +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.Connection; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; + +import javax.annotation.Nullable; + +public abstract class BaseBlockEntity extends BlockEntity { + protected BaseBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + @Override + public final CompoundTag getUpdateTag() { + return writeUpdate(super.getUpdateTag()); + } + + @Override + public final ClientboundBlockEntityDataPacket getUpdatePacket() { + return ClientboundBlockEntityDataPacket.create(this, BlockEntity::getUpdateTag); + } + + @Override + public final void onDataPacket(Connection net, ClientboundBlockEntityDataPacket packet) { + readUpdate(packet.getTag()); + } + + @Override + public final void handleUpdateTag(CompoundTag tag) { + super.load(tag); + readUpdate(tag); + } + + public CompoundTag writeUpdate(CompoundTag tag) { + return tag; + } + + public void readUpdate(@Nullable CompoundTag tag) { + } +} diff --git a/src/main/java/com/refinedmods/refinedpipes/tile/EnergyPipeTileEntity.java b/src/main/java/com/refinedmods/refinedpipes/blockentity/EnergyPipeBlockEntity.java similarity index 65% rename from src/main/java/com/refinedmods/refinedpipes/tile/EnergyPipeTileEntity.java rename to src/main/java/com/refinedmods/refinedpipes/blockentity/EnergyPipeBlockEntity.java index 5216d6b..0ca1976 100644 --- a/src/main/java/com/refinedmods/refinedpipes/tile/EnergyPipeTileEntity.java +++ b/src/main/java/com/refinedmods/refinedpipes/blockentity/EnergyPipeBlockEntity.java @@ -1,13 +1,14 @@ -package com.refinedmods.refinedpipes.tile; +package com.refinedmods.refinedpipes.blockentity; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.energy.ClientEnergyPipeEnergyStorage; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipe; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeType; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.energy.CapabilityEnergy; @@ -15,12 +16,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class EnergyPipeTileEntity extends PipeTileEntity { +public class EnergyPipeBlockEntity extends PipeBlockEntity { private final EnergyPipeType type; private final LazyOptional clientEnergyStorage; - public EnergyPipeTileEntity(EnergyPipeType type) { - super(type.getTileType()); + public EnergyPipeBlockEntity(BlockPos pos, BlockState state, EnergyPipeType type) { + super(type.getBlockEntityType(), pos, state); this.type = type; this.clientEnergyStorage = LazyOptional.of(() -> new ClientEnergyPipeEnergyStorage(type)); @@ -30,10 +31,10 @@ public EnergyPipeTileEntity(EnergyPipeType type) { @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction side) { if (cap == CapabilityEnergy.ENERGY) { - if (!world.isRemote) { - NetworkManager mgr = NetworkManager.get(world); + if (!level.isClientSide) { + NetworkManager mgr = NetworkManager.get(level); - Pipe pipe = mgr.getPipe(pos); + Pipe pipe = mgr.getPipe(worldPosition); if (pipe instanceof EnergyPipe) { return ((EnergyPipe) pipe).getEnergyStorage().cast(); } @@ -46,7 +47,7 @@ public LazyOptional getCapability(@Nonnull Capability cap, @Nullable D } @Override - protected Pipe createPipe(World world, BlockPos pos) { - return new EnergyPipe(world, pos, type); + protected Pipe createPipe(Level level, BlockPos pos) { + return new EnergyPipe(level, pos, type); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/tile/FluidPipeTileEntity.java b/src/main/java/com/refinedmods/refinedpipes/blockentity/FluidPipeBlockEntity.java similarity index 64% rename from src/main/java/com/refinedmods/refinedpipes/tile/FluidPipeTileEntity.java rename to src/main/java/com/refinedmods/refinedpipes/blockentity/FluidPipeBlockEntity.java index 0a693d6..3a42bfe 100644 --- a/src/main/java/com/refinedmods/refinedpipes/tile/FluidPipeTileEntity.java +++ b/src/main/java/com/refinedmods/refinedpipes/blockentity/FluidPipeBlockEntity.java @@ -1,24 +1,27 @@ -package com.refinedmods.refinedpipes.tile; +package com.refinedmods.refinedpipes.blockentity; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.fluid.FluidNetwork; import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipe; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipeType; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.fluids.FluidStack; -public class FluidPipeTileEntity extends PipeTileEntity { +import javax.annotation.Nullable; + +public class FluidPipeBlockEntity extends PipeBlockEntity { private final FluidPipeType type; private FluidStack fluid = FluidStack.EMPTY; private float fullness = 0; private float renderFullness = 0; - public FluidPipeTileEntity(FluidPipeType type) { - super(type.getTileType()); + public FluidPipeBlockEntity(BlockPos pos, BlockState state, FluidPipeType type) { + super(type.getBlockEntityType(), pos, state); this.type = type; } @@ -52,10 +55,10 @@ public float updateAndGetRenderFullness(float partialTicks) { } @Override - public CompoundNBT writeUpdate(CompoundNBT tag) { - Pipe pipe = NetworkManager.get(world).getPipe(pos); + public CompoundTag writeUpdate(CompoundTag tag) { + Pipe pipe = NetworkManager.get(level).getPipe(worldPosition); if (pipe instanceof FluidPipe && pipe.getNetwork() != null) { - tag.put("fluid", ((FluidNetwork) pipe.getNetwork()).getFluidTank().getFluid().writeToNBT(new CompoundNBT())); + tag.put("fluid", ((FluidNetwork) pipe.getNetwork()).getFluidTank().getFluid().writeToNBT(new CompoundTag())); tag.putFloat("fullness", ((FluidPipe) pipe).getFullness()); } @@ -63,14 +66,19 @@ public CompoundNBT writeUpdate(CompoundNBT tag) { } @Override - public void readUpdate(CompoundNBT tag) { - if (tag.contains("fluid")) { + public void readUpdate(@Nullable CompoundTag tag) { + if (tag != null && tag.contains("fluid")) { fluid = FluidStack.loadFluidStackFromNBT(tag.getCompound("fluid")); + } else { + fluid = FluidStack.EMPTY; } - if (tag.contains("fullness")) { + if (tag != null && tag.contains("fullness")) { fullness = tag.getFloat("fullness"); renderFullness = fullness; + } else { + fullness = 0; + renderFullness = 0; } super.readUpdate(tag); @@ -81,7 +89,7 @@ public void setFullness(float fullness) { } @Override - protected Pipe createPipe(World world, BlockPos pos) { - return new FluidPipe(world, pos, type); + protected Pipe createPipe(Level level, BlockPos pos) { + return new FluidPipe(level, pos, type); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/tile/ItemPipeTileEntity.java b/src/main/java/com/refinedmods/refinedpipes/blockentity/ItemPipeBlockEntity.java similarity index 53% rename from src/main/java/com/refinedmods/refinedpipes/tile/ItemPipeTileEntity.java rename to src/main/java/com/refinedmods/refinedpipes/blockentity/ItemPipeBlockEntity.java index 1934df2..a003c5d 100644 --- a/src/main/java/com/refinedmods/refinedpipes/tile/ItemPipeTileEntity.java +++ b/src/main/java/com/refinedmods/refinedpipes/blockentity/ItemPipeBlockEntity.java @@ -1,34 +1,29 @@ -package com.refinedmods.refinedpipes.tile; +package com.refinedmods.refinedpipes.blockentity; import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.item.ItemPipe; import com.refinedmods.refinedpipes.network.pipe.item.ItemPipeType; import com.refinedmods.refinedpipes.network.pipe.transport.ItemTransport; import com.refinedmods.refinedpipes.network.pipe.transport.ItemTransportProps; -import net.minecraft.inventory.InventoryHelper; -import net.minecraft.tileentity.ITickableTileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.Containers; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import java.util.ArrayList; import java.util.List; -public class ItemPipeTileEntity extends PipeTileEntity implements ITickableTileEntity { - private List props = new ArrayList<>(); - +public class ItemPipeBlockEntity extends PipeBlockEntity { private final ItemPipeType type; + private List props = new ArrayList<>(); - public ItemPipeTileEntity(ItemPipeType type) { - super(type.getTileType()); - + public ItemPipeBlockEntity(BlockPos pos, BlockState state, ItemPipeType type) { + super(type.getBlockEntityType(), pos, state); this.type = type; } - @Override - public void tick() { - if (world.isRemote) { - props.forEach(ItemTransportProps::tick); - } + public static void tick(ItemPipeBlockEntity blockEntity) { + blockEntity.props.forEach(ItemTransportProps::tick); } public List getProps() { @@ -44,12 +39,12 @@ protected void spawnDrops(Pipe pipe) { super.spawnDrops(pipe); for (ItemTransport transport : ((ItemPipe) pipe).getTransports()) { - InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), transport.getValue()); + Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), transport.getValue()); } } @Override - protected Pipe createPipe(World world, BlockPos pos) { - return new ItemPipe(world, pos, type); + protected Pipe createPipe(Level level, BlockPos pos) { + return new ItemPipe(level, pos, type); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/blockentity/PipeBlockEntity.java b/src/main/java/com/refinedmods/refinedpipes/blockentity/PipeBlockEntity.java new file mode 100644 index 0000000..c7ae5bb --- /dev/null +++ b/src/main/java/com/refinedmods/refinedpipes/blockentity/PipeBlockEntity.java @@ -0,0 +1,114 @@ +package com.refinedmods.refinedpipes.blockentity; + +import com.refinedmods.refinedpipes.network.NetworkManager; +import com.refinedmods.refinedpipes.network.pipe.Pipe; +import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; +import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentManager; +import com.refinedmods.refinedpipes.network.pipe.attachment.ClientAttachmentManager; +import com.refinedmods.refinedpipes.network.pipe.attachment.DummyAttachmentManager; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Containers; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.client.model.data.IModelData; +import net.minecraftforge.client.model.data.ModelDataMap; +import net.minecraftforge.client.model.data.ModelProperty; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public abstract class PipeBlockEntity extends BaseBlockEntity { + public static final ModelProperty ATTACHMENTS_PROPERTY = new ModelProperty<>(); + private final AttachmentManager clientAttachmentManager = new ClientAttachmentManager(); + + protected PipeBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + public AttachmentManager getAttachmentManager() { + if (level.isClientSide) { + return clientAttachmentManager; + } + + Pipe pipe = NetworkManager.get(level).getPipe(worldPosition); + + if (pipe != null) { + return pipe.getAttachmentManager(); + } + + return DummyAttachmentManager.INSTANCE; + } + + @Override + public void clearRemoved() { + super.clearRemoved(); + + if (!level.isClientSide) { + NetworkManager mgr = NetworkManager.get(level); + + if (mgr.getPipe(worldPosition) == null) { + mgr.addPipe(createPipe(level, worldPosition)); + } + } + } + + // TODO: remove when https://github.com/MinecraftForge/MinecraftForge/pull/8303/files is merged + private boolean unloaded; + + @Override + public void onChunkUnloaded() { + super.onChunkUnloaded(); + unloaded = true; + } + + @Override + public void setRemoved() { + super.setRemoved(); + + if (!level.isClientSide && !unloaded) { + NetworkManager mgr = NetworkManager.get(level); + + Pipe pipe = mgr.getPipe(worldPosition); + if (pipe != null) { + spawnDrops(pipe); + + for (Attachment attachment : pipe.getAttachmentManager().getAttachments()) { + Containers.dropItemStack(level, worldPosition.getX(), worldPosition.getY(), worldPosition.getZ(), attachment.getDrop()); + } + } + + mgr.removePipe(worldPosition); + } + } + + protected void spawnDrops(Pipe pipe) { + } + + @Nonnull + @Override + public IModelData getModelData() { + return new ModelDataMap.Builder().withInitial(ATTACHMENTS_PROPERTY, getAttachmentManager().getState()).build(); + } + + @Override + public CompoundTag writeUpdate(CompoundTag tag) { + getAttachmentManager().writeUpdate(tag); + + return tag; + } + + @Override + public void readUpdate(@Nullable CompoundTag tag) { + getAttachmentManager().readUpdate(tag); + + requestModelDataUpdate(); + + BlockState state = level.getBlockState(worldPosition); + level.sendBlockUpdated(worldPosition, state, state, 1 | 2); + } + + protected abstract Pipe createPipe(Level level, BlockPos pos); +} diff --git a/src/main/java/com/refinedmods/refinedpipes/container/BaseContainer.java b/src/main/java/com/refinedmods/refinedpipes/container/BaseContainerMenu.java similarity index 61% rename from src/main/java/com/refinedmods/refinedpipes/container/BaseContainer.java rename to src/main/java/com/refinedmods/refinedpipes/container/BaseContainerMenu.java index 804c616..0c6711c 100644 --- a/src/main/java/com/refinedmods/refinedpipes/container/BaseContainer.java +++ b/src/main/java/com/refinedmods/refinedpipes/container/BaseContainerMenu.java @@ -4,25 +4,25 @@ import com.refinedmods.refinedpipes.container.slot.FilterSlot; import com.refinedmods.refinedpipes.container.slot.FluidFilterSlot; import com.refinedmods.refinedpipes.message.FluidFilterSlotUpdateMessage; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.container.ClickType; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.ItemStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -public class BaseContainer extends Container { +public class BaseContainerMenu extends AbstractContainerMenu { private final List fluidSlots = new ArrayList<>(); private final List fluids = new ArrayList<>(); - private final PlayerEntity player; + private final Player player; - protected BaseContainer(@Nullable ContainerType type, int windowId, PlayerEntity player) { + protected BaseContainerMenu(@Nullable MenuType type, int windowId, Player player) { super(type, windowId); this.player = player; @@ -33,7 +33,7 @@ protected void addPlayerInventory(int xInventory, int yInventory) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 9; x++) { - addSlot(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18)); + addSlot(new Slot(player.getInventory(), id, xInventory + x * 18, yInventory + y * 18)); id++; } @@ -45,26 +45,26 @@ protected void addPlayerInventory(int xInventory, int yInventory) { int x = xInventory + i * 18; int y = yInventory + 4 + (3 * 18); - addSlot(new Slot(player.inventory, id, x, y)); + addSlot(new Slot(player.getInventory(), id, x, y)); id++; } } @Override - public ItemStack slotClick(int id, int dragType, ClickType clickType, PlayerEntity player) { + public void clicked(int id, int dragType, ClickType clickType, Player player) { Slot slot = id >= 0 ? getSlot(id) : null; - ItemStack holding = player.inventory.getItemStack(); + ItemStack holding = player.containerMenu.getCarried(); if (slot instanceof FilterSlot) { if (holding.isEmpty()) { - slot.putStack(ItemStack.EMPTY); - } else if (slot.isItemValid(holding)) { - slot.putStack(holding.copy()); + slot.set(ItemStack.EMPTY); + } else if (slot.mayPlace(holding)) { + slot.set(holding.copy()); } - return holding; + return; } else if (slot instanceof FluidFilterSlot) { if (holding.isEmpty()) { ((FluidFilterSlot) slot).onContainerClicked(ItemStack.EMPTY); @@ -72,10 +72,10 @@ public ItemStack slotClick(int id, int dragType, ClickType clickType, PlayerEnti ((FluidFilterSlot) slot).onContainerClicked(holding); } - return holding; + return; } - return super.slotClick(id, dragType, clickType, player); + super.clicked(id, dragType, clickType, player); } @Override @@ -89,10 +89,10 @@ protected Slot addSlot(Slot slot) { } @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); + public void broadcastChanges() { + super.broadcastChanges(); - if (!(player instanceof ServerPlayerEntity)) { + if (!(player instanceof ServerPlayer)) { return; } @@ -105,13 +105,13 @@ public void detectAndSendChanges() { if (!cached.equals(actual)) { this.fluids.set(i, actual.copy()); - RefinedPipes.NETWORK.sendToClient((ServerPlayerEntity) player, new FluidFilterSlotUpdateMessage(slot.slotNumber, actual)); + RefinedPipes.NETWORK.sendToClient((ServerPlayer) player, new FluidFilterSlotUpdateMessage(slot.getInventoryIndex(), actual)); } } } @Override - public boolean canInteractWith(PlayerEntity player) { + public boolean stillValid(Player player) { return true; } @@ -120,11 +120,11 @@ public List getFluidSlots() { } @Override - public boolean canMergeSlot(ItemStack stack, Slot slot) { + public boolean canTakeItemForPickAll(ItemStack stack, Slot slot) { if (slot instanceof FilterSlot || slot instanceof FluidFilterSlot) { return false; } - return super.canMergeSlot(stack, slot); + return super.canTakeItemForPickAll(stack, slot); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/container/ExtractorAttachmentContainer.java b/src/main/java/com/refinedmods/refinedpipes/container/ExtractorAttachmentContainerMenu.java similarity index 83% rename from src/main/java/com/refinedmods/refinedpipes/container/ExtractorAttachmentContainer.java rename to src/main/java/com/refinedmods/refinedpipes/container/ExtractorAttachmentContainerMenu.java index c8a3128..6047e8c 100644 --- a/src/main/java/com/refinedmods/refinedpipes/container/ExtractorAttachmentContainer.java +++ b/src/main/java/com/refinedmods/refinedpipes/container/ExtractorAttachmentContainerMenu.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedpipes.container; import com.refinedmods.refinedpipes.RefinedPipes; -import com.refinedmods.refinedpipes.RefinedPipesContainers; +import com.refinedmods.refinedpipes.RefinedPipesContainerMenus; import com.refinedmods.refinedpipes.container.slot.FilterSlot; import com.refinedmods.refinedpipes.container.slot.FluidFilterSlot; import com.refinedmods.refinedpipes.inventory.fluid.FluidInventory; @@ -11,17 +11,17 @@ import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.RedstoneMode; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.RoutingMode; import com.refinedmods.refinedpipes.util.FluidUtil; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.SlotItemHandler; -public class ExtractorAttachmentContainer extends BaseContainer { +public class ExtractorAttachmentContainerMenu extends BaseContainerMenu { private final BlockPos pos; private final Direction dir; private final ExtractorAttachmentType extractorAttachmentType; @@ -33,9 +33,9 @@ public class ExtractorAttachmentContainer extends BaseContainer { private int stackSize; private boolean exactMode; - public ExtractorAttachmentContainer( + public ExtractorAttachmentContainerMenu( int windowId, - PlayerEntity player, + Player player, BlockPos pos, Direction dir, RedstoneMode redstoneMode, @@ -47,7 +47,7 @@ public ExtractorAttachmentContainer( ItemStackHandler itemFilter, FluidInventory fluidFilter, boolean fluidMode) { - super(RefinedPipesContainers.EXTRACTOR_ATTACHMENT, windowId, player); + super(RefinedPipesContainerMenus.EXTRACTOR_ATTACHMENT, windowId, player); addPlayerInventory(8, 111); @@ -92,46 +92,46 @@ public RedstoneMode getRedstoneMode() { return redstoneMode; } - public BlacklistWhitelist getBlacklistWhitelist() { - return blacklistWhitelist; - } - - public RoutingMode getRoutingMode() { - return routingMode; - } - - public int getStackSize() { - return stackSize; - } - - public boolean isExactMode() { - return exactMode; - } - public void setRedstoneMode(RedstoneMode redstoneMode) { this.redstoneMode = redstoneMode; RefinedPipes.NETWORK.sendToServer(new ChangeRedstoneModeMessage(pos, dir, redstoneMode)); } + public BlacklistWhitelist getBlacklistWhitelist() { + return blacklistWhitelist; + } + public void setBlacklistWhitelist(BlacklistWhitelist blacklistWhitelist) { this.blacklistWhitelist = blacklistWhitelist; RefinedPipes.NETWORK.sendToServer(new ChangeBlacklistWhitelistMessage(pos, dir, blacklistWhitelist)); } + public RoutingMode getRoutingMode() { + return routingMode; + } + public void setRoutingMode(RoutingMode routingMode) { this.routingMode = routingMode; RefinedPipes.NETWORK.sendToServer(new ChangeRoutingModeMessage(pos, dir, routingMode)); } + public int getStackSize() { + return stackSize; + } + public void setStackSize(int stackSize) { this.stackSize = stackSize; RefinedPipes.NETWORK.sendToServer(new ChangeStackSizeMessage(pos, dir, stackSize)); } + public boolean isExactMode() { + return exactMode; + } + public void setExactMode(boolean exactMode) { this.exactMode = exactMode; @@ -139,17 +139,17 @@ public void setExactMode(boolean exactMode) { } @Override - public ItemStack transferStackInSlot(PlayerEntity player, int index) { - Slot slot = inventorySlots.get(index); - if (slot != null && slot.getHasStack() && index < 9 * 4) { - for (int i = 9 * 4; i < inventorySlots.size(); ++i) { - Slot filterSlot = inventorySlots.get(i); + public ItemStack quickMoveStack(Player player, int index) { + Slot slot = slots.get(index); + if (slot != null && slot.hasItem() && index < 9 * 4) { + for (int i = 9 * 4; i < slots.size(); ++i) { + Slot filterSlot = slots.get(i); if (filterSlot instanceof FluidFilterSlot) { FluidFilterSlot fluidSlot = (FluidFilterSlot) filterSlot; if (fluidSlot.getFluidInventory().getFluid(fluidSlot.getSlotIndex()).isEmpty()) { - FluidStack toInsert = FluidUtil.getFromStack(slot.getStack(), true).getValue(); + FluidStack toInsert = FluidUtil.getFromStack(slot.getItem(), true).getValue(); boolean foundExistingFluid = false; @@ -161,7 +161,7 @@ public ItemStack transferStackInSlot(PlayerEntity player, int index) { } if (!foundExistingFluid) { - fluidSlot.onContainerClicked(slot.getStack()); + fluidSlot.onContainerClicked(slot.getItem()); } break; @@ -169,20 +169,20 @@ public ItemStack transferStackInSlot(PlayerEntity player, int index) { } else if (filterSlot instanceof SlotItemHandler) { SlotItemHandler itemSlot = (SlotItemHandler) filterSlot; - if (!itemSlot.getHasStack()) { - ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot.getStack(), 1); + if (!itemSlot.hasItem()) { + ItemStack toInsert = ItemHandlerHelper.copyStackWithSize(slot.getItem(), 1); boolean foundExistingItem = false; for (int j = 0; j < itemSlot.getItemHandler().getSlots(); ++j) { - if (ItemStack.areItemStacksEqual(itemSlot.getItemHandler().getStackInSlot(j), toInsert)) { + if (ItemStack.matches(itemSlot.getItemHandler().getStackInSlot(j), toInsert)) { foundExistingItem = true; break; } } if (!foundExistingItem) { - itemSlot.putStack(toInsert); + itemSlot.set(toInsert); } break; diff --git a/src/main/java/com/refinedmods/refinedpipes/container/factory/ExtractorAttachmentContainerFactory.java b/src/main/java/com/refinedmods/refinedpipes/container/factory/ExtractorAttachmentContainerFactory.java index 67fed3a..6cb373b 100644 --- a/src/main/java/com/refinedmods/refinedpipes/container/factory/ExtractorAttachmentContainerFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/container/factory/ExtractorAttachmentContainerFactory.java @@ -1,16 +1,16 @@ package com.refinedmods.refinedpipes.container.factory; -import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainer; +import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainerMenu; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.*; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.network.PacketBuffer; -import net.minecraftforge.fml.network.IContainerFactory; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; +import net.minecraftforge.network.IContainerFactory; -public class ExtractorAttachmentContainerFactory implements IContainerFactory { +public class ExtractorAttachmentContainerFactory implements IContainerFactory { @Override - public ExtractorAttachmentContainer create(int windowId, PlayerInventory inv, PacketBuffer buf) { - return new ExtractorAttachmentContainer( + public ExtractorAttachmentContainerMenu create(int windowId, Inventory inv, FriendlyByteBuf buf) { + return new ExtractorAttachmentContainerMenu( windowId, inv.player, buf.readBlockPos(), diff --git a/src/main/java/com/refinedmods/refinedpipes/container/provider/ExtractorAttachmentContainerProvider.java b/src/main/java/com/refinedmods/refinedpipes/container/provider/ExtractorAttachmentMenuProvider.java similarity index 61% rename from src/main/java/com/refinedmods/refinedpipes/container/provider/ExtractorAttachmentContainerProvider.java rename to src/main/java/com/refinedmods/refinedpipes/container/provider/ExtractorAttachmentMenuProvider.java index 20964d7..6e0b0a5 100644 --- a/src/main/java/com/refinedmods/refinedpipes/container/provider/ExtractorAttachmentContainerProvider.java +++ b/src/main/java/com/refinedmods/refinedpipes/container/provider/ExtractorAttachmentMenuProvider.java @@ -1,38 +1,54 @@ package com.refinedmods.refinedpipes.container.provider; import com.refinedmods.refinedpipes.RefinedPipes; -import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainer; +import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainerMenu; import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachment; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraftforge.fml.network.NetworkHooks; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraftforge.network.NetworkHooks; import javax.annotation.Nullable; -public class ExtractorAttachmentContainerProvider implements INamedContainerProvider { +public class ExtractorAttachmentMenuProvider implements MenuProvider { private final Pipe pipe; private final ExtractorAttachment attachment; - public ExtractorAttachmentContainerProvider(Pipe pipe, ExtractorAttachment attachment) { + public ExtractorAttachmentMenuProvider(Pipe pipe, ExtractorAttachment attachment) { this.pipe = pipe; this.attachment = attachment; } + public static void open(Pipe pipe, ExtractorAttachment attachment, ServerPlayer player) { + ExtractorAttachmentMenuProvider provider = new ExtractorAttachmentMenuProvider(pipe, attachment); + + NetworkHooks.openGui(player, provider, buf -> { + buf.writeBlockPos(pipe.getPos()); + buf.writeByte(attachment.getDirection().ordinal()); + buf.writeByte(attachment.getRedstoneMode().ordinal()); + buf.writeByte(attachment.getBlacklistWhitelist().ordinal()); + buf.writeByte(attachment.getRoutingMode().ordinal()); + buf.writeInt(attachment.getStackSize()); + buf.writeBoolean(attachment.isExactMode()); + buf.writeByte(attachment.getType().ordinal()); + buf.writeBoolean(attachment.isFluidMode()); + }); + } + @Override - public ITextComponent getDisplayName() { - return new TranslationTextComponent("item." + RefinedPipes.ID + "." + attachment.getType().getId().getPath() + "_attachment"); + public Component getDisplayName() { + return new TranslatableComponent("item." + RefinedPipes.ID + "." + attachment.getType().getId().getPath() + "_attachment"); } @Nullable @Override - public Container createMenu(int windowId, PlayerInventory inv, PlayerEntity player) { - return new ExtractorAttachmentContainer( + public AbstractContainerMenu createMenu(int windowId, Inventory inv, Player player) { + return new ExtractorAttachmentContainerMenu( windowId, player, pipe.getPos(), @@ -48,20 +64,4 @@ public Container createMenu(int windowId, PlayerInventory inv, PlayerEntity play attachment.isFluidMode() ); } - - public static void open(Pipe pipe, ExtractorAttachment attachment, ServerPlayerEntity player) { - ExtractorAttachmentContainerProvider provider = new ExtractorAttachmentContainerProvider(pipe, attachment); - - NetworkHooks.openGui(player, provider, buf -> { - buf.writeBlockPos(pipe.getPos()); - buf.writeByte(attachment.getDirection().ordinal()); - buf.writeByte(attachment.getRedstoneMode().ordinal()); - buf.writeByte(attachment.getBlacklistWhitelist().ordinal()); - buf.writeByte(attachment.getRoutingMode().ordinal()); - buf.writeInt(attachment.getStackSize()); - buf.writeBoolean(attachment.isExactMode()); - buf.writeByte(attachment.getType().ordinal()); - buf.writeBoolean(attachment.isFluidMode()); - }); - } } diff --git a/src/main/java/com/refinedmods/refinedpipes/container/slot/FilterSlot.java b/src/main/java/com/refinedmods/refinedpipes/container/slot/FilterSlot.java index a17bf4c..23c5276 100644 --- a/src/main/java/com/refinedmods/refinedpipes/container/slot/FilterSlot.java +++ b/src/main/java/com/refinedmods/refinedpipes/container/slot/FilterSlot.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.container.slot; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; @@ -12,11 +12,11 @@ public FilterSlot(IItemHandler handler, int inventoryIndex, int x, int y) { } @Override - public void putStack(@Nonnull ItemStack stack) { + public void set(@Nonnull ItemStack stack) { if (!stack.isEmpty()) { stack.setCount(1); } - super.putStack(stack); + super.set(stack); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/container/slot/FluidFilterSlot.java b/src/main/java/com/refinedmods/refinedpipes/container/slot/FluidFilterSlot.java index 984385c..67ba520 100644 --- a/src/main/java/com/refinedmods/refinedpipes/container/slot/FluidFilterSlot.java +++ b/src/main/java/com/refinedmods/refinedpipes/container/slot/FluidFilterSlot.java @@ -2,23 +2,29 @@ import com.refinedmods.refinedpipes.inventory.fluid.FluidInventory; import com.refinedmods.refinedpipes.util.FluidUtil; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.SlotItemHandler; import javax.annotation.Nonnull; public class FluidFilterSlot extends SlotItemHandler { + private final int inventoryIndex; private FluidInventory fluidInventory; public FluidFilterSlot(FluidInventory inventory, int inventoryIndex, int x, int y) { super(new ItemStackHandler(inventory.getSlots()), inventoryIndex, x, y); this.fluidInventory = inventory; + this.inventoryIndex = inventoryIndex; + } + + public int getInventoryIndex() { + return inventoryIndex; } @Override - public boolean isItemValid(@Nonnull ItemStack stack) { + public boolean mayPlace(@Nonnull ItemStack stack) { return false; } diff --git a/src/main/java/com/refinedmods/refinedpipes/inventory/fluid/FluidInventory.java b/src/main/java/com/refinedmods/refinedpipes/inventory/fluid/FluidInventory.java index 906262f..0f90330 100644 --- a/src/main/java/com/refinedmods/refinedpipes/inventory/fluid/FluidInventory.java +++ b/src/main/java/com/refinedmods/refinedpipes/inventory/fluid/FluidInventory.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.inventory.fluid; -import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.CompoundTag; import net.minecraftforge.fluids.FluidStack; import javax.annotation.Nonnull; @@ -52,21 +52,21 @@ public void setFluid(int slot, @Nonnull FluidStack stack) { onContentsChanged(); } - public CompoundNBT writeToNbt() { - CompoundNBT tag = new CompoundNBT(); + public CompoundTag writeToNbt() { + CompoundTag tag = new CompoundTag(); for (int i = 0; i < getSlots(); ++i) { FluidStack stack = getFluid(i); if (!stack.isEmpty()) { - tag.put(String.format(NBT_SLOT, i), stack.writeToNBT(new CompoundNBT())); + tag.put(String.format(NBT_SLOT, i), stack.writeToNBT(new CompoundTag())); } } return tag; } - public void readFromNbt(CompoundNBT tag) { + public void readFromNbt(CompoundTag tag) { for (int i = 0; i < getSlots(); ++i) { String key = String.format(NBT_SLOT, i); diff --git a/src/main/java/com/refinedmods/refinedpipes/item/AttachmentItem.java b/src/main/java/com/refinedmods/refinedpipes/item/AttachmentItem.java index dc76368..e49de8f 100644 --- a/src/main/java/com/refinedmods/refinedpipes/item/AttachmentItem.java +++ b/src/main/java/com/refinedmods/refinedpipes/item/AttachmentItem.java @@ -2,11 +2,11 @@ import com.refinedmods.refinedpipes.RefinedPipes; import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentFactory; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; import javax.annotation.Nullable; import java.util.List; @@ -15,7 +15,7 @@ public class AttachmentItem extends Item { private final AttachmentFactory type; public AttachmentItem(AttachmentFactory type) { - super(new Item.Properties().group(RefinedPipes.MAIN_GROUP)); + super(new Item.Properties().tab(RefinedPipes.MAIN_GROUP)); this.type = type; @@ -23,8 +23,8 @@ public AttachmentItem(AttachmentFactory type) { } @Override - public void addInformation(ItemStack stack, @Nullable World world, List tooltip, ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag flag) { + super.appendHoverText(stack, level, tooltip, flag); type.addInformation(tooltip); } diff --git a/src/main/java/com/refinedmods/refinedpipes/item/BaseBlockItem.java b/src/main/java/com/refinedmods/refinedpipes/item/BaseBlockItem.java index 2432bbd..7e178bc 100644 --- a/src/main/java/com/refinedmods/refinedpipes/item/BaseBlockItem.java +++ b/src/main/java/com/refinedmods/refinedpipes/item/BaseBlockItem.java @@ -1,13 +1,13 @@ package com.refinedmods.refinedpipes.item; import com.refinedmods.refinedpipes.RefinedPipes; -import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; public class BaseBlockItem extends BlockItem { public BaseBlockItem(Block block) { - super(block, new Item.Properties().group(RefinedPipes.MAIN_GROUP)); + super(block, new Item.Properties().tab(RefinedPipes.MAIN_GROUP)); this.setRegistryName(block.getRegistryName()); } diff --git a/src/main/java/com/refinedmods/refinedpipes/item/EnergyPipeBlockItem.java b/src/main/java/com/refinedmods/refinedpipes/item/EnergyPipeBlockItem.java index 8fa0f86..09afd33 100644 --- a/src/main/java/com/refinedmods/refinedpipes/item/EnergyPipeBlockItem.java +++ b/src/main/java/com/refinedmods/refinedpipes/item/EnergyPipeBlockItem.java @@ -3,13 +3,13 @@ import com.refinedmods.refinedpipes.block.EnergyPipeBlock; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeType; import com.refinedmods.refinedpipes.util.StringUtil; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.World; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; import javax.annotation.Nullable; import java.util.List; @@ -24,19 +24,19 @@ public EnergyPipeBlockItem(EnergyPipeBlock block) { } @Override - public void addInformation(ItemStack stack, @Nullable World world, List tooltip, ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag flag) { + super.appendHoverText(stack, level, tooltip, flag); - tooltip.add(new TranslationTextComponent("misc.refinedpipes.tier", new TranslationTextComponent("enchantment.level." + type.getTier())).mergeStyle(TextFormatting.YELLOW)); + tooltip.add(new TranslatableComponent("misc.refinedpipes.tier", new TranslatableComponent("enchantment.level." + type.getTier())).withStyle(ChatFormatting.YELLOW)); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.energy_pipe.capacity", - new StringTextComponent(StringUtil.formatNumber(type.getCapacity()) + " FE").mergeStyle(TextFormatting.WHITE) - ).mergeStyle(TextFormatting.GRAY)); + new TextComponent(StringUtil.formatNumber(type.getCapacity()) + " FE").withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY)); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.energy_pipe.transfer_rate", - new StringTextComponent(StringUtil.formatNumber(type.getTransferRate()) + " FE/t").mergeStyle(TextFormatting.WHITE) - ).mergeStyle(TextFormatting.GRAY)); + new TextComponent(StringUtil.formatNumber(type.getTransferRate()) + " FE/t").withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY)); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/item/FluidPipeBlockItem.java b/src/main/java/com/refinedmods/refinedpipes/item/FluidPipeBlockItem.java index 840299e..062d57b 100644 --- a/src/main/java/com/refinedmods/refinedpipes/item/FluidPipeBlockItem.java +++ b/src/main/java/com/refinedmods/refinedpipes/item/FluidPipeBlockItem.java @@ -3,13 +3,13 @@ import com.refinedmods.refinedpipes.block.FluidPipeBlock; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipeType; import com.refinedmods.refinedpipes.util.StringUtil; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.World; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; import javax.annotation.Nullable; import java.util.List; @@ -24,19 +24,19 @@ public FluidPipeBlockItem(FluidPipeBlock block) { } @Override - public void addInformation(ItemStack stack, @Nullable World world, List tooltip, ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag flag) { + super.appendHoverText(stack, level, tooltip, flag); - tooltip.add(new TranslationTextComponent("misc.refinedpipes.tier", new TranslationTextComponent("enchantment.level." + type.getTier())).mergeStyle(TextFormatting.YELLOW)); + tooltip.add(new TranslatableComponent("misc.refinedpipes.tier", new TranslatableComponent("enchantment.level." + type.getTier())).withStyle(ChatFormatting.YELLOW)); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.fluid_pipe.capacity", - new StringTextComponent(StringUtil.formatNumber(type.getCapacity()) + " mB").mergeStyle(TextFormatting.WHITE) - ).mergeStyle(TextFormatting.GRAY)); + new TextComponent(StringUtil.formatNumber(type.getCapacity()) + " mB").withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY)); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.fluid_pipe.transfer_rate", - new StringTextComponent(StringUtil.formatNumber(type.getTransferRate()) + " mB/t").mergeStyle(TextFormatting.WHITE) - ).mergeStyle(TextFormatting.GRAY)); + new TextComponent(StringUtil.formatNumber(type.getTransferRate()) + " mB/t").withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY)); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/item/ItemPipeBlockItem.java b/src/main/java/com/refinedmods/refinedpipes/item/ItemPipeBlockItem.java index f56f394..91fe363 100644 --- a/src/main/java/com/refinedmods/refinedpipes/item/ItemPipeBlockItem.java +++ b/src/main/java/com/refinedmods/refinedpipes/item/ItemPipeBlockItem.java @@ -2,13 +2,13 @@ import com.refinedmods.refinedpipes.block.ItemPipeBlock; import com.refinedmods.refinedpipes.network.pipe.item.ItemPipeType; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.World; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; import javax.annotation.Nullable; import java.util.List; @@ -23,14 +23,14 @@ public ItemPipeBlockItem(ItemPipeBlock block) { } @Override - public void addInformation(ItemStack stack, @Nullable World world, List tooltip, ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag flag) { + super.appendHoverText(stack, level, tooltip, flag); - tooltip.add(new TranslationTextComponent("misc.refinedpipes.tier", new TranslationTextComponent("enchantment.level." + type.getTier())).mergeStyle(TextFormatting.YELLOW)); + tooltip.add(new TranslatableComponent("misc.refinedpipes.tier", new TranslatableComponent("enchantment.level." + type.getTier())).withStyle(ChatFormatting.YELLOW)); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.item_pipe.speed", - new StringTextComponent(type.getSpeedComparedToBasicTier() + "%").mergeStyle(TextFormatting.WHITE) - ).mergeStyle(TextFormatting.GRAY)); + new TextComponent(type.getSpeedComparedToBasicTier() + "%").withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY)); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/item/creativetab/MainCreativeModeTab.java b/src/main/java/com/refinedmods/refinedpipes/item/creativetab/MainCreativeModeTab.java new file mode 100644 index 0000000..c762922 --- /dev/null +++ b/src/main/java/com/refinedmods/refinedpipes/item/creativetab/MainCreativeModeTab.java @@ -0,0 +1,17 @@ +package com.refinedmods.refinedpipes.item.creativetab; + +import com.refinedmods.refinedpipes.RefinedPipes; +import com.refinedmods.refinedpipes.RefinedPipesItems; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; + +public class MainCreativeModeTab extends CreativeModeTab { + public MainCreativeModeTab() { + super(RefinedPipes.ID); + } + + @Override + public ItemStack makeIcon() { + return new ItemStack(RefinedPipesItems.BASIC_ITEM_PIPE); + } +} diff --git a/src/main/java/com/refinedmods/refinedpipes/item/group/MainItemGroup.java b/src/main/java/com/refinedmods/refinedpipes/item/group/MainItemGroup.java deleted file mode 100644 index efea0e1..0000000 --- a/src/main/java/com/refinedmods/refinedpipes/item/group/MainItemGroup.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.refinedmods.refinedpipes.item.group; - -import com.refinedmods.refinedpipes.RefinedPipes; -import com.refinedmods.refinedpipes.RefinedPipesItems; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; - -public class MainItemGroup extends ItemGroup { - public MainItemGroup() { - super(RefinedPipes.ID); - } - - @Override - public ItemStack createIcon() { - return new ItemStack(RefinedPipesItems.BASIC_ITEM_PIPE); - } -} diff --git a/src/main/java/com/refinedmods/refinedpipes/message/ChangeBlacklistWhitelistMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/ChangeBlacklistWhitelistMessage.java index c1aa70e..8e68f82 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/ChangeBlacklistWhitelistMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/ChangeBlacklistWhitelistMessage.java @@ -1,16 +1,16 @@ package com.refinedmods.refinedpipes.message; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.BlacklistWhitelist; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachment; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -25,13 +25,13 @@ public ChangeBlacklistWhitelistMessage(BlockPos pos, Direction direction, Blackl this.blacklistWhitelist = blacklistWhitelist; } - public static void encode(ChangeBlacklistWhitelistMessage message, PacketBuffer buf) { + public static void encode(ChangeBlacklistWhitelistMessage message, FriendlyByteBuf buf) { buf.writeBlockPos(message.pos); buf.writeByte(message.direction.ordinal()); buf.writeByte(message.blacklistWhitelist.ordinal()); } - public static ChangeBlacklistWhitelistMessage decode(PacketBuffer buf) { + public static ChangeBlacklistWhitelistMessage decode(FriendlyByteBuf buf) { BlockPos pos = buf.readBlockPos(); Direction direction = DirectionUtil.safeGet(buf.readByte()); BlacklistWhitelist blacklistWhitelist = BlacklistWhitelist.get(buf.readByte()); @@ -41,15 +41,15 @@ public static ChangeBlacklistWhitelistMessage decode(PacketBuffer buf) { public static void handle(ChangeBlacklistWhitelistMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - TileEntity tile = ctx.get().getSender().world.getTileEntity(message.pos); + BlockEntity blockEntity = ctx.get().getSender().level.getBlockEntity(message.pos); - if (tile instanceof PipeTileEntity) { - Attachment attachment = ((PipeTileEntity) tile).getAttachmentManager().getAttachment(message.direction); + if (blockEntity instanceof PipeBlockEntity) { + Attachment attachment = ((PipeBlockEntity) blockEntity).getAttachmentManager().getAttachment(message.direction); if (attachment instanceof ExtractorAttachment) { ((ExtractorAttachment) attachment).setBlacklistWhitelist(message.blacklistWhitelist); - NetworkManager.get(tile.getWorld()).markDirty(); + NetworkManager.get(blockEntity.getLevel()).setDirty(); } } }); diff --git a/src/main/java/com/refinedmods/refinedpipes/message/ChangeExactModeMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/ChangeExactModeMessage.java index 3d3dfdd..2049a46 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/ChangeExactModeMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/ChangeExactModeMessage.java @@ -1,15 +1,15 @@ package com.refinedmods.refinedpipes.message; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachment; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -24,13 +24,13 @@ public ChangeExactModeMessage(BlockPos pos, Direction direction, boolean exactMo this.exactMode = exactMode; } - public static void encode(ChangeExactModeMessage message, PacketBuffer buf) { + public static void encode(ChangeExactModeMessage message, FriendlyByteBuf buf) { buf.writeBlockPos(message.pos); buf.writeByte(message.direction.ordinal()); buf.writeBoolean(message.exactMode); } - public static ChangeExactModeMessage decode(PacketBuffer buf) { + public static ChangeExactModeMessage decode(FriendlyByteBuf buf) { BlockPos pos = buf.readBlockPos(); Direction direction = DirectionUtil.safeGet(buf.readByte()); boolean exactMode = buf.readBoolean(); @@ -40,15 +40,15 @@ public static ChangeExactModeMessage decode(PacketBuffer buf) { public static void handle(ChangeExactModeMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - TileEntity tile = ctx.get().getSender().world.getTileEntity(message.pos); + BlockEntity blockEntity = ctx.get().getSender().level.getBlockEntity(message.pos); - if (tile instanceof PipeTileEntity) { - Attachment attachment = ((PipeTileEntity) tile).getAttachmentManager().getAttachment(message.direction); + if (blockEntity instanceof PipeBlockEntity) { + Attachment attachment = ((PipeBlockEntity) blockEntity).getAttachmentManager().getAttachment(message.direction); if (attachment instanceof ExtractorAttachment) { ((ExtractorAttachment) attachment).setExactMode(message.exactMode); - NetworkManager.get(tile.getWorld()).markDirty(); + NetworkManager.get(blockEntity.getLevel()).setDirty(); } } }); diff --git a/src/main/java/com/refinedmods/refinedpipes/message/ChangeRedstoneModeMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/ChangeRedstoneModeMessage.java index ef2797b..0ae2213 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/ChangeRedstoneModeMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/ChangeRedstoneModeMessage.java @@ -1,16 +1,16 @@ package com.refinedmods.refinedpipes.message; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.RedstoneMode; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -25,13 +25,13 @@ public ChangeRedstoneModeMessage(BlockPos pos, Direction direction, RedstoneMode this.redstoneMode = redstoneMode; } - public static void encode(ChangeRedstoneModeMessage message, PacketBuffer buf) { + public static void encode(ChangeRedstoneModeMessage message, FriendlyByteBuf buf) { buf.writeBlockPos(message.pos); buf.writeByte(message.direction.ordinal()); buf.writeByte(message.redstoneMode.ordinal()); } - public static ChangeRedstoneModeMessage decode(PacketBuffer buf) { + public static ChangeRedstoneModeMessage decode(FriendlyByteBuf buf) { BlockPos pos = buf.readBlockPos(); Direction direction = DirectionUtil.safeGet(buf.readByte()); RedstoneMode redstoneMode = RedstoneMode.get(buf.readByte()); @@ -41,15 +41,15 @@ public static ChangeRedstoneModeMessage decode(PacketBuffer buf) { public static void handle(ChangeRedstoneModeMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - TileEntity tile = ctx.get().getSender().world.getTileEntity(message.pos); + BlockEntity blockEntity = ctx.get().getSender().level.getBlockEntity(message.pos); - if (tile instanceof PipeTileEntity) { - Attachment attachment = ((PipeTileEntity) tile).getAttachmentManager().getAttachment(message.direction); + if (blockEntity instanceof PipeBlockEntity) { + Attachment attachment = ((PipeBlockEntity) blockEntity).getAttachmentManager().getAttachment(message.direction); if (attachment instanceof ExtractorAttachment) { ((ExtractorAttachment) attachment).setRedstoneMode(message.redstoneMode); - NetworkManager.get(tile.getWorld()).markDirty(); + NetworkManager.get(blockEntity.getLevel()).setDirty(); } } }); diff --git a/src/main/java/com/refinedmods/refinedpipes/message/ChangeRoutingModeMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/ChangeRoutingModeMessage.java index b43566d..3b0d627 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/ChangeRoutingModeMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/ChangeRoutingModeMessage.java @@ -1,16 +1,16 @@ package com.refinedmods.refinedpipes.message; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.RoutingMode; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -25,13 +25,13 @@ public ChangeRoutingModeMessage(BlockPos pos, Direction direction, RoutingMode r this.routingMode = routingMode; } - public static void encode(ChangeRoutingModeMessage message, PacketBuffer buf) { + public static void encode(ChangeRoutingModeMessage message, FriendlyByteBuf buf) { buf.writeBlockPos(message.pos); buf.writeByte(message.direction.ordinal()); buf.writeByte(message.routingMode.ordinal()); } - public static ChangeRoutingModeMessage decode(PacketBuffer buf) { + public static ChangeRoutingModeMessage decode(FriendlyByteBuf buf) { BlockPos pos = buf.readBlockPos(); Direction direction = DirectionUtil.safeGet(buf.readByte()); RoutingMode redstoneMode = RoutingMode.get(buf.readByte()); @@ -41,15 +41,15 @@ public static ChangeRoutingModeMessage decode(PacketBuffer buf) { public static void handle(ChangeRoutingModeMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - TileEntity tile = ctx.get().getSender().world.getTileEntity(message.pos); + BlockEntity blockEntity = ctx.get().getSender().level.getBlockEntity(message.pos); - if (tile instanceof PipeTileEntity) { - Attachment attachment = ((PipeTileEntity) tile).getAttachmentManager().getAttachment(message.direction); + if (blockEntity instanceof PipeBlockEntity) { + Attachment attachment = ((PipeBlockEntity) blockEntity).getAttachmentManager().getAttachment(message.direction); if (attachment instanceof ExtractorAttachment) { ((ExtractorAttachment) attachment).setRoutingMode(message.routingMode); - NetworkManager.get(tile.getWorld()).markDirty(); + NetworkManager.get(blockEntity.getLevel()).setDirty(); } } }); diff --git a/src/main/java/com/refinedmods/refinedpipes/message/ChangeStackSizeMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/ChangeStackSizeMessage.java index 1fb06e1..851fc36 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/ChangeStackSizeMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/ChangeStackSizeMessage.java @@ -1,15 +1,15 @@ package com.refinedmods.refinedpipes.message; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; import com.refinedmods.refinedpipes.network.NetworkManager; import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachment; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -24,13 +24,13 @@ public ChangeStackSizeMessage(BlockPos pos, Direction direction, int stackSize) this.stackSize = stackSize; } - public static void encode(ChangeStackSizeMessage message, PacketBuffer buf) { + public static void encode(ChangeStackSizeMessage message, FriendlyByteBuf buf) { buf.writeBlockPos(message.pos); buf.writeByte(message.direction.ordinal()); buf.writeInt(message.stackSize); } - public static ChangeStackSizeMessage decode(PacketBuffer buf) { + public static ChangeStackSizeMessage decode(FriendlyByteBuf buf) { BlockPos pos = buf.readBlockPos(); Direction direction = DirectionUtil.safeGet(buf.readByte()); int stackSize = buf.readInt(); @@ -40,15 +40,15 @@ public static ChangeStackSizeMessage decode(PacketBuffer buf) { public static void handle(ChangeStackSizeMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - TileEntity tile = ctx.get().getSender().world.getTileEntity(message.pos); + BlockEntity blockEntity = ctx.get().getSender().level.getBlockEntity(message.pos); - if (tile instanceof PipeTileEntity) { - Attachment attachment = ((PipeTileEntity) tile).getAttachmentManager().getAttachment(message.direction); + if (blockEntity instanceof PipeBlockEntity) { + Attachment attachment = ((PipeBlockEntity) blockEntity).getAttachmentManager().getAttachment(message.direction); if (attachment instanceof ExtractorAttachment) { ((ExtractorAttachment) attachment).setStackSize(message.stackSize); - NetworkManager.get(tile.getWorld()).markDirty(); + NetworkManager.get(blockEntity.getLevel()).setDirty(); } } }); diff --git a/src/main/java/com/refinedmods/refinedpipes/message/FluidFilterSlotUpdateMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/FluidFilterSlotUpdateMessage.java index 1efd9a5..5184e31 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/FluidFilterSlotUpdateMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/FluidFilterSlotUpdateMessage.java @@ -2,11 +2,11 @@ import com.refinedmods.refinedpipes.container.slot.FluidFilterSlot; import net.minecraft.client.Minecraft; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.Slot; -import net.minecraft.network.PacketBuffer; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -19,23 +19,23 @@ public FluidFilterSlotUpdateMessage(int containerSlot, FluidStack stack) { this.stack = stack; } - public static void encode(FluidFilterSlotUpdateMessage message, PacketBuffer buf) { + public static void encode(FluidFilterSlotUpdateMessage message, FriendlyByteBuf buf) { buf.writeInt(message.containerSlot); message.stack.writeToPacket(buf); } - public static FluidFilterSlotUpdateMessage decode(PacketBuffer buf) { + public static FluidFilterSlotUpdateMessage decode(FriendlyByteBuf buf) { return new FluidFilterSlotUpdateMessage(buf.readInt(), FluidStack.readFromPacket(buf)); } public static void handle(FluidFilterSlotUpdateMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - Container container = Minecraft.getInstance().player.openContainer; + AbstractContainerMenu container = Minecraft.getInstance().player.containerMenu; if (container == null) { return; } - if (message.containerSlot < 0 || message.containerSlot >= container.inventorySlots.size()) { + if (message.containerSlot < 0 || message.containerSlot >= container.slots.size()) { return; } diff --git a/src/main/java/com/refinedmods/refinedpipes/message/FluidPipeMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/FluidPipeMessage.java index dfae38a..7ef4ce1 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/FluidPipeMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/FluidPipeMessage.java @@ -1,12 +1,12 @@ package com.refinedmods.refinedpipes.message; -import com.refinedmods.refinedpipes.tile.FluidPipeTileEntity; +import com.refinedmods.refinedpipes.blockentity.FluidPipeBlockEntity; import net.minecraft.client.Minecraft; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -24,13 +24,13 @@ public FluidPipeMessage(BlockPos pos, FluidStack fluid, float fullness) { public FluidPipeMessage() { } - public static void encode(FluidPipeMessage message, PacketBuffer buf) { + public static void encode(FluidPipeMessage message, FriendlyByteBuf buf) { buf.writeBlockPos(message.pos); buf.writeFluidStack(message.fluid); buf.writeFloat(message.fullness); } - public static FluidPipeMessage decode(PacketBuffer buf) { + public static FluidPipeMessage decode(FriendlyByteBuf buf) { BlockPos pos = buf.readBlockPos(); FluidStack fluid = buf.readFluidStack(); float fullness = buf.readFloat(); @@ -40,11 +40,11 @@ public static FluidPipeMessage decode(PacketBuffer buf) { public static void handle(FluidPipeMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - TileEntity tile = Minecraft.getInstance().world.getTileEntity(message.pos); + BlockEntity blockEntity = Minecraft.getInstance().level.getBlockEntity(message.pos); - if (tile instanceof FluidPipeTileEntity) { - ((FluidPipeTileEntity) tile).setFluid(message.fluid); - ((FluidPipeTileEntity) tile).setFullness(message.fullness); + if (blockEntity instanceof FluidPipeBlockEntity) { + ((FluidPipeBlockEntity) blockEntity).setFluid(message.fluid); + ((FluidPipeBlockEntity) blockEntity).setFullness(message.fullness); } }); diff --git a/src/main/java/com/refinedmods/refinedpipes/message/ItemTransportMessage.java b/src/main/java/com/refinedmods/refinedpipes/message/ItemTransportMessage.java index 6e5a3d8..ed48c00 100644 --- a/src/main/java/com/refinedmods/refinedpipes/message/ItemTransportMessage.java +++ b/src/main/java/com/refinedmods/refinedpipes/message/ItemTransportMessage.java @@ -1,12 +1,12 @@ package com.refinedmods.refinedpipes.message; +import com.refinedmods.refinedpipes.blockentity.ItemPipeBlockEntity; import com.refinedmods.refinedpipes.network.pipe.transport.ItemTransportProps; -import com.refinedmods.refinedpipes.tile.ItemPipeTileEntity; import net.minecraft.client.Minecraft; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.network.NetworkEvent; import java.util.ArrayList; import java.util.List; @@ -21,14 +21,14 @@ public ItemTransportMessage(BlockPos pos, List props) { this.props = props; } - public static void encode(ItemTransportMessage message, PacketBuffer buf) { + public static void encode(ItemTransportMessage message, FriendlyByteBuf buf) { buf.writeBlockPos(message.pos); buf.writeInt(message.props.size()); message.props.forEach(p -> p.writeToBuffer(buf)); } - public static ItemTransportMessage decode(PacketBuffer buf) { + public static ItemTransportMessage decode(FriendlyByteBuf buf) { BlockPos pos = buf.readBlockPos(); int count = buf.readInt(); List props = new ArrayList<>(); @@ -42,10 +42,10 @@ public static ItemTransportMessage decode(PacketBuffer buf) { public static void handle(ItemTransportMessage message, Supplier ctx) { ctx.get().enqueueWork(() -> { - TileEntity tile = Minecraft.getInstance().world.getTileEntity(message.pos); + BlockEntity blockEntity = Minecraft.getInstance().level.getBlockEntity(message.pos); - if (tile instanceof ItemPipeTileEntity) { - ((ItemPipeTileEntity) tile).setProps(message.props); + if (blockEntity instanceof ItemPipeBlockEntity) { + ((ItemPipeBlockEntity) blockEntity).setProps(message.props); } }); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/Network.java b/src/main/java/com/refinedmods/refinedpipes/network/Network.java index ff61e31..8d4484e 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/Network.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/Network.java @@ -5,10 +5,10 @@ import com.refinedmods.refinedpipes.network.pipe.Destination; import com.refinedmods.refinedpipes.network.pipe.DestinationType; import com.refinedmods.refinedpipes.network.pipe.Pipe; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; import java.util.List; import java.util.Objects; @@ -32,26 +32,26 @@ public String getId() { return id; } - public NetworkGraphScannerResult scanGraph(World world, BlockPos pos) { - return graph.scan(world, pos); + public NetworkGraphScannerResult scanGraph(Level level, BlockPos pos) { + return graph.scan(level, pos); } public List getDestinations(DestinationType type) { return graph.getDestinations(type); } - public CompoundNBT writeToNbt(CompoundNBT tag) { + public CompoundTag writeToNbt(CompoundTag tag) { tag.putString("id", id); - tag.putLong("origin", originPos.toLong()); + tag.putLong("origin", originPos.asLong()); return tag; } - public void update(World world) { + public void update(Level level) { if (!didDoInitialScan) { didDoInitialScan = true; - scanGraph(world, originPos); + scanGraph(level, originPos); } graph.getPipes().forEach(Pipe::update); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/NetworkFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/NetworkFactory.java index c6e1112..dc08351 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/NetworkFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/NetworkFactory.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes.network; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; public interface NetworkFactory { Network create(BlockPos pos); - Network create(CompoundNBT tag); + Network create(CompoundTag tag); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/NetworkManager.java b/src/main/java/com/refinedmods/refinedpipes/network/NetworkManager.java index 4054e53..3d2c235 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/NetworkManager.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/NetworkManager.java @@ -6,42 +6,42 @@ import com.refinedmods.refinedpipes.network.pipe.PipeFactory; import com.refinedmods.refinedpipes.network.pipe.PipeRegistry; import com.refinedmods.refinedpipes.network.pipe.item.ItemPipe; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.INBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.WorldSavedData; -import net.minecraftforge.common.util.Constants; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.saveddata.SavedData; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.util.*; -public class NetworkManager extends WorldSavedData { +public class NetworkManager extends SavedData { private static final String NAME = RefinedPipes.ID + "_networks"; private static final Logger LOGGER = LogManager.getLogger(NetworkManager.class); + private final Level level; + private final Map networks = new HashMap<>(); + private final Map pipes = new HashMap<>(); - public static NetworkManager get(World world) { - return get((ServerWorld) world); + public NetworkManager(Level level) { + this.level = level; } - public static NetworkManager get(ServerWorld world) { - return world.getSavedData().getOrCreate(() -> new NetworkManager(NAME, world), NAME); + public static NetworkManager get(Level level) { + return get((ServerLevel) level); } - private final World world; - private final Map networks = new HashMap<>(); - private final Map pipes = new HashMap<>(); - - public NetworkManager(String name, World world) { - super(name); - - this.world = world; + public static NetworkManager get(ServerLevel level) { + return level.getDataStorage().computeIfAbsent((tag) -> { + NetworkManager networkManager = new NetworkManager(level); + networkManager.load(tag); + return networkManager; + }, () -> new NetworkManager(level), NAME); } public void addNetwork(Network network) { @@ -53,7 +53,7 @@ public void addNetwork(Network network) { LOGGER.debug("Network {} created", network.getId()); - markDirty(); + setDirty(); } public void removeNetwork(String id) { @@ -65,18 +65,18 @@ public void removeNetwork(String id) { LOGGER.debug("Network {} removed", id); - markDirty(); + setDirty(); } - private void formNetworkAt(World world, BlockPos pos, ResourceLocation type) { + private void formNetworkAt(Level level, BlockPos pos, ResourceLocation type) { Network network = NetworkRegistry.INSTANCE.getFactory(type).create(pos); addNetwork(network); - network.scanGraph(world, pos); + network.scanGraph(level, pos); } - private void mergeNetworksIntoOne(Set candidates, World world, BlockPos pos) { + private void mergeNetworksIntoOne(Set candidates, Level level, BlockPos pos) { if (candidates.isEmpty()) { throw new RuntimeException("Cannot merge networks: no candidates"); } @@ -110,7 +110,7 @@ private void mergeNetworksIntoOne(Set candidates, World world, BlockPos po } } - mainNetwork.scanGraph(world, pos); + mainNetwork.scanGraph(level, pos); mergedNetworks.forEach(n -> n.onMergedWith(mainNetwork)); } @@ -124,14 +124,14 @@ public void addPipe(Pipe pipe) { LOGGER.debug("Pipe added at {}", pipe.getPos()); - markDirty(); + setDirty(); Set adjacentPipes = findAdjacentPipes(pipe.getPos(), pipe.getNetworkType()); if (adjacentPipes.isEmpty()) { - formNetworkAt(pipe.getWorld(), pipe.getPos(), pipe.getNetworkType()); + formNetworkAt(pipe.getLevel(), pipe.getPos(), pipe.getNetworkType()); } else { - mergeNetworksIntoOne(adjacentPipes, pipe.getWorld(), pipe.getPos()); + mergeNetworksIntoOne(adjacentPipes, pipe.getLevel(), pipe.getPos()); } } @@ -149,7 +149,7 @@ public void removePipe(BlockPos pos) { LOGGER.debug("Pipe removed at {}", pipe.getPos()); - markDirty(); + setDirty(); if (pipe.getNetwork() != null) { splitNetworks(pipe); @@ -174,10 +174,10 @@ private void splitNetworks(Pipe originPipe) { if (otherPipeInNetwork != null) { otherPipeInNetwork.getNetwork().setOriginPos(otherPipeInNetwork.getPos()); - markDirty(); + setDirty(); NetworkGraphScannerResult result = otherPipeInNetwork.getNetwork().scanGraph( - otherPipeInNetwork.getWorld(), + otherPipeInNetwork.getLevel(), otherPipeInNetwork.getPos() ); @@ -195,7 +195,7 @@ private void splitNetworks(Pipe originPipe) { // The formNetworkAt call below can let these removed pipes join a network again. // We only have to form a new network when necessary, hence the null check. if (removed.getNetwork() == null) { - formNetworkAt(removed.getWorld(), removed.getPos(), removed.getNetworkType()); + formNetworkAt(removed.getLevel(), removed.getPos(), removed.getNetworkType()); } } @@ -213,7 +213,7 @@ private Set findAdjacentPipes(BlockPos pos, ResourceLocation networkType) Set pipes = new HashSet<>(); for (Direction dir : Direction.values()) { - Pipe pipe = getPipe(pos.offset(dir)); + Pipe pipe = getPipe(pos.relative(dir)); if (pipe != null && pipe.getNetworkType().equals(networkType)) { pipes.add(pipe); @@ -226,7 +226,7 @@ private Set findAdjacentPipes(BlockPos pos, ResourceLocation networkType) @Nullable private Pipe findFirstAdjacentPipe(BlockPos pos, ResourceLocation networkType) { for (Direction dir : Direction.values()) { - Pipe pipe = getPipe(pos.offset(dir)); + Pipe pipe = getPipe(pos.relative(dir)); if (pipe != null && pipe.getNetworkType().equals(networkType)) { return pipe; @@ -245,11 +245,10 @@ public Collection getNetworks() { return networks.values(); } - @Override - public void read(CompoundNBT tag) { - ListNBT pipes = tag.getList("pipes", Constants.NBT.TAG_COMPOUND); - for (INBT pipeTag : pipes) { - CompoundNBT pipeTagCompound = (CompoundNBT) pipeTag; + public void load(CompoundTag tag) { + ListTag pipes = tag.getList("pipes", Tag.TAG_COMPOUND); + for (Tag pipeTag : pipes) { + CompoundTag pipeTagCompound = (CompoundTag) pipeTag; // @BC ResourceLocation factoryId = pipeTagCompound.contains("id") ? new ResourceLocation(pipeTagCompound.getString("id")) : ItemPipe.ID; @@ -260,14 +259,14 @@ public void read(CompoundNBT tag) { continue; } - Pipe pipe = factory.createFromNbt(world, pipeTagCompound); + Pipe pipe = factory.createFromNbt(level, pipeTagCompound); this.pipes.put(pipe.getPos(), pipe); } - ListNBT nets = tag.getList("networks", Constants.NBT.TAG_COMPOUND); - for (INBT netTag : nets) { - CompoundNBT netTagCompound = (CompoundNBT) netTag; + ListTag nets = tag.getList("networks", Tag.TAG_COMPOUND); + for (Tag netTag : nets) { + CompoundTag netTagCompound = (CompoundTag) netTag; if (!netTagCompound.contains("type")) { LOGGER.warn("Skipping network without type"); continue; @@ -291,18 +290,18 @@ public void read(CompoundNBT tag) { } @Override - public CompoundNBT write(CompoundNBT tag) { - ListNBT pipes = new ListNBT(); + public CompoundTag save(CompoundTag tag) { + ListTag pipes = new ListTag(); this.pipes.values().forEach(p -> { - CompoundNBT pipeTag = new CompoundNBT(); + CompoundTag pipeTag = new CompoundTag(); pipeTag.putString("id", p.getId().toString()); pipes.add(p.writeToNbt(pipeTag)); }); tag.put("pipes", pipes); - ListNBT networks = new ListNBT(); + ListTag networks = new ListTag(); this.networks.values().forEach(n -> { - CompoundNBT networkTag = new CompoundNBT(); + CompoundTag networkTag = new CompoundTag(); networkTag.putString("type", n.getType().toString()); networks.add(n.writeToNbt(networkTag)); }); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/NetworkRegistry.java b/src/main/java/com/refinedmods/refinedpipes/network/NetworkRegistry.java index 777c7d6..2970531 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/NetworkRegistry.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/NetworkRegistry.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.network; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -9,10 +9,8 @@ import java.util.Map; public class NetworkRegistry { - private static final Logger LOGGER = LogManager.getLogger(NetworkRegistry.class); - public static final NetworkRegistry INSTANCE = new NetworkRegistry(); - + private static final Logger LOGGER = LogManager.getLogger(NetworkRegistry.class); private final Map factories = new HashMap<>(); private NetworkRegistry() { diff --git a/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetwork.java b/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetwork.java index dee229c..0934340 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetwork.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetwork.java @@ -6,10 +6,10 @@ import com.refinedmods.refinedpipes.network.pipe.DestinationType; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipe; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeType; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; @@ -28,8 +28,8 @@ public EnergyNetwork(BlockPos originPos, String id, EnergyPipeType pipeType) { } @Override - public NetworkGraphScannerResult scanGraph(World world, BlockPos pos) { - NetworkGraphScannerResult result = super.scanGraph(world, pos); + public NetworkGraphScannerResult scanGraph(Level level, BlockPos pos) { + NetworkGraphScannerResult result = super.scanGraph(level, pos); energyStorage.setCapacityAndMaxExtract( result.getFoundPipes() @@ -51,8 +51,8 @@ public EnergyStorage getEnergyStorage() { } @Override - public void update(World world) { - super.update(world); + public void update(Level level) { + super.update(level); List destinations = graph.getDestinations(DestinationType.ENERGY_STORAGE); @@ -62,12 +62,12 @@ public void update(World world) { } for (Destination destination : destinations) { - TileEntity tile = destination.getConnectedPipe().getWorld().getTileEntity(destination.getReceiver()); - if (tile == null) { + BlockEntity blockEntity = destination.getConnectedPipe().getLevel().getBlockEntity(destination.getReceiver()); + if (blockEntity == null) { continue; } - IEnergyStorage handler = tile.getCapability(CapabilityEnergy.ENERGY, destination.getIncomingDirection().getOpposite()).orElse(null); + IEnergyStorage handler = blockEntity.getCapability(CapabilityEnergy.ENERGY, destination.getIncomingDirection().getOpposite()).orElse(null); if (handler == null) { continue; } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetworkFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetworkFactory.java index 93f2adf..c42a5f8 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetworkFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/energy/EnergyNetworkFactory.java @@ -4,8 +4,8 @@ import com.refinedmods.refinedpipes.network.NetworkFactory; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeType; import com.refinedmods.refinedpipes.util.StringUtil; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -26,8 +26,8 @@ public Network create(BlockPos pos) { } @Override - public Network create(CompoundNBT tag) { - EnergyNetwork network = new EnergyNetwork(BlockPos.fromLong(tag.getLong("origin")), tag.getString("id"), pipeType); + public Network create(CompoundTag tag) { + EnergyNetwork network = new EnergyNetwork(BlockPos.of(tag.getLong("origin")), tag.getString("id"), pipeType); LOGGER.debug("Deserialized energy network {} of type {}", network.getId(), network.getType().toString()); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetwork.java b/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetwork.java index d548d6f..6f4a1d8 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetwork.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetwork.java @@ -6,11 +6,11 @@ import com.refinedmods.refinedpipes.network.pipe.DestinationType; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipe; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipeType; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; @@ -35,8 +35,8 @@ public FluidTank getFluidTank() { } @Override - public NetworkGraphScannerResult scanGraph(World world, BlockPos pos) { - NetworkGraphScannerResult result = super.scanGraph(world, pos); + public NetworkGraphScannerResult scanGraph(Level level, BlockPos pos) { + NetworkGraphScannerResult result = super.scanGraph(level, pos); fluidTank.setCapacity( result.getFoundPipes() @@ -54,8 +54,8 @@ public NetworkGraphScannerResult scanGraph(World world, BlockPos pos) { } @Override - public void update(World world) { - super.update(world); + public void update(Level level) { + super.update(level); List destinations = graph.getDestinations(DestinationType.FLUID_HANDLER); @@ -64,12 +64,12 @@ public void update(World world) { } for (Destination destination : destinations) { - TileEntity tile = destination.getConnectedPipe().getWorld().getTileEntity(destination.getReceiver()); - if (tile == null) { + BlockEntity blockEntity = destination.getConnectedPipe().getLevel().getBlockEntity(destination.getReceiver()); + if (blockEntity == null) { continue; } - IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, destination.getIncomingDirection().getOpposite()).orElse(null); + IFluidHandler handler = blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, destination.getIncomingDirection().getOpposite()).orElse(null); if (handler == null) { continue; } @@ -107,8 +107,8 @@ public ResourceLocation getType() { } @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { - tag.put("tank", fluidTank.writeToNBT(new CompoundNBT())); + public CompoundTag writeToNbt(CompoundTag tag) { + tag.put("tank", fluidTank.writeToNBT(new CompoundTag())); return super.writeToNbt(tag); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetworkFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetworkFactory.java index 322e581..54e1eb5 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetworkFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/fluid/FluidNetworkFactory.java @@ -4,8 +4,8 @@ import com.refinedmods.refinedpipes.network.NetworkFactory; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipeType; import com.refinedmods.refinedpipes.util.StringUtil; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -26,8 +26,8 @@ public Network create(BlockPos pos) { } @Override - public Network create(CompoundNBT tag) { - FluidNetwork network = new FluidNetwork(BlockPos.fromLong(tag.getLong("origin")), tag.getString("id"), pipeType); + public Network create(CompoundTag tag) { + FluidNetwork network = new FluidNetwork(BlockPos.of(tag.getLong("origin")), tag.getString("id"), pipeType); if (tag.contains("tank")) { network.getFluidTank().readFromNBT(tag.getCompound("tank")); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraph.java b/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraph.java index 1024085..a2c208f 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraph.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraph.java @@ -4,8 +4,8 @@ import com.refinedmods.refinedpipes.network.pipe.Destination; import com.refinedmods.refinedpipes.network.pipe.DestinationType; import com.refinedmods.refinedpipes.network.pipe.Pipe; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import java.util.*; @@ -19,7 +19,7 @@ public NetworkGraph(Network network) { this.network = network; } - public NetworkGraphScannerResult scan(World originWorld, BlockPos originPos) { + public NetworkGraphScannerResult scan(Level originWorld, BlockPos originPos) { NetworkGraphScanner scanner = new NetworkGraphScanner(pipes, network.getType()); NetworkGraphScannerResult result = scanner.scanAt(originWorld, originPos); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScanner.java b/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScanner.java index 27dd4b0..ea36475 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScanner.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScanner.java @@ -5,11 +5,11 @@ import com.refinedmods.refinedpipes.network.pipe.DestinationType; import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeEnergyStorage; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.items.CapabilityItemHandler; @@ -33,8 +33,8 @@ public NetworkGraphScanner(Set currentPipes, ResourceLocation requiredNetw this.requiredNetworkType = requiredNetworkType; } - public NetworkGraphScannerResult scanAt(World world, BlockPos pos) { - addRequest(new NetworkGraphScannerRequest(world, pos, null, null)); + public NetworkGraphScannerResult scanAt(Level level, BlockPos pos) { + addRequest(new NetworkGraphScannerRequest(level, pos, null, null)); NetworkGraphScannerRequest request; while ((request = requests.poll()) != null) { @@ -51,7 +51,7 @@ public NetworkGraphScannerResult scanAt(World world, BlockPos pos) { } private void singleScanAt(NetworkGraphScannerRequest request) { - Pipe pipe = NetworkManager.get(request.getWorld()).getPipe(request.getPos()); + Pipe pipe = NetworkManager.get(request.getLevel()).getPipe(request.getPos()); if (pipe != null) { if (!requiredNetworkType.equals(pipe.getNetworkType())) { @@ -69,32 +69,32 @@ private void singleScanAt(NetworkGraphScannerRequest request) { for (Direction dir : Direction.values()) { addRequest(new NetworkGraphScannerRequest( - request.getWorld(), - request.getPos().offset(dir), + request.getLevel(), + request.getPos().relative(dir), dir, request )); } } - } else if (request.getParent() != null) { // This can NOT be called on pipe positions! (causes problems with tiles getting invalidated/validates when it shouldn't) + } else if (request.getParent() != null) { // This can NOT be called on pipe positions! (causes problems with block entities getting invalidated/validates when it shouldn't) // We can NOT have the TE capability checks always run regardless of whether there was a pipe or not. // Otherwise we have this loop: pipe gets placed -> network gets scanned -> TEs get checked -> it might check the TE we just placed // -> the newly created TE can be created in immediate mode -> TE#validate is called again -> TE#remove is called again! - Pipe connectedPipe = NetworkManager.get(request.getWorld()).getPipe(request.getParent().getPos()); + Pipe connectedPipe = NetworkManager.get(request.getLevel()).getPipe(request.getParent().getPos()); // If this destination is connected to a pipe with an attachment, then this is not a valid destination. if (!connectedPipe.getAttachmentManager().hasAttachment(request.getDirection())) { - TileEntity tile = request.getWorld().getTileEntity(request.getPos()); + BlockEntity blockEntity = request.getLevel().getBlockEntity(request.getPos()); - if (tile != null) { - tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, request.getDirection().getOpposite()) + if (blockEntity != null) { + blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, request.getDirection().getOpposite()) .ifPresent(itemHandler -> destinations.add(new Destination(DestinationType.ITEM_HANDLER, request.getPos(), request.getDirection(), connectedPipe))); - tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, request.getDirection().getOpposite()) + blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, request.getDirection().getOpposite()) .ifPresent(fluidHandler -> destinations.add(new Destination(DestinationType.FLUID_HANDLER, request.getPos(), request.getDirection(), connectedPipe))); - tile.getCapability(CapabilityEnergy.ENERGY, request.getDirection().getOpposite()) + blockEntity.getCapability(CapabilityEnergy.ENERGY, request.getDirection().getOpposite()) .ifPresent(energyStorage -> { if (!(energyStorage instanceof EnergyPipeEnergyStorage)) { destinations.add(new Destination(DestinationType.ENERGY_STORAGE, request.getPos(), request.getDirection(), connectedPipe)); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScannerRequest.java b/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScannerRequest.java index 1c15b60..9c385c2 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScannerRequest.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/graph/NetworkGraphScannerRequest.java @@ -1,13 +1,13 @@ package com.refinedmods.refinedpipes.network.graph; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; import javax.annotation.Nullable; public class NetworkGraphScannerRequest { - private final World world; + private final Level level; private final BlockPos pos; @Nullable private final Direction direction; @@ -15,15 +15,15 @@ public class NetworkGraphScannerRequest { private final NetworkGraphScannerRequest parent; private boolean successful; - public NetworkGraphScannerRequest(World world, BlockPos pos, @Nullable Direction direction, @Nullable NetworkGraphScannerRequest parent) { - this.world = world; + public NetworkGraphScannerRequest(Level level, BlockPos pos, @Nullable Direction direction, @Nullable NetworkGraphScannerRequest parent) { + this.level = level; this.pos = pos; this.direction = direction; this.parent = parent; } - public World getWorld() { - return world; + public Level getLevel() { + return level; } public BlockPos getPos() { @@ -40,11 +40,11 @@ public NetworkGraphScannerRequest getParent() { return parent; } - public void setSuccessful(boolean successful) { - this.successful = successful; - } - public boolean isSuccessful() { return successful; } + + public void setSuccessful(boolean successful) { + this.successful = successful; + } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetwork.java b/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetwork.java index 33ee80d..331dd0a 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetwork.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetwork.java @@ -13,9 +13,9 @@ import com.refinedmods.refinedpipes.routing.Graph; import com.refinedmods.refinedpipes.routing.Node; import com.refinedmods.refinedpipes.routing.NodeIndex; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; import java.util.List; import java.util.Set; @@ -31,8 +31,8 @@ public ItemNetwork(BlockPos originPos, String id) { } @Override - public NetworkGraphScannerResult scanGraph(World world, BlockPos pos) { - NetworkGraphScannerResult result = super.scanGraph(world, pos); + public NetworkGraphScannerResult scanGraph(Level level, BlockPos pos) { + NetworkGraphScannerResult result = super.scanGraph(level, pos); updateRouting(result, graph.getDestinations(DestinationType.ITEM_HANDLER)); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetworkFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetworkFactory.java index e0b46ad..a22b0db 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetworkFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/item/ItemNetworkFactory.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedpipes.network.Network; import com.refinedmods.refinedpipes.network.NetworkFactory; import com.refinedmods.refinedpipes.util.StringUtil; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -19,8 +19,8 @@ public Network create(BlockPos pos) { } @Override - public Network create(CompoundNBT tag) { - ItemNetwork network = new ItemNetwork(BlockPos.fromLong(tag.getLong("origin")), tag.getString("id")); + public Network create(CompoundTag tag) { + ItemNetwork network = new ItemNetwork(BlockPos.of(tag.getLong("origin")), tag.getString("id")); LOGGER.debug("Deserialized item network {}", network.getId()); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCache.java b/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCache.java index ebc39ce..292cbc6 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCache.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCache.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedpipes.network.pipe.Destination; import com.refinedmods.refinedpipes.routing.Path; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; import javax.annotation.Nullable; import java.util.HashMap; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCacheFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCacheFactory.java index d8c3af7..09a488a 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCacheFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/item/routing/DestinationPathCacheFactory.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedpipes.network.pipe.Destination; import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.routing.*; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/item/routing/EdgeFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/item/routing/EdgeFactory.java index 3a49833..86fd7e0 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/item/routing/EdgeFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/item/routing/EdgeFactory.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedpipes.network.graph.NetworkGraphScannerRequest; import com.refinedmods.refinedpipes.routing.Edge; import com.refinedmods.refinedpipes.routing.NodeIndex; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/Destination.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/Destination.java index 81c2cd6..c314585 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/Destination.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/Destination.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedpipes.network.pipe; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import java.util.Objects; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/Pipe.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/Pipe.java index af2370e..287f887 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/Pipe.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/Pipe.java @@ -3,27 +3,25 @@ import com.refinedmods.refinedpipes.network.Network; import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; import com.refinedmods.refinedpipes.network.pipe.attachment.ServerAttachmentManager; -import net.minecraft.block.BlockState; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.Objects; public abstract class Pipe { - private final Logger logger = LogManager.getLogger(getClass()); - - protected final World world; + protected final Level level; protected final BlockPos pos; protected final ServerAttachmentManager attachmentManager = new ServerAttachmentManager(this); - + private final Logger logger = LogManager.getLogger(getClass()); protected Network network; - public Pipe(World world, BlockPos pos) { - this.world = world; + public Pipe(Level level, BlockPos pos) { + this.level = level; this.pos = pos; } @@ -37,8 +35,8 @@ public ServerAttachmentManager getAttachmentManager() { return attachmentManager; } - public World getWorld() { - return world; + public Level getLevel() { + return level; } public BlockPos getPos() { @@ -66,12 +64,12 @@ public void leaveNetwork() { } public void sendBlockUpdate() { - BlockState state = world.getBlockState(pos); - world.notifyBlockUpdate(pos, state, state, 1 | 2); + BlockState state = level.getBlockState(pos); + level.sendBlockUpdated(pos, state, state, 1 | 2); } - public CompoundNBT writeToNbt(CompoundNBT tag) { - tag.putLong("pos", pos.toLong()); + public CompoundTag writeToNbt(CompoundTag tag) { + tag.putLong("pos", pos.asLong()); attachmentManager.writeToNbt(tag); @@ -87,12 +85,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pipe pipe = (Pipe) o; - return world.equals(pipe.world) && + return level.equals(pipe.level) && pos.equals(pipe.pos); } @Override public int hashCode() { - return Objects.hash(world, pos); + return Objects.hash(level, pos); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeFactory.java index af30e74..b1fc132 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeFactory.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedpipes.network.pipe; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.world.World; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.Level; public interface PipeFactory { - Pipe createFromNbt(World world, CompoundNBT tag); + Pipe createFromNbt(Level level, CompoundTag tag); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeRegistry.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeRegistry.java index 1e30809..0bcbae8 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeRegistry.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/PipeRegistry.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.network.pipe; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; import javax.annotation.Nullable; import java.util.HashMap; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/Attachment.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/Attachment.java index 5392216..a8a8654 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/Attachment.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/Attachment.java @@ -1,11 +1,11 @@ package com.refinedmods.refinedpipes.network.pipe.attachment; import com.refinedmods.refinedpipes.network.pipe.Pipe; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; public abstract class Attachment { protected final Pipe pipe; @@ -24,7 +24,7 @@ public Pipe getPipe() { return pipe; } - public CompoundNBT writeToNbt(CompoundNBT tag) { + public CompoundTag writeToNbt(CompoundTag tag) { tag.putInt("dir", direction.ordinal()); return tag; @@ -36,6 +36,6 @@ public CompoundNBT writeToNbt(CompoundNBT tag) { public abstract ItemStack getDrop(); - public void openContainer(ServerPlayerEntity player) { + public void openContainer(ServerPlayer player) { } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentFactory.java index ed58163..438d65c 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentFactory.java @@ -1,16 +1,16 @@ package com.refinedmods.refinedpipes.network.pipe.attachment; import com.refinedmods.refinedpipes.network.pipe.Pipe; -import net.minecraft.block.Block; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; import java.util.List; public interface AttachmentFactory { - Attachment createFromNbt(Pipe pipe, CompoundNBT tag); + Attachment createFromNbt(Pipe pipe, CompoundTag tag); Attachment create(Pipe pipe, Direction dir); @@ -20,7 +20,7 @@ public interface AttachmentFactory { ResourceLocation getModelLocation(); - void addInformation(List tooltip); + void addInformation(List tooltip); boolean canPlaceOnPipe(Block pipe); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentManager.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentManager.java index b1bd53b..f356f8b 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentManager.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentManager.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes.network.pipe.attachment; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -14,7 +14,7 @@ public interface AttachmentManager { boolean hasAttachment(Direction dir); - void openAttachmentContainer(Direction dir, ServerPlayerEntity player); + void openAttachmentContainer(Direction dir, ServerPlayer player); @Nonnull ItemStack getPickBlock(Direction dir); @@ -22,7 +22,7 @@ public interface AttachmentManager { @Nullable Attachment getAttachment(Direction dir); - void writeUpdate(CompoundNBT tag); + void writeUpdate(CompoundTag tag); - void readUpdate(CompoundNBT tag); + void readUpdate(@Nullable CompoundTag tag); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentRegistry.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentRegistry.java index 0e0204f..3ce9b0b 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentRegistry.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/AttachmentRegistry.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.network.pipe.attachment; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; import javax.annotation.Nullable; import java.util.Collection; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ClientAttachmentManager.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ClientAttachmentManager.java index 952a7e1..473712e 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ClientAttachmentManager.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ClientAttachmentManager.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes.network.pipe.attachment; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -26,7 +26,7 @@ public boolean hasAttachment(Direction dir) { } @Override - public void openAttachmentContainer(Direction dir, ServerPlayerEntity player) { + public void openAttachmentContainer(Direction dir, ServerPlayer player) { throw new RuntimeException("Server-side only"); } @@ -43,20 +43,20 @@ public Attachment getAttachment(Direction dir) { } @Override - public void writeUpdate(CompoundNBT tag) { + public void writeUpdate(CompoundTag tag) { throw new RuntimeException("Server-side only"); } @Override - public void readUpdate(CompoundNBT tag) { + public void readUpdate(@Nullable CompoundTag tag) { this.pickBlocks.clear(); for (Direction dir : Direction.values()) { String attachmentKey = "attch_" + dir.ordinal(); String pickBlockKey = "pb_" + dir.ordinal(); - if (tag.contains(attachmentKey) || tag.contains(pickBlockKey)) { - pickBlocks.put(dir, ItemStack.read(tag.getCompound(pickBlockKey))); + if (tag != null && (tag.contains(attachmentKey) || tag.contains(pickBlockKey))) { + pickBlocks.put(dir, ItemStack.of(tag.getCompound(pickBlockKey))); attachmentState[dir.ordinal()] = new ResourceLocation(tag.getString(attachmentKey)); } else { diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/DummyAttachmentManager.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/DummyAttachmentManager.java index 9b65ca6..7fba2a9 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/DummyAttachmentManager.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/DummyAttachmentManager.java @@ -1,18 +1,17 @@ package com.refinedmods.refinedpipes.network.pipe.attachment; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class DummyAttachmentManager implements AttachmentManager { - private static final ResourceLocation[] STATE = new ResourceLocation[Direction.values().length]; - public static final DummyAttachmentManager INSTANCE = new DummyAttachmentManager(); + private static final ResourceLocation[] STATE = new ResourceLocation[Direction.values().length]; private DummyAttachmentManager() { } @@ -28,7 +27,7 @@ public boolean hasAttachment(Direction dir) { } @Override - public void openAttachmentContainer(Direction dir, ServerPlayerEntity player) { + public void openAttachmentContainer(Direction dir, ServerPlayer player) { } @@ -45,12 +44,12 @@ public Attachment getAttachment(Direction dir) { } @Override - public void writeUpdate(CompoundNBT tag) { + public void writeUpdate(CompoundTag tag) { } @Override - public void readUpdate(CompoundNBT tag) { + public void readUpdate(@Nullable CompoundTag tag) { } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ServerAttachmentManager.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ServerAttachmentManager.java index 2278706..5157063 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ServerAttachmentManager.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/ServerAttachmentManager.java @@ -1,14 +1,13 @@ package com.refinedmods.refinedpipes.network.pipe.attachment; import com.refinedmods.refinedpipes.network.pipe.Pipe; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.INBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.util.Constants; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -36,7 +35,7 @@ public boolean hasAttachment(Direction dir) { } @Override - public void openAttachmentContainer(Direction dir, ServerPlayerEntity player) { + public void openAttachmentContainer(Direction dir, ServerPlayer player) { if (hasAttachment(dir)) { getAttachment(dir).openContainer(player); } @@ -53,14 +52,14 @@ public void removeAttachmentAndScanGraph(Direction dir) { attachmentState[dir.ordinal()] = null; // Re-scan graph, required to rebuild destinations (chests with an attachment connected are no valid destination, refresh that) - pipe.getNetwork().scanGraph(pipe.getWorld(), pipe.getPos()); + pipe.getNetwork().scanGraph(pipe.getLevel(), pipe.getPos()); } public void setAttachmentAndScanGraph(Direction dir, Attachment attachment) { setAttachment(dir, attachment); // Re-scan graph, required to rebuild destinations (chests with an attachment connected are no valid destination, refresh that) - pipe.getNetwork().scanGraph(pipe.getWorld(), pipe.getPos()); + pipe.getNetwork().scanGraph(pipe.getLevel(), pipe.getPos()); } private void setAttachment(Direction dir, Attachment attachment) { @@ -78,10 +77,10 @@ public Collection getAttachments() { return attachments.values(); } - public CompoundNBT writeToNbt(CompoundNBT tag) { - ListNBT attch = new ListNBT(); + public CompoundTag writeToNbt(CompoundTag tag) { + ListTag attch = new ListTag(); getAttachments().forEach(a -> { - CompoundNBT attchTag = new CompoundNBT(); + CompoundTag attchTag = new CompoundTag(); attchTag.putString("typ", a.getId().toString()); attch.add(a.writeToNbt(attchTag)); }); @@ -89,10 +88,10 @@ public CompoundNBT writeToNbt(CompoundNBT tag) { return tag; } - public void readFromNbt(CompoundNBT tag) { - ListNBT attch = tag.getList("attch", Constants.NBT.TAG_COMPOUND); - for (INBT item : attch) { - CompoundNBT attchTag = (CompoundNBT) item; + public void readFromNbt(CompoundTag tag) { + ListTag attch = tag.getList("attch", Tag.TAG_COMPOUND); + for (Tag item : attch) { + CompoundTag attchTag = (CompoundTag) item; AttachmentFactory factory = AttachmentRegistry.INSTANCE.getFactory(new ResourceLocation(attchTag.getString("typ"))); if (factory != null) { @@ -110,17 +109,17 @@ public ResourceLocation[] getState() { } @Override - public void writeUpdate(CompoundNBT tag) { + public void writeUpdate(CompoundTag tag) { for (Direction dir : Direction.values()) { if (hasAttachment(dir)) { tag.putString("attch_" + dir.ordinal(), getAttachment(dir).getId().toString()); - tag.put("pb_" + dir.ordinal(), getAttachment(dir).getDrop().write(new CompoundNBT())); + tag.put("pb_" + dir.ordinal(), getAttachment(dir).getDrop().save(new CompoundTag())); } } } @Override - public void readUpdate(CompoundNBT tag) { + public void readUpdate(@Nullable CompoundTag tag) { throw new RuntimeException("Client-side only"); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/BlacklistWhitelist.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/BlacklistWhitelist.java index 51d836a..35d0efe 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/BlacklistWhitelist.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/BlacklistWhitelist.java @@ -4,6 +4,16 @@ public enum BlacklistWhitelist { BLACKLIST, WHITELIST; + public static BlacklistWhitelist get(byte b) { + BlacklistWhitelist[] v = values(); + + if (b < 0 || b >= v.length) { + return BLACKLIST; + } + + return v[b]; + } + public BlacklistWhitelist next() { switch (this) { case BLACKLIST: @@ -14,14 +24,4 @@ public BlacklistWhitelist next() { return BLACKLIST; } } - - public static BlacklistWhitelist get(byte b) { - BlacklistWhitelist[] v = values(); - - if (b < 0 || b >= v.length) { - return BLACKLIST; - } - - return v[b]; - } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachment.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachment.java index f13de88..9d2c8cd 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachment.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachment.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.network.pipe.attachment.extractor; -import com.refinedmods.refinedpipes.container.provider.ExtractorAttachmentContainerProvider; +import com.refinedmods.refinedpipes.container.provider.ExtractorAttachmentMenuProvider; import com.refinedmods.refinedpipes.inventory.fluid.FluidInventory; import com.refinedmods.refinedpipes.network.Network; import com.refinedmods.refinedpipes.network.NetworkManager; @@ -15,13 +15,13 @@ import com.refinedmods.refinedpipes.network.pipe.transport.callback.ItemInsertTransportCallback; import com.refinedmods.refinedpipes.network.pipe.transport.callback.ItemPipeGoneTransportCallback; import com.refinedmods.refinedpipes.routing.Path; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; @@ -35,10 +35,8 @@ import javax.annotation.Nullable; public class ExtractorAttachment extends Attachment { - private static final Logger LOGGER = LogManager.getLogger(ExtractorAttachment.class); - public static final int MAX_FILTER_SLOTS = 15; - + private static final Logger LOGGER = LogManager.getLogger(ExtractorAttachment.class); private final ExtractorAttachmentType type; private final ItemStackHandler itemFilter; private final FluidInventory fluidFilter; @@ -61,6 +59,32 @@ public ExtractorAttachment(Pipe pipe, Direction direction, ExtractorAttachmentTy this.fluidFilter = createFluidFilterInventory(this); } + public static ItemStackHandler createItemFilterInventory(@Nullable ExtractorAttachment attachment) { + return new ItemStackHandler(MAX_FILTER_SLOTS) { + @Override + protected void onContentsChanged(int slot) { + super.onContentsChanged(slot); + + if (attachment != null) { + NetworkManager.get(attachment.pipe.getLevel()).setDirty(); + } + } + }; + } + + public static FluidInventory createFluidFilterInventory(@Nullable ExtractorAttachment attachment) { + return new FluidInventory(MAX_FILTER_SLOTS) { + @Override + protected void onContentsChanged() { + super.onContentsChanged(); + + if (attachment != null) { + NetworkManager.get(attachment.pipe.getLevel()).setDirty(); + } + } + }; + } + public boolean isFluidMode() { return pipe.getNetwork() instanceof FluidNetwork; } @@ -80,22 +104,22 @@ public void update() { return; } - if (!redstoneMode.isEnabled(pipe.getWorld(), pipe.getPos())) { + if (!redstoneMode.isEnabled(pipe.getLevel(), pipe.getPos())) { return; } - BlockPos destinationPos = pipe.getPos().offset(getDirection()); + BlockPos destinationPos = pipe.getPos().relative(getDirection()); - TileEntity tile = pipe.getWorld().getTileEntity(destinationPos); - if (tile == null) { + BlockEntity blockEntity = pipe.getLevel().getBlockEntity(destinationPos); + if (blockEntity == null) { return; } if (network instanceof ItemNetwork) { - tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getDirection().getOpposite()) + blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getDirection().getOpposite()) .ifPresent(itemHandler -> update((ItemNetwork) network, destinationPos, itemHandler)); } else if (network instanceof FluidNetwork) { - tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, getDirection().getOpposite()) + blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, getDirection().getOpposite()) .ifPresent(fluidHandler -> update((FluidNetwork) network, fluidHandler)); } } @@ -125,7 +149,7 @@ private void update(ItemNetwork network, BlockPos sourcePos, IItemHandler source return; } - BlockPos fromPos = pipe.getPos().offset(getDirection()); + BlockPos fromPos = pipe.getPos().relative(getDirection()); ((ItemPipe) pipe).addTransport(new ItemTransport( extracted.copy(), @@ -187,7 +211,7 @@ private void update(FluidNetwork network, IFluidHandler source) { network.getFluidTank().fill(drained, IFluidHandler.FluidAction.EXECUTE); - NetworkManager.get(pipe.getWorld()).markDirty(); + NetworkManager.get(pipe.getLevel()).setDirty(); } private boolean acceptsItem(ItemStack stack) { @@ -195,9 +219,9 @@ private boolean acceptsItem(ItemStack stack) { for (int i = 0; i < itemFilter.getSlots(); ++i) { ItemStack filtered = itemFilter.getStackInSlot(i); - boolean equals = filtered.isItemEqual(stack); + boolean equals = filtered.sameItem(stack); if (exactMode) { - equals = equals && ItemStack.areItemStackTagsEqual(filtered, stack); + equals = equals && ItemStack.tagMatches(filtered, stack); } if (equals) { @@ -210,9 +234,9 @@ private boolean acceptsItem(ItemStack stack) { for (int i = 0; i < itemFilter.getSlots(); ++i) { ItemStack filtered = itemFilter.getStackInSlot(i); - boolean equals = filtered.isItemEqual(stack); + boolean equals = filtered.sameItem(stack); if (exactMode) { - equals = equals && ItemStack.areItemStackTagsEqual(filtered, stack); + equals = equals && ItemStack.tagMatches(filtered, stack); } if (equals) { @@ -263,10 +287,10 @@ private boolean acceptsFluid(FluidStack stack) { } @Override - public void openContainer(ServerPlayerEntity player) { + public void openContainer(ServerPlayer player) { super.openContainer(player); - ExtractorAttachmentContainerProvider.open(pipe, this, player); + ExtractorAttachmentMenuProvider.open(pipe, this, player); } @Override @@ -280,7 +304,7 @@ public ItemStack getDrop() { } @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { + public CompoundTag writeToNbt(CompoundTag tag) { tag.putByte("rm", (byte) redstoneMode.ordinal()); tag.put("itemfilter", itemFilter.serializeNBT()); tag.putByte("bw", (byte) blacklistWhitelist.ordinal()); @@ -317,6 +341,10 @@ public void setRedstoneMode(RedstoneMode redstoneMode) { this.redstoneMode = redstoneMode; } + public BlacklistWhitelist getBlacklistWhitelist() { + return blacklistWhitelist; + } + public void setBlacklistWhitelist(BlacklistWhitelist blacklistWhitelist) { if (!type.getCanSetWhitelistBlacklist()) { return; @@ -325,8 +353,8 @@ public void setBlacklistWhitelist(BlacklistWhitelist blacklistWhitelist) { this.blacklistWhitelist = blacklistWhitelist; } - public BlacklistWhitelist getBlacklistWhitelist() { - return blacklistWhitelist; + public RoutingMode getRoutingMode() { + return routingMode; } public void setRoutingMode(RoutingMode routingMode) { @@ -337,8 +365,8 @@ public void setRoutingMode(RoutingMode routingMode) { this.routingMode = routingMode; } - public RoutingMode getRoutingMode() { - return routingMode; + public int getStackSize() { + return stackSize; } public void setStackSize(int stackSize) { @@ -353,14 +381,14 @@ public void setStackSize(int stackSize) { this.stackSize = stackSize; } - public int getStackSize() { - return stackSize; - } - public void setRoundRobinIndex(int roundRobinIndex) { itemDestinationFinder.setRoundRobinIndex(roundRobinIndex); } + public boolean isExactMode() { + return exactMode; + } + public void setExactMode(boolean exactMode) { if (!type.getCanSetExactMode()) { return; @@ -368,34 +396,4 @@ public void setExactMode(boolean exactMode) { this.exactMode = exactMode; } - - public boolean isExactMode() { - return exactMode; - } - - public static ItemStackHandler createItemFilterInventory(@Nullable ExtractorAttachment attachment) { - return new ItemStackHandler(MAX_FILTER_SLOTS) { - @Override - protected void onContentsChanged(int slot) { - super.onContentsChanged(slot); - - if (attachment != null) { - NetworkManager.get(attachment.pipe.getWorld()).markDirty(); - } - } - }; - } - - public static FluidInventory createFluidFilterInventory(@Nullable ExtractorAttachment attachment) { - return new FluidInventory(MAX_FILTER_SLOTS) { - @Override - protected void onContentsChanged() { - super.onContentsChanged(); - - if (attachment != null) { - NetworkManager.get(attachment.pipe.getWorld()).markDirty(); - } - } - }; - } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentFactory.java index 5e4827a..de83745 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentFactory.java @@ -7,14 +7,14 @@ import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentFactory; import com.refinedmods.refinedpipes.util.DirectionUtil; import com.refinedmods.refinedpipes.util.StringUtil; -import net.minecraft.block.Block; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.ChatFormatting; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; import java.util.List; @@ -26,7 +26,7 @@ public ExtractorAttachmentFactory(ExtractorAttachmentType type) { } @Override - public Attachment createFromNbt(Pipe pipe, CompoundNBT tag) { + public Attachment createFromNbt(Pipe pipe, CompoundTag tag) { Direction dir = DirectionUtil.safeGet((byte) tag.getInt("dir")); ExtractorAttachment attachment = new ExtractorAttachment(pipe, dir, type); @@ -87,42 +87,42 @@ public ResourceLocation getModelLocation() { } @Override - public void addInformation(List tooltip) { - tooltip.add(new TranslationTextComponent("misc.refinedpipes.tier", new TranslationTextComponent("enchantment.level." + type.getTier())).mergeStyle(TextFormatting.YELLOW)); + public void addInformation(List tooltip) { + tooltip.add(new TranslatableComponent("misc.refinedpipes.tier", new TranslatableComponent("enchantment.level." + type.getTier())).withStyle(ChatFormatting.YELLOW)); - ITextComponent itemsToExtract = new StringTextComponent(StringUtil.formatNumber(type.getItemsToExtract()) + " ") - .append(new TranslationTextComponent("misc.refinedpipes.item" + (type.getItemsToExtract() == 1 ? "" : "s"))) - .mergeStyle(TextFormatting.WHITE); + Component itemsToExtract = new TextComponent(StringUtil.formatNumber(type.getItemsToExtract()) + " ") + .append(new TranslatableComponent("misc.refinedpipes.item" + (type.getItemsToExtract() == 1 ? "" : "s"))) + .withStyle(ChatFormatting.WHITE); float itemSecondsInterval = type.getItemTickInterval() / 20F; - ITextComponent itemTickInterval = new StringTextComponent(StringUtil.formatNumber(itemSecondsInterval) + " ") - .append(new TranslationTextComponent("misc.refinedpipes.second" + (itemSecondsInterval == 1 ? "" : "s"))) - .mergeStyle(TextFormatting.WHITE); + Component itemTickInterval = new TextComponent(StringUtil.formatNumber(itemSecondsInterval) + " ") + .append(new TranslatableComponent("misc.refinedpipes.second" + (itemSecondsInterval == 1 ? "" : "s"))) + .withStyle(ChatFormatting.WHITE); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.extractor_attachment.item_extraction_rate", itemsToExtract, itemTickInterval - ).mergeStyle(TextFormatting.GRAY)); + ).withStyle(ChatFormatting.GRAY)); - ITextComponent fluidsToExtract = new StringTextComponent(StringUtil.formatNumber(type.getFluidsToExtract()) + " mB") - .mergeStyle(TextFormatting.WHITE); + Component fluidsToExtract = new TextComponent(StringUtil.formatNumber(type.getFluidsToExtract()) + " mB") + .withStyle(ChatFormatting.WHITE); float fluidSecondsInterval = type.getFluidTickInterval() / 20F; - ITextComponent fluidTickInterval = new StringTextComponent(StringUtil.formatNumber(fluidSecondsInterval) + " ") - .append(new TranslationTextComponent("misc.refinedpipes.second" + (fluidSecondsInterval == 1 ? "" : "s"))) - .mergeStyle(TextFormatting.WHITE); + Component fluidTickInterval = new TextComponent(StringUtil.formatNumber(fluidSecondsInterval) + " ") + .append(new TranslatableComponent("misc.refinedpipes.second" + (fluidSecondsInterval == 1 ? "" : "s"))) + .withStyle(ChatFormatting.WHITE); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.extractor_attachment.fluid_extraction_rate", fluidsToExtract, fluidTickInterval - ).mergeStyle(TextFormatting.GRAY)); + ).withStyle(ChatFormatting.GRAY)); - tooltip.add(new TranslationTextComponent( + tooltip.add(new TranslatableComponent( "tooltip.refinedpipes.extractor_attachment.filter_slots", - new StringTextComponent("" + type.getFilterSlots()).mergeStyle(TextFormatting.WHITE) - ).mergeStyle(TextFormatting.GRAY)); + new TextComponent("" + type.getFilterSlots()).withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY)); addAbilityToInformation(tooltip, type.getCanSetRedstoneMode(), "misc.refinedpipes.redstone_mode"); addAbilityToInformation(tooltip, type.getCanSetWhitelistBlacklist(), "misc.refinedpipes.mode"); @@ -130,10 +130,10 @@ public void addInformation(List tooltip) { addAbilityToInformation(tooltip, type.getCanSetExactMode(), "misc.refinedpipes.exact_mode"); } - private void addAbilityToInformation(List tooltip, boolean possible, String key) { + private void addAbilityToInformation(List tooltip, boolean possible, String key) { tooltip.add( - new StringTextComponent(possible ? "âś“ " : "❌ ").append(new TranslationTextComponent(key)) - .mergeStyle(possible ? TextFormatting.GREEN : TextFormatting.RED) + new TextComponent(possible ? "âś“ " : "❌ ").append(new TranslatableComponent(key)) + .withStyle(possible ? ChatFormatting.GREEN : ChatFormatting.RED) ); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java index 84fa7ad..e5dd7ed 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedpipes.RefinedPipes; import com.refinedmods.refinedpipes.RefinedPipesItems; import com.refinedmods.refinedpipes.config.ServerConfig; -import net.minecraft.item.Item; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; public enum ExtractorAttachmentType { BASIC(1), @@ -19,6 +19,16 @@ public enum ExtractorAttachmentType { this.tier = tier; } + public static ExtractorAttachmentType get(byte b) { + ExtractorAttachmentType[] v = values(); + + if (b < 0 || b >= v.length) { + return BASIC; + } + + return v[b]; + } + public int getTier() { return tier; } @@ -143,14 +153,4 @@ ResourceLocation getModelLocation() { throw new RuntimeException("?"); } } - - public static ExtractorAttachmentType get(byte b) { - ExtractorAttachmentType[] v = values(); - - if (b < 0 || b >= v.length) { - return BASIC; - } - - return v[b]; - } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ItemDestinationFinder.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ItemDestinationFinder.java index c8b1cea..6a0e44c 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ItemDestinationFinder.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/ItemDestinationFinder.java @@ -4,9 +4,9 @@ import com.refinedmods.refinedpipes.network.pipe.Destination; import com.refinedmods.refinedpipes.network.pipe.DestinationType; import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; @@ -36,7 +36,7 @@ public Destination find(RoutingMode routingMode, BlockPos sourcePos, ItemStack e List destinations = new ArrayList<>(network.getDestinations(DestinationType.ITEM_HANDLER)); while (!destinations.isEmpty()) { - int randomIndex = attachment.getPipe().getWorld().getRandom().nextInt(destinations.size()); + int randomIndex = attachment.getPipe().getLevel().getRandom().nextInt(destinations.size()); Destination randomDestination = destinations.get(randomIndex); if (isDestinationApplicable(sourcePos, extracted, randomDestination)) { @@ -80,12 +80,12 @@ public Destination find(RoutingMode routingMode, BlockPos sourcePos, ItemStack e } private boolean isDestinationApplicable(BlockPos sourcePos, ItemStack extracted, Destination destination) { - TileEntity tile = destination.getConnectedPipe().getWorld().getTileEntity(destination.getReceiver()); - if (tile == null) { + BlockEntity blockEntity = destination.getConnectedPipe().getLevel().getBlockEntity(destination.getReceiver()); + if (blockEntity == null) { return false; } - IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, destination.getIncomingDirection().getOpposite()).orElse(null); + IItemHandler handler = blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, destination.getIncomingDirection().getOpposite()).orElse(null); if (handler == null) { return false; } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/RedstoneMode.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/RedstoneMode.java index 0294c6e..efc4c05 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/RedstoneMode.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/attachment/extractor/RedstoneMode.java @@ -1,26 +1,13 @@ package com.refinedmods.refinedpipes.network.pipe.attachment.extractor; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; public enum RedstoneMode { IGNORED, HIGH, LOW; - public boolean isEnabled(World world, BlockPos pos) { - switch (this) { - case IGNORED: - return true; - case HIGH: - return world.isBlockPowered(pos); - case LOW: - return !world.isBlockPowered(pos); - default: - return false; - } - } - public static RedstoneMode get(byte b) { RedstoneMode[] m = values(); @@ -31,6 +18,19 @@ public static RedstoneMode get(byte b) { return m[b]; } + public boolean isEnabled(Level level, BlockPos pos) { + switch (this) { + case IGNORED: + return true; + case HIGH: + return level.hasNeighborSignal(pos); + case LOW: + return !level.hasNeighborSignal(pos); + default: + return false; + } + } + public RedstoneMode next() { switch (this) { case IGNORED: diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipe.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipe.java index 5963609..0a1c846 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipe.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipe.java @@ -4,10 +4,10 @@ import com.refinedmods.refinedpipes.network.Network; import com.refinedmods.refinedpipes.network.energy.EnergyNetwork; import com.refinedmods.refinedpipes.network.pipe.Pipe; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; import net.minecraftforge.common.util.LazyOptional; public class EnergyPipe extends Pipe { @@ -17,8 +17,8 @@ public class EnergyPipe extends Pipe { private LazyOptional energyStorage = LazyOptional.empty(); - public EnergyPipe(World world, BlockPos pos, EnergyPipeType type) { - super(world, pos); + public EnergyPipe(Level level, BlockPos pos, EnergyPipeType type) { + super(level, pos); this.type = type; } @@ -45,7 +45,7 @@ public EnergyPipeType getType() { } @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { + public CompoundTag writeToNbt(CompoundTag tag) { tag = super.writeToNbt(tag); tag.putInt("type", type.ordinal()); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeFactory.java index 527f8ea..b4e255a 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeFactory.java @@ -2,18 +2,18 @@ import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.PipeFactory; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.Level; public class EnergyPipeFactory implements PipeFactory { @Override - public Pipe createFromNbt(World world, CompoundNBT tag) { - BlockPos pos = BlockPos.fromLong(tag.getLong("pos")); + public Pipe createFromNbt(Level level, CompoundTag tag) { + BlockPos pos = BlockPos.of(tag.getLong("pos")); EnergyPipeType pipeType = EnergyPipeType.values()[tag.getInt("type")]; - EnergyPipe pipe = new EnergyPipe(world, pos, pipeType); + EnergyPipe pipe = new EnergyPipe(level, pos, pipeType); pipe.getAttachmentManager().readFromNbt(tag); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeType.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeType.java index 70af153..c38b778 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeType.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/energy/EnergyPipeType.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes.network.pipe.energy; import com.refinedmods.refinedpipes.RefinedPipes; -import com.refinedmods.refinedpipes.RefinedPipesTileEntities; -import com.refinedmods.refinedpipes.tile.EnergyPipeTileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.ResourceLocation; +import com.refinedmods.refinedpipes.RefinedPipesBlockEntities; +import com.refinedmods.refinedpipes.blockentity.EnergyPipeBlockEntity; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.entity.BlockEntityType; public enum EnergyPipeType { BASIC(1), @@ -91,18 +91,18 @@ public ResourceLocation getNetworkType() { } } - public TileEntityType getTileType() { + public BlockEntityType getBlockEntityType() { switch (this) { case BASIC: - return RefinedPipesTileEntities.BASIC_ENERGY_PIPE; + return RefinedPipesBlockEntities.BASIC_ENERGY_PIPE; case IMPROVED: - return RefinedPipesTileEntities.IMPROVED_ENERGY_PIPE; + return RefinedPipesBlockEntities.IMPROVED_ENERGY_PIPE; case ADVANCED: - return RefinedPipesTileEntities.ADVANCED_ENERGY_PIPE; + return RefinedPipesBlockEntities.ADVANCED_ENERGY_PIPE; case ELITE: - return RefinedPipesTileEntities.ELITE_ENERGY_PIPE; + return RefinedPipesBlockEntities.ELITE_ENERGY_PIPE; case ULTIMATE: - return RefinedPipesTileEntities.ULTIMATE_ENERGY_PIPE; + return RefinedPipesBlockEntities.ULTIMATE_ENERGY_PIPE; default: throw new RuntimeException("?"); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipe.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipe.java index a50e0a9..971b3a2 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipe.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipe.java @@ -4,10 +4,10 @@ import com.refinedmods.refinedpipes.message.FluidPipeMessage; import com.refinedmods.refinedpipes.network.fluid.FluidNetwork; import com.refinedmods.refinedpipes.network.pipe.Pipe; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; public class FluidPipe extends Pipe { public static final ResourceLocation ID = new ResourceLocation(RefinedPipes.ID, "fluid"); @@ -15,8 +15,8 @@ public class FluidPipe extends Pipe { private final FluidPipeType type; private float lastFullness = 0; - public FluidPipe(World world, BlockPos pos, FluidPipeType type) { - super(world, pos); + public FluidPipe(Level level, BlockPos pos, FluidPipeType type) { + super(level, pos); this.type = type; } @@ -34,7 +34,7 @@ public void update() { } public void sendFluidPipeUpdate() { - RefinedPipes.NETWORK.sendInArea(world, pos, 32, new FluidPipeMessage(pos, ((FluidNetwork) network).getFluidTank().getFluid(), getFullness())); + RefinedPipes.NETWORK.sendInArea(level, pos, 32, new FluidPipeMessage(pos, ((FluidNetwork) network).getFluidTank().getFluid(), getFullness())); } public float getFullness() { @@ -49,7 +49,7 @@ public FluidPipeType getType() { } @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { + public CompoundTag writeToNbt(CompoundTag tag) { tag = super.writeToNbt(tag); tag.putInt("type", type.ordinal()); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeFactory.java index 7bdd2d1..da7c701 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeFactory.java @@ -2,18 +2,18 @@ import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.PipeFactory; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.Level; public class FluidPipeFactory implements PipeFactory { @Override - public Pipe createFromNbt(World world, CompoundNBT tag) { - BlockPos pos = BlockPos.fromLong(tag.getLong("pos")); + public Pipe createFromNbt(Level level, CompoundTag tag) { + BlockPos pos = BlockPos.of(tag.getLong("pos")); FluidPipeType pipeType = FluidPipeType.values()[tag.getInt("type")]; - FluidPipe pipe = new FluidPipe(world, pos, pipeType); + FluidPipe pipe = new FluidPipe(level, pos, pipeType); pipe.getAttachmentManager().readFromNbt(tag); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeType.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeType.java index 30398fa..4b9cbc7 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeType.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/fluid/FluidPipeType.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes.network.pipe.fluid; import com.refinedmods.refinedpipes.RefinedPipes; -import com.refinedmods.refinedpipes.RefinedPipesTileEntities; -import com.refinedmods.refinedpipes.tile.FluidPipeTileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.ResourceLocation; +import com.refinedmods.refinedpipes.RefinedPipesBlockEntities; +import com.refinedmods.refinedpipes.blockentity.FluidPipeBlockEntity; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.entity.BlockEntityType; public enum FluidPipeType { BASIC(1), @@ -23,18 +23,18 @@ public int getTier() { return tier; } - public TileEntityType getTileType() { + public BlockEntityType getBlockEntityType() { switch (this) { case BASIC: - return RefinedPipesTileEntities.BASIC_FLUID_PIPE; + return RefinedPipesBlockEntities.BASIC_FLUID_PIPE; case IMPROVED: - return RefinedPipesTileEntities.IMPROVED_FLUID_PIPE; + return RefinedPipesBlockEntities.IMPROVED_FLUID_PIPE; case ADVANCED: - return RefinedPipesTileEntities.ADVANCED_FLUID_PIPE; + return RefinedPipesBlockEntities.ADVANCED_FLUID_PIPE; case ELITE: - return RefinedPipesTileEntities.ELITE_FLUID_PIPE; + return RefinedPipesBlockEntities.ELITE_FLUID_PIPE; case ULTIMATE: - return RefinedPipesTileEntities.ULTIMATE_FLUID_PIPE; + return RefinedPipesBlockEntities.ULTIMATE_FLUID_PIPE; default: throw new RuntimeException("?"); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipe.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipe.java index 96c97f1..88646b3 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipe.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipe.java @@ -7,11 +7,11 @@ import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.transport.ItemTransport; import com.refinedmods.refinedpipes.network.pipe.transport.ItemTransportProps; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; import java.util.ArrayList; import java.util.List; @@ -24,8 +24,8 @@ public class ItemPipe extends Pipe { private final List transportsToRemove = new ArrayList<>(); private final ItemPipeType type; - public ItemPipe(World world, BlockPos pos, ItemPipeType type) { - super(world, pos); + public ItemPipe(Level level, BlockPos pos, ItemPipeType type) { + super(level, pos); this.type = type; } @@ -37,19 +37,19 @@ public void update() { transports.removeAll(transportsToRemove); if (!transportsToAdd.isEmpty() || !transportsToRemove.isEmpty()) { - NetworkManager.get(world).markDirty(); + NetworkManager.get(level).setDirty(); sendTransportUpdate(); } if (!transports.isEmpty()) { - NetworkManager.get(world).markDirty(); + NetworkManager.get(level).setDirty(); } transportsToAdd.clear(); transportsToRemove.clear(); if (transports.removeIf(t -> t.update(network, this))) { - NetworkManager.get(world).markDirty(); + NetworkManager.get(level).setDirty(); } } @@ -71,18 +71,18 @@ public void sendTransportUpdate() { props.add(transport.createProps(this)); } - RefinedPipes.NETWORK.sendInArea(world, pos, 32, new ItemTransportMessage(pos, props)); + RefinedPipes.NETWORK.sendInArea(level, pos, 32, new ItemTransportMessage(pos, props)); } @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { + public CompoundTag writeToNbt(CompoundTag tag) { tag = super.writeToNbt(tag); tag.putInt("type", type.ordinal()); - ListNBT transports = new ListNBT(); + ListTag transports = new ListTag(); for (ItemTransport transport : this.transports) { - transports.add(transport.writeToNbt(new CompoundNBT())); + transports.add(transport.writeToNbt(new CompoundTag())); } tag.put("transports", transports); diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeFactory.java index e1a3278..07b56b2 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeFactory.java @@ -3,26 +3,26 @@ import com.refinedmods.refinedpipes.network.pipe.Pipe; import com.refinedmods.refinedpipes.network.pipe.PipeFactory; import com.refinedmods.refinedpipes.network.pipe.transport.ItemTransport; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.util.Constants; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.level.Level; public class ItemPipeFactory implements PipeFactory { @Override - public Pipe createFromNbt(World world, CompoundNBT tag) { - BlockPos pos = BlockPos.fromLong(tag.getLong("pos")); + public Pipe createFromNbt(Level level, CompoundTag tag) { + BlockPos pos = BlockPos.of(tag.getLong("pos")); ItemPipeType pipeType = ItemPipeType.values()[tag.getInt("type")]; - ItemPipe pipe = new ItemPipe(world, pos, pipeType); + ItemPipe pipe = new ItemPipe(level, pos, pipeType); pipe.getAttachmentManager().readFromNbt(tag); - ListNBT transports = tag.getList("transports", Constants.NBT.TAG_COMPOUND); + ListTag transports = tag.getList("transports", Tag.TAG_COMPOUND); for (int i = 0; i < transports.size(); ++i) { - CompoundNBT transportTag = transports.getCompound(i); + CompoundTag transportTag = transports.getCompound(i); ItemTransport itemTransport = ItemTransport.of(transportTag); if (itemTransport != null) { diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeType.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeType.java index dae8afb..788d473 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeType.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/item/ItemPipeType.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes.network.pipe.item; import com.refinedmods.refinedpipes.RefinedPipes; -import com.refinedmods.refinedpipes.RefinedPipesTileEntities; -import com.refinedmods.refinedpipes.tile.ItemPipeTileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.ResourceLocation; +import com.refinedmods.refinedpipes.RefinedPipesBlockEntities; +import com.refinedmods.refinedpipes.blockentity.ItemPipeBlockEntity; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.entity.BlockEntityType; public enum ItemPipeType { BASIC(1), @@ -45,14 +45,14 @@ public int getSpeedComparedToBasicTier() { return (int) ((float) mySpeed / (float) speedOfBasicTier * 100F); } - public TileEntityType getTileType() { + public BlockEntityType getBlockEntityType() { switch (this) { case BASIC: - return RefinedPipesTileEntities.BASIC_ITEM_PIPE; + return RefinedPipesBlockEntities.BASIC_ITEM_PIPE; case IMPROVED: - return RefinedPipesTileEntities.IMPROVED_ITEM_PIPE; + return RefinedPipesBlockEntities.IMPROVED_ITEM_PIPE; case ADVANCED: - return RefinedPipesTileEntities.ADVANCED_ITEM_PIPE; + return RefinedPipesBlockEntities.ADVANCED_ITEM_PIPE; default: throw new RuntimeException("?"); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCache.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCache.java index 8aff2dc..650b238 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCache.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCache.java @@ -1,25 +1,26 @@ package com.refinedmods.refinedpipes.network.pipe.shape; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; import com.refinedmods.refinedpipes.item.AttachmentItem; import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentFactory; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; import com.refinedmods.refinedpipes.util.Raytracer; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.IBlockReader; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.EntityCollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; @@ -31,28 +32,28 @@ public class PipeShapeCache { private static final ResourceLocation[] NO_ATTACHMENT_STATE = new ResourceLocation[Direction.values().length]; private final PipeShapeFactory shapeFactory; - private final List attachmentShapes = new ArrayList<>(); + private final List attachmentShapes = new ArrayList<>(); private final Map cache = new HashMap<>(); public PipeShapeCache(PipeShapeFactory shapeFactory) { this.shapeFactory = shapeFactory; - attachmentShapes.add(PipeShapeProps.NORTH_ATTACHMENT_SHAPE.getBoundingBox()); - attachmentShapes.add(PipeShapeProps.EAST_ATTACHMENT_SHAPE.getBoundingBox()); - attachmentShapes.add(PipeShapeProps.SOUTH_ATTACHMENT_SHAPE.getBoundingBox()); - attachmentShapes.add(PipeShapeProps.WEST_ATTACHMENT_SHAPE.getBoundingBox()); - attachmentShapes.add(PipeShapeProps.UP_ATTACHMENT_SHAPE.getBoundingBox()); - attachmentShapes.add(PipeShapeProps.DOWN_ATTACHMENT_SHAPE.getBoundingBox()); + attachmentShapes.add(PipeShapeProps.NORTH_ATTACHMENT_SHAPE.bounds()); + attachmentShapes.add(PipeShapeProps.EAST_ATTACHMENT_SHAPE.bounds()); + attachmentShapes.add(PipeShapeProps.SOUTH_ATTACHMENT_SHAPE.bounds()); + attachmentShapes.add(PipeShapeProps.WEST_ATTACHMENT_SHAPE.bounds()); + attachmentShapes.add(PipeShapeProps.UP_ATTACHMENT_SHAPE.bounds()); + attachmentShapes.add(PipeShapeProps.DOWN_ATTACHMENT_SHAPE.bounds()); } - public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext ctx) { VoxelShape shape = createShapeIfNeeded(state, world, pos); - if (ctx.getEntity() instanceof PlayerEntity) { - Item inHand = ((PlayerEntity) ctx.getEntity()).getHeldItemMainhand().getItem(); + if (ctx instanceof EntityCollisionContext entityCollisionContext && entityCollisionContext.getEntity() instanceof Player player) { + Item inHand = player.getMainHandItem().getItem(); if (inHand instanceof AttachmentItem) { - shape = addFakeAttachmentShape(state.getBlock(), pos, ctx.getEntity(), shape, ((AttachmentItem) inHand).getFactory()); + shape = addFakeAttachmentShape(state.getBlock(), pos, player, shape, ((AttachmentItem) inHand).getFactory()); } } @@ -64,22 +65,22 @@ private VoxelShape addFakeAttachmentShape(Block block, BlockPos pos, Entity enti return shape; } - Pair vec = Raytracer.getVectors(entity); + Pair vec = Raytracer.getVectors(entity); - Raytracer.AdvancedRayTraceResult result = Raytracer.collisionRayTrace(pos, vec.getLeft(), vec.getRight(), attachmentShapes); + Raytracer.AdvancedRayTraceResult result = Raytracer.collisionRayTrace(pos, vec.getLeft(), vec.getRight(), attachmentShapes); if (result != null) { - shape = VoxelShapes.or(shape, VoxelShapes.create(result.bounds)); + shape = Shapes.or(shape, Shapes.create(result.bounds)); } return shape; } - private VoxelShape createShapeIfNeeded(BlockState state, IBlockReader world, BlockPos pos) { + private VoxelShape createShapeIfNeeded(BlockState state, BlockGetter world, BlockPos pos) { ResourceLocation[] attachmentState; - TileEntity tile = world.getTileEntity(pos); - if (tile instanceof PipeTileEntity) { - attachmentState = ((PipeTileEntity) tile).getAttachmentManager().getState(); + BlockEntity blockEntity = world.getBlockEntity(pos); + if (blockEntity instanceof PipeBlockEntity) { + attachmentState = ((PipeBlockEntity) blockEntity).getAttachmentManager().getState(); } else { attachmentState = NO_ATTACHMENT_STATE; } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCacheEntry.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCacheEntry.java index 9cacef1..b3f2d47 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCacheEntry.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeCacheEntry.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedpipes.network.pipe.shape; -import net.minecraft.block.BlockState; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.state.BlockState; import java.util.Arrays; import java.util.Objects; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeFactory.java index 1cad3d0..3792076 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeFactory.java @@ -1,62 +1,62 @@ package com.refinedmods.refinedpipes.network.pipe.shape; import com.refinedmods.refinedpipes.block.PipeBlock; -import net.minecraft.block.BlockState; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; public class PipeShapeFactory { public VoxelShape createShape(BlockState state, ResourceLocation[] attachmentState) { VoxelShape shape = PipeShapeProps.CORE_SHAPE; - if (state.get(PipeBlock.NORTH)) { - shape = VoxelShapes.or(shape, PipeShapeProps.NORTH_EXTENSION_SHAPE); + if (state.getValue(PipeBlock.NORTH)) { + shape = Shapes.or(shape, PipeShapeProps.NORTH_EXTENSION_SHAPE); } - if (state.get(PipeBlock.EAST)) { - shape = VoxelShapes.or(shape, PipeShapeProps.EAST_EXTENSION_SHAPE); + if (state.getValue(PipeBlock.EAST)) { + shape = Shapes.or(shape, PipeShapeProps.EAST_EXTENSION_SHAPE); } - if (state.get(PipeBlock.SOUTH)) { - shape = VoxelShapes.or(shape, PipeShapeProps.SOUTH_EXTENSION_SHAPE); + if (state.getValue(PipeBlock.SOUTH)) { + shape = Shapes.or(shape, PipeShapeProps.SOUTH_EXTENSION_SHAPE); } - if (state.get(PipeBlock.WEST)) { - shape = VoxelShapes.or(shape, PipeShapeProps.WEST_EXTENSION_SHAPE); + if (state.getValue(PipeBlock.WEST)) { + shape = Shapes.or(shape, PipeShapeProps.WEST_EXTENSION_SHAPE); } - if (state.get(PipeBlock.UP)) { - shape = VoxelShapes.or(shape, PipeShapeProps.UP_EXTENSION_SHAPE); + if (state.getValue(PipeBlock.UP)) { + shape = Shapes.or(shape, PipeShapeProps.UP_EXTENSION_SHAPE); } - if (state.get(PipeBlock.DOWN)) { - shape = VoxelShapes.or(shape, PipeShapeProps.DOWN_EXTENSION_SHAPE); + if (state.getValue(PipeBlock.DOWN)) { + shape = Shapes.or(shape, PipeShapeProps.DOWN_EXTENSION_SHAPE); } - if (attachmentState[Direction.NORTH.ordinal()] != null || state.get(PipeBlock.INV_NORTH)) { - shape = VoxelShapes.or(shape, PipeShapeProps.NORTH_ATTACHMENT_SHAPE); + if (attachmentState[Direction.NORTH.ordinal()] != null || state.getValue(PipeBlock.INV_NORTH)) { + shape = Shapes.or(shape, PipeShapeProps.NORTH_ATTACHMENT_SHAPE); } - if (attachmentState[Direction.EAST.ordinal()] != null || state.get(PipeBlock.INV_EAST)) { - shape = VoxelShapes.or(shape, PipeShapeProps.EAST_ATTACHMENT_SHAPE); + if (attachmentState[Direction.EAST.ordinal()] != null || state.getValue(PipeBlock.INV_EAST)) { + shape = Shapes.or(shape, PipeShapeProps.EAST_ATTACHMENT_SHAPE); } - if (attachmentState[Direction.SOUTH.ordinal()] != null || state.get(PipeBlock.INV_SOUTH)) { - shape = VoxelShapes.or(shape, PipeShapeProps.SOUTH_ATTACHMENT_SHAPE); + if (attachmentState[Direction.SOUTH.ordinal()] != null || state.getValue(PipeBlock.INV_SOUTH)) { + shape = Shapes.or(shape, PipeShapeProps.SOUTH_ATTACHMENT_SHAPE); } - if (attachmentState[Direction.WEST.ordinal()] != null || state.get(PipeBlock.INV_WEST)) { - shape = VoxelShapes.or(shape, PipeShapeProps.WEST_ATTACHMENT_SHAPE); + if (attachmentState[Direction.WEST.ordinal()] != null || state.getValue(PipeBlock.INV_WEST)) { + shape = Shapes.or(shape, PipeShapeProps.WEST_ATTACHMENT_SHAPE); } - if (attachmentState[Direction.UP.ordinal()] != null || state.get(PipeBlock.INV_UP)) { - shape = VoxelShapes.or(shape, PipeShapeProps.UP_ATTACHMENT_SHAPE); + if (attachmentState[Direction.UP.ordinal()] != null || state.getValue(PipeBlock.INV_UP)) { + shape = Shapes.or(shape, PipeShapeProps.UP_ATTACHMENT_SHAPE); } - if (attachmentState[Direction.DOWN.ordinal()] != null || state.get(PipeBlock.INV_DOWN)) { - shape = VoxelShapes.or(shape, PipeShapeProps.DOWN_ATTACHMENT_SHAPE); + if (attachmentState[Direction.DOWN.ordinal()] != null || state.getValue(PipeBlock.INV_DOWN)) { + shape = Shapes.or(shape, PipeShapeProps.DOWN_ATTACHMENT_SHAPE); } return shape; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeProps.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeProps.java index b8607b0..e8d2ef2 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeProps.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/shape/PipeShapeProps.java @@ -1,21 +1,21 @@ package com.refinedmods.refinedpipes.network.pipe.shape; -import net.minecraft.block.Block; -import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.phys.shapes.VoxelShape; public class PipeShapeProps { - public static final VoxelShape CORE_SHAPE = Block.makeCuboidShape(4, 4, 4, 12, 12, 12); - public static final VoxelShape NORTH_EXTENSION_SHAPE = Block.makeCuboidShape(4, 4, 0, 12, 12, 4); - public static final VoxelShape EAST_EXTENSION_SHAPE = Block.makeCuboidShape(12, 4, 4, 16, 12, 12); - public static final VoxelShape SOUTH_EXTENSION_SHAPE = Block.makeCuboidShape(4, 4, 12, 12, 12, 16); - public static final VoxelShape WEST_EXTENSION_SHAPE = Block.makeCuboidShape(0, 4, 4, 4, 12, 12); - public static final VoxelShape UP_EXTENSION_SHAPE = Block.makeCuboidShape(4, 12, 4, 12, 16, 12); - public static final VoxelShape DOWN_EXTENSION_SHAPE = Block.makeCuboidShape(4, 0, 4, 12, 4, 12); + public static final VoxelShape CORE_SHAPE = Block.box(4, 4, 4, 12, 12, 12); + public static final VoxelShape NORTH_EXTENSION_SHAPE = Block.box(4, 4, 0, 12, 12, 4); + public static final VoxelShape EAST_EXTENSION_SHAPE = Block.box(12, 4, 4, 16, 12, 12); + public static final VoxelShape SOUTH_EXTENSION_SHAPE = Block.box(4, 4, 12, 12, 12, 16); + public static final VoxelShape WEST_EXTENSION_SHAPE = Block.box(0, 4, 4, 4, 12, 12); + public static final VoxelShape UP_EXTENSION_SHAPE = Block.box(4, 12, 4, 12, 16, 12); + public static final VoxelShape DOWN_EXTENSION_SHAPE = Block.box(4, 0, 4, 12, 4, 12); - public static final VoxelShape NORTH_ATTACHMENT_SHAPE = Block.makeCuboidShape(3, 3, 0, 13, 13, 3); - public static final VoxelShape EAST_ATTACHMENT_SHAPE = Block.makeCuboidShape(13, 3, 3, 16, 13, 13); - public static final VoxelShape SOUTH_ATTACHMENT_SHAPE = Block.makeCuboidShape(3, 3, 13, 13, 13, 16); - public static final VoxelShape WEST_ATTACHMENT_SHAPE = Block.makeCuboidShape(0, 3, 3, 3, 13, 13); - public static final VoxelShape UP_ATTACHMENT_SHAPE = Block.makeCuboidShape(3, 13, 3, 13, 16, 13); - public static final VoxelShape DOWN_ATTACHMENT_SHAPE = Block.makeCuboidShape(3, 0, 3, 13, 3, 13); + public static final VoxelShape NORTH_ATTACHMENT_SHAPE = Block.box(3, 3, 0, 13, 13, 3); + public static final VoxelShape EAST_ATTACHMENT_SHAPE = Block.box(13, 3, 3, 16, 13, 13); + public static final VoxelShape SOUTH_ATTACHMENT_SHAPE = Block.box(3, 3, 13, 13, 13, 16); + public static final VoxelShape WEST_ATTACHMENT_SHAPE = Block.box(0, 3, 3, 3, 13, 13); + public static final VoxelShape UP_ATTACHMENT_SHAPE = Block.box(3, 13, 3, 13, 16, 13); + public static final VoxelShape DOWN_ATTACHMENT_SHAPE = Block.box(3, 0, 3, 13, 3, 13); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransport.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransport.java index 98180dd..502cd5f 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransport.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransport.java @@ -7,16 +7,15 @@ import com.refinedmods.refinedpipes.network.pipe.transport.callback.TransportCallbackFactory; import com.refinedmods.refinedpipes.network.pipe.transport.callback.TransportCallbackFactoryRegistry; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.INBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.nbt.LongNBT; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.util.Constants; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.LongTag; +import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -63,6 +62,106 @@ public ItemTransport(ItemStack value, BlockPos source, BlockPos destination, Deq this.progressInCurrentPipe = progressInCurrentPipe; } + private static Direction getDirection(BlockPos a, BlockPos b) { + if (a.relative(Direction.NORTH).equals(b)) { + return Direction.NORTH; + } + + if (a.relative(Direction.EAST).equals(b)) { + return Direction.EAST; + } + + if (a.relative(Direction.SOUTH).equals(b)) { + return Direction.SOUTH; + } + + if (a.relative(Direction.WEST).equals(b)) { + return Direction.WEST; + } + + if (a.relative(Direction.UP).equals(b)) { + return Direction.UP; + } + + if (a.relative(Direction.DOWN).equals(b)) { + return Direction.DOWN; + } + + return Direction.NORTH; + } + + @Nullable + public static ItemTransport of(CompoundTag tag) { + ItemStack value = ItemStack.of(tag.getCompound("v")); + if (value.isEmpty()) { + LOGGER.warn("Item no longer exists"); + return null; + } + + BlockPos source = BlockPos.of(tag.getLong("src")); + BlockPos destination = BlockPos.of(tag.getLong("dst")); + + ListTag pathTag = tag.getList("pth", Tag.TAG_LONG); + Deque path = new ArrayDeque<>(); + for (Tag pathItem : pathTag) { + path.add(BlockPos.of(((LongTag) pathItem).getAsLong())); + } + + Direction initialDirection = DirectionUtil.safeGet((byte) tag.getInt("initd")); + + ResourceLocation finishedCallbackId = new ResourceLocation(tag.getString("fcid")); + TransportCallbackFactory finishedCallbackFactory = TransportCallbackFactoryRegistry.INSTANCE.getFactory(finishedCallbackId); + if (finishedCallbackFactory == null) { + LOGGER.warn("Finished callback factory " + finishedCallbackId + " no longer exists"); + return null; + } + TransportCallback finishedCallback = finishedCallbackFactory.create(tag.getCompound("fc")); + if (finishedCallback == null) { + LOGGER.warn("Finished callback factory " + finishedCallbackId + " returned null!"); + return null; + } + + ResourceLocation cancelCallbackId = new ResourceLocation(tag.getString("ccid")); + TransportCallbackFactory cancelCallbackFactory = TransportCallbackFactoryRegistry.INSTANCE.getFactory(cancelCallbackId); + if (cancelCallbackFactory == null) { + LOGGER.warn("Cancel callback factory " + cancelCallbackId + " no longer exists"); + return null; + } + TransportCallback cancelCallback = cancelCallbackFactory.create(tag.getCompound("cc")); + if (cancelCallback == null) { + LOGGER.warn("Cancel callback factory " + cancelCallbackId + " returned null!"); + return null; + } + + ResourceLocation pipeGoneCallbackId = new ResourceLocation(tag.getString("pgcid")); + TransportCallbackFactory pipeGoneCallbackFactory = TransportCallbackFactoryRegistry.INSTANCE.getFactory(pipeGoneCallbackId); + if (pipeGoneCallbackFactory == null) { + LOGGER.warn("Pipe gone callback factory " + pipeGoneCallbackId + " no longer exists"); + return null; + } + TransportCallback pipeGoneCallback = pipeGoneCallbackFactory.create(tag.getCompound("pgc")); + if (pipeGoneCallback == null) { + LOGGER.warn("Pipe gone callback factory " + pipeGoneCallbackId + " returned null!"); + return null; + } + + boolean firstPipe = tag.getBoolean("fp"); + int progressInCurrentPipe = tag.getInt("p"); + + return new ItemTransport( + value, + source, + destination, + path, + initialDirection, + finishedCallback, + cancelCallback, + pipeGoneCallback, + firstPipe, + progressInCurrentPipe + ); + } + public ItemStack getValue() { return value; } @@ -77,14 +176,14 @@ public Direction getDirection(ItemPipe currentPipe) { return getDirection(currentPipe.getPos(), nextPipe); } - private boolean onDone(Network network, World world, ItemPipe currentPipe) { - finishedCallback.call(network, world, currentPipe.getPos(), cancelCallback); + private boolean onDone(Network network, Level level, ItemPipe currentPipe) { + finishedCallback.call(network, level, currentPipe.getPos(), cancelCallback); return true; } - private boolean onPipeGone(Network network, World world, BlockPos posWherePipeIsGone) { + private boolean onPipeGone(Network network, Level level, BlockPos posWherePipeIsGone) { LOGGER.warn("Pipe on path is gone"); - pipeGoneCallback.call(network, world, posWherePipeIsGone, cancelCallback); + pipeGoneCallback.call(network, level, posWherePipeIsGone, cancelCallback); return true; } @@ -93,10 +192,10 @@ public boolean update(Network network, ItemPipe currentPipe) { double progress = (double) progressInCurrentPipe / (double) getMaxTicksInPipe(currentPipe); - BlockPos nextPos = currentPipe.getPos().offset(getDirection(currentPipe)); - if (progress > 0.25 && currentPipe.getWorld().isAirBlock(nextPos)) { + BlockPos nextPos = currentPipe.getPos().relative(getDirection(currentPipe)); + if (progress > 0.25 && currentPipe.getLevel().isEmptyBlock(nextPos)) { currentPipe.removeTransport(this); - return onPipeGone(network, currentPipe.getWorld(), nextPos); + return onPipeGone(network, currentPipe.getLevel(), nextPos); } if (progressInCurrentPipe >= getMaxTicksInPipe(currentPipe)) { @@ -105,12 +204,12 @@ public boolean update(Network network, ItemPipe currentPipe) { BlockPos nextPipePos = path.poll(); if (nextPipePos == null) { - return onDone(network, currentPipe.getWorld(), currentPipe); + return onDone(network, currentPipe.getLevel(), currentPipe); } Pipe nextPipe = network.getPipe(nextPipePos); if (nextPipe == null) { - return onPipeGone(network, currentPipe.getWorld(), nextPipePos); + return onPipeGone(network, currentPipe.getLevel(), nextPipePos); } progressInCurrentPipe = 0; @@ -124,34 +223,6 @@ private boolean isLastPipe() { return path.isEmpty(); } - private static Direction getDirection(BlockPos a, BlockPos b) { - if (a.offset(Direction.NORTH).equals(b)) { - return Direction.NORTH; - } - - if (a.offset(Direction.EAST).equals(b)) { - return Direction.EAST; - } - - if (a.offset(Direction.SOUTH).equals(b)) { - return Direction.SOUTH; - } - - if (a.offset(Direction.WEST).equals(b)) { - return Direction.WEST; - } - - if (a.offset(Direction.UP).equals(b)) { - return Direction.UP; - } - - if (a.offset(Direction.DOWN).equals(b)) { - return Direction.DOWN; - } - - return Direction.NORTH; - } - private int getMaxTicksInPipe(ItemPipe currentPipe) { double mt = currentPipe.getMaxTicksInPipe(); @@ -178,24 +249,24 @@ public ItemTransportProps createProps(ItemPipe currentPipe) { ); } - public CompoundNBT writeToNbt(CompoundNBT tag) { - tag.put("v", value.write(new CompoundNBT())); - tag.putLong("src", source.toLong()); - tag.putLong("dst", destination.toLong()); + public CompoundTag writeToNbt(CompoundTag tag) { + tag.put("v", value.save(new CompoundTag())); + tag.putLong("src", source.asLong()); + tag.putLong("dst", destination.asLong()); - ListNBT path = new ListNBT(); + ListTag path = new ListTag(); for (BlockPos pathItem : this.path) { - path.add(LongNBT.valueOf(pathItem.toLong())); + path.add(LongTag.valueOf(pathItem.asLong())); } tag.put("pth", path); tag.putInt("initiald", initialDirection.ordinal()); - tag.put("fc", finishedCallback.writeToNbt(new CompoundNBT())); + tag.put("fc", finishedCallback.writeToNbt(new CompoundTag())); tag.putString("fcid", finishedCallback.getId().toString()); - tag.put("cc", cancelCallback.writeToNbt(new CompoundNBT())); + tag.put("cc", cancelCallback.writeToNbt(new CompoundTag())); tag.putString("ccid", cancelCallback.getId().toString()); - tag.put("pgc", pipeGoneCallback.writeToNbt(new CompoundNBT())); + tag.put("pgc", pipeGoneCallback.writeToNbt(new CompoundTag())); tag.putString("pgcid", pipeGoneCallback.getId().toString()); tag.putBoolean("fp", firstPipe); @@ -203,76 +274,4 @@ public CompoundNBT writeToNbt(CompoundNBT tag) { return tag; } - - @Nullable - public static ItemTransport of(CompoundNBT tag) { - ItemStack value = ItemStack.read(tag.getCompound("v")); - if (value.isEmpty()) { - LOGGER.warn("Item no longer exists"); - return null; - } - - BlockPos source = BlockPos.fromLong(tag.getLong("src")); - BlockPos destination = BlockPos.fromLong(tag.getLong("dst")); - - ListNBT pathTag = tag.getList("pth", Constants.NBT.TAG_LONG); - Deque path = new ArrayDeque<>(); - for (INBT pathItem : pathTag) { - path.add(BlockPos.fromLong(((LongNBT) pathItem).getLong())); - } - - Direction initialDirection = DirectionUtil.safeGet((byte) tag.getInt("initd")); - - ResourceLocation finishedCallbackId = new ResourceLocation(tag.getString("fcid")); - TransportCallbackFactory finishedCallbackFactory = TransportCallbackFactoryRegistry.INSTANCE.getFactory(finishedCallbackId); - if (finishedCallbackFactory == null) { - LOGGER.warn("Finished callback factory " + finishedCallbackId + " no longer exists"); - return null; - } - TransportCallback finishedCallback = finishedCallbackFactory.create(tag.getCompound("fc")); - if (finishedCallback == null) { - LOGGER.warn("Finished callback factory " + finishedCallbackId + " returned null!"); - return null; - } - - ResourceLocation cancelCallbackId = new ResourceLocation(tag.getString("ccid")); - TransportCallbackFactory cancelCallbackFactory = TransportCallbackFactoryRegistry.INSTANCE.getFactory(cancelCallbackId); - if (cancelCallbackFactory == null) { - LOGGER.warn("Cancel callback factory " + cancelCallbackId + " no longer exists"); - return null; - } - TransportCallback cancelCallback = cancelCallbackFactory.create(tag.getCompound("cc")); - if (cancelCallback == null) { - LOGGER.warn("Cancel callback factory " + cancelCallbackId + " returned null!"); - return null; - } - - ResourceLocation pipeGoneCallbackId = new ResourceLocation(tag.getString("pgcid")); - TransportCallbackFactory pipeGoneCallbackFactory = TransportCallbackFactoryRegistry.INSTANCE.getFactory(pipeGoneCallbackId); - if (pipeGoneCallbackFactory == null) { - LOGGER.warn("Pipe gone callback factory " + pipeGoneCallbackId + " no longer exists"); - return null; - } - TransportCallback pipeGoneCallback = pipeGoneCallbackFactory.create(tag.getCompound("pgc")); - if (pipeGoneCallback == null) { - LOGGER.warn("Pipe gone callback factory " + pipeGoneCallbackId + " returned null!"); - return null; - } - - boolean firstPipe = tag.getBoolean("fp"); - int progressInCurrentPipe = tag.getInt("p"); - - return new ItemTransport( - value, - source, - destination, - path, - initialDirection, - finishedCallback, - cancelCallback, - pipeGoneCallback, - firstPipe, - progressInCurrentPipe - ); - } } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransportProps.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransportProps.java index 0a441c0..a67bf33 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransportProps.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/ItemTransportProps.java @@ -1,18 +1,18 @@ package com.refinedmods.refinedpipes.network.pipe.transport; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.Direction; +import net.minecraft.core.Direction; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.item.ItemStack; public class ItemTransportProps { private final ItemStack stack; private final int maxTicksInPipe; - private int progress; private final Direction direction; private final Direction initialDirection; private final boolean lastPipe; private final boolean firstPipe; + private int progress; public ItemTransportProps(ItemStack stack, int maxTicksInPipe, int progress, Direction direction, Direction initialDirection, boolean lastPipe, boolean firstPipe) { this.stack = stack; @@ -24,19 +24,9 @@ public ItemTransportProps(ItemStack stack, int maxTicksInPipe, int progress, Dir this.firstPipe = firstPipe; } - public void writeToBuffer(PacketBuffer buf) { - buf.writeItemStack(stack); - buf.writeInt(maxTicksInPipe); - buf.writeInt(progress); - buf.writeInt(direction.ordinal()); - buf.writeInt(initialDirection.ordinal()); - buf.writeBoolean(lastPipe); - buf.writeBoolean(firstPipe); - } - - public static ItemTransportProps create(PacketBuffer buf) { + public static ItemTransportProps create(FriendlyByteBuf buf) { return new ItemTransportProps( - buf.readItemStack(), + buf.readItem(), buf.readInt(), buf.readInt(), DirectionUtil.safeGet((byte) buf.readInt()), @@ -46,6 +36,16 @@ public static ItemTransportProps create(PacketBuffer buf) { ); } + public void writeToBuffer(FriendlyByteBuf buf) { + buf.writeItem(stack); + buf.writeInt(maxTicksInPipe); + buf.writeInt(progress); + buf.writeInt(direction.ordinal()); + buf.writeInt(initialDirection.ordinal()); + buf.writeBoolean(lastPipe); + buf.writeBoolean(firstPipe); + } + public void tick() { progress++; } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemBounceBackTransportCallback.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemBounceBackTransportCallback.java index 7217a89..cacce57 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemBounceBackTransportCallback.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemBounceBackTransportCallback.java @@ -2,22 +2,20 @@ import com.refinedmods.refinedpipes.RefinedPipes; import com.refinedmods.refinedpipes.network.Network; -import net.minecraft.inventory.InventoryHelper; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Containers; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; public class ItemBounceBackTransportCallback implements TransportCallback { - private static final Logger LOGGER = LogManager.getLogger(ItemBounceBackTransportCallback.class); - public static final ResourceLocation ID = new ResourceLocation(RefinedPipes.ID, "item_bounce_back"); - + private static final Logger LOGGER = LogManager.getLogger(ItemBounceBackTransportCallback.class); private final BlockPos originalItemHandlerPosition; private final BlockPos bounceBackItemHandlerPosition; private final ItemStack toInsert; @@ -28,22 +26,11 @@ public ItemBounceBackTransportCallback(BlockPos originalItemHandlerPosition, Blo this.toInsert = toInsert; } - @Override - public void call(Network network, World world, BlockPos currentPos, TransportCallback cancelCallback) { - // TODO: Actually bounce back... - InventoryHelper.spawnItemStack(world, originalItemHandlerPosition.getX(), originalItemHandlerPosition.getY(), originalItemHandlerPosition.getZ(), toInsert); - } - - @Override - public ResourceLocation getId() { - return ID; - } - @Nullable - public static ItemBounceBackTransportCallback of(CompoundNBT tag) { - BlockPos originalItemHandlerPosition = BlockPos.fromLong(tag.getLong("oihpos")); - BlockPos bounceBackItemHandlerPosition = BlockPos.fromLong(tag.getLong("bbihpos")); - ItemStack toInsert = ItemStack.read(tag.getCompound("s")); + public static ItemBounceBackTransportCallback of(CompoundTag tag) { + BlockPos originalItemHandlerPosition = BlockPos.of(tag.getLong("oihpos")); + BlockPos bounceBackItemHandlerPosition = BlockPos.of(tag.getLong("bbihpos")); + ItemStack toInsert = ItemStack.of(tag.getCompound("s")); if (toInsert.isEmpty()) { LOGGER.warn("Item no longer exists"); @@ -54,10 +41,21 @@ public static ItemBounceBackTransportCallback of(CompoundNBT tag) { } @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { - tag.putLong("oihpos", originalItemHandlerPosition.toLong()); - tag.putLong("bbihpos", bounceBackItemHandlerPosition.toLong()); - tag.put("s", toInsert.write(new CompoundNBT())); + public void call(Network network, Level level, BlockPos currentPos, TransportCallback cancelCallback) { + // TODO: Actually bounce back... + Containers.dropItemStack(level, originalItemHandlerPosition.getX(), originalItemHandlerPosition.getY(), originalItemHandlerPosition.getZ(), toInsert); + } + + @Override + public ResourceLocation getId() { + return ID; + } + + @Override + public CompoundTag writeToNbt(CompoundTag tag) { + tag.putLong("oihpos", originalItemHandlerPosition.asLong()); + tag.putLong("bbihpos", bounceBackItemHandlerPosition.asLong()); + tag.put("s", toInsert.save(new CompoundTag())); return tag; } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemInsertTransportCallback.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemInsertTransportCallback.java index e0ded98..a39eb1c 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemInsertTransportCallback.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemInsertTransportCallback.java @@ -3,13 +3,13 @@ import com.refinedmods.refinedpipes.RefinedPipes; import com.refinedmods.refinedpipes.network.Network; import com.refinedmods.refinedpipes.util.DirectionUtil; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; @@ -19,10 +19,8 @@ import javax.annotation.Nullable; public class ItemInsertTransportCallback implements TransportCallback { - private static final Logger LOGGER = LogManager.getLogger(ItemInsertTransportCallback.class); - public static final ResourceLocation ID = new ResourceLocation(RefinedPipes.ID, "item_insert"); - + private static final Logger LOGGER = LogManager.getLogger(ItemInsertTransportCallback.class); private final BlockPos itemHandlerPosition; private final Direction incomingDirection; private final ItemStack toInsert; @@ -33,26 +31,40 @@ public ItemInsertTransportCallback(BlockPos itemHandlerPosition, Direction incom this.toInsert = toInsert; } + @Nullable + public static ItemInsertTransportCallback of(CompoundTag tag) { + BlockPos itemHandlerPosition = BlockPos.of(tag.getLong("ihpos")); + ItemStack toInsert = ItemStack.of(tag.getCompound("s")); + Direction incomingDirection = DirectionUtil.safeGet((byte) tag.getInt("incdir")); + + if (toInsert.isEmpty()) { + LOGGER.warn("Item no longer exists"); + return null; + } + + return new ItemInsertTransportCallback(itemHandlerPosition, incomingDirection, toInsert); + } + @Override - public void call(Network network, World world, BlockPos currentPos, TransportCallback cancelCallback) { - TileEntity tile = world.getTileEntity(itemHandlerPosition); - if (tile == null) { + public void call(Network network, Level level, BlockPos currentPos, TransportCallback cancelCallback) { + BlockEntity blockEntity = level.getBlockEntity(itemHandlerPosition); + if (blockEntity == null) { LOGGER.warn("Destination item handler is gone at " + itemHandlerPosition); - cancelCallback.call(network, world, currentPos, cancelCallback); + cancelCallback.call(network, level, currentPos, cancelCallback); return; } - IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, incomingDirection.getOpposite()).orElse(null); + IItemHandler itemHandler = blockEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, incomingDirection.getOpposite()).orElse(null); if (itemHandler == null) { LOGGER.warn("Destination item handler is no longer exposing a capability at " + itemHandlerPosition); - cancelCallback.call(network, world, currentPos, cancelCallback); + cancelCallback.call(network, level, currentPos, cancelCallback); return; } if (ItemHandlerHelper.insertItem(itemHandler, toInsert, true).isEmpty()) { ItemHandlerHelper.insertItem(itemHandler, toInsert, false); } else { - cancelCallback.call(network, world, currentPos, cancelCallback); + cancelCallback.call(network, level, currentPos, cancelCallback); } } @@ -61,24 +73,10 @@ public ResourceLocation getId() { return ID; } - @Nullable - public static ItemInsertTransportCallback of(CompoundNBT tag) { - BlockPos itemHandlerPosition = BlockPos.fromLong(tag.getLong("ihpos")); - ItemStack toInsert = ItemStack.read(tag.getCompound("s")); - Direction incomingDirection = DirectionUtil.safeGet((byte) tag.getInt("incdir")); - - if (toInsert.isEmpty()) { - LOGGER.warn("Item no longer exists"); - return null; - } - - return new ItemInsertTransportCallback(itemHandlerPosition, incomingDirection, toInsert); - } - @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { - tag.putLong("ihpos", itemHandlerPosition.toLong()); - tag.put("s", toInsert.write(new CompoundNBT())); + public CompoundTag writeToNbt(CompoundTag tag) { + tag.putLong("ihpos", itemHandlerPosition.asLong()); + tag.put("s", toInsert.save(new CompoundTag())); tag.putInt("incdir", incomingDirection.ordinal()); return tag; diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemPipeGoneTransportCallback.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemPipeGoneTransportCallback.java index 8f5ccea..8acce73 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemPipeGoneTransportCallback.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/ItemPipeGoneTransportCallback.java @@ -2,41 +2,29 @@ import com.refinedmods.refinedpipes.RefinedPipes; import com.refinedmods.refinedpipes.network.Network; -import net.minecraft.inventory.InventoryHelper; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Containers; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; public class ItemPipeGoneTransportCallback implements TransportCallback { - private static final Logger LOGGER = LogManager.getLogger(ItemPipeGoneTransportCallback.class); - public static final ResourceLocation ID = new ResourceLocation(RefinedPipes.ID, "item_pipe_gone"); - + private static final Logger LOGGER = LogManager.getLogger(ItemPipeGoneTransportCallback.class); private final ItemStack stack; public ItemPipeGoneTransportCallback(ItemStack stack) { this.stack = stack; } - @Override - public void call(Network network, World world, BlockPos currentPos, TransportCallback cancelCallback) { - InventoryHelper.spawnItemStack(world, currentPos.getX(), currentPos.getY(), currentPos.getZ(), stack); - } - - @Override - public ResourceLocation getId() { - return ID; - } - @Nullable - public static ItemPipeGoneTransportCallback of(CompoundNBT tag) { - ItemStack stack = ItemStack.read(tag.getCompound("s")); + public static ItemPipeGoneTransportCallback of(CompoundTag tag) { + ItemStack stack = ItemStack.of(tag.getCompound("s")); if (stack.isEmpty()) { LOGGER.warn("Item no longer exists"); @@ -47,8 +35,18 @@ public static ItemPipeGoneTransportCallback of(CompoundNBT tag) { } @Override - public CompoundNBT writeToNbt(CompoundNBT tag) { - tag.put("s", stack.write(new CompoundNBT())); + public void call(Network network, Level level, BlockPos currentPos, TransportCallback cancelCallback) { + Containers.dropItemStack(level, currentPos.getX(), currentPos.getY(), currentPos.getZ(), stack); + } + + @Override + public ResourceLocation getId() { + return ID; + } + + @Override + public CompoundTag writeToNbt(CompoundTag tag) { + tag.put("s", stack.save(new CompoundTag())); return tag; } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallback.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallback.java index b8058d2..5f63cb5 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallback.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallback.java @@ -1,15 +1,15 @@ package com.refinedmods.refinedpipes.network.pipe.transport.callback; import com.refinedmods.refinedpipes.network.Network; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; public interface TransportCallback { - void call(Network network, World world, BlockPos currentPos, TransportCallback cancelCallback); + void call(Network network, Level level, BlockPos currentPos, TransportCallback cancelCallback); ResourceLocation getId(); - CompoundNBT writeToNbt(CompoundNBT tag); + CompoundTag writeToNbt(CompoundTag tag); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactory.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactory.java index 047b8e9..1544a45 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactory.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactory.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedpipes.network.pipe.transport.callback; -import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.CompoundTag; import javax.annotation.Nullable; public interface TransportCallbackFactory { @Nullable - TransportCallback create(CompoundNBT tag); + TransportCallback create(CompoundTag tag); } diff --git a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactoryRegistry.java b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactoryRegistry.java index 361bc15..b70af3e 100644 --- a/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactoryRegistry.java +++ b/src/main/java/com/refinedmods/refinedpipes/network/pipe/transport/callback/TransportCallbackFactoryRegistry.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.network.pipe.transport.callback; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; import javax.annotation.Nullable; import java.util.HashMap; diff --git a/src/main/java/com/refinedmods/refinedpipes/render/CubeBuilder.java b/src/main/java/com/refinedmods/refinedpipes/render/CubeBuilder.java index b32097b..8124d33 100644 --- a/src/main/java/com/refinedmods/refinedpipes/render/CubeBuilder.java +++ b/src/main/java/com/refinedmods/refinedpipes/render/CubeBuilder.java @@ -1,9 +1,9 @@ package com.refinedmods.refinedpipes.render; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.Direction; +import net.minecraft.core.Direction; import javax.annotation.Nullable; @@ -15,61 +15,61 @@ public class CubeBuilder { private CubeBuilder() { } - public void putCube(MatrixStack matrixStack, IVertexBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, int r, int g, int b, int a, int light, TextureAtlasSprite sprite) { - putCube(matrixStack, builder, x1, y1, z1, x2, y2, z2, r, g, b, a, light, sprite, null); + public void putCube(PoseStack poseStack, VertexConsumer builder, float x1, float y1, float z1, float x2, float y2, float z2, int r, int g, int b, int a, int light, TextureAtlasSprite sprite) { + putCube(poseStack, builder, x1, y1, z1, x2, y2, z2, r, g, b, a, light, sprite, null); } - public void putCube(MatrixStack matrixStack, IVertexBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, int r, int g, int b, int a, int light, TextureAtlasSprite sprite, @Nullable Direction exclude) { - matrixStack.push(); + public void putCube(PoseStack poseStack, VertexConsumer builder, float x1, float y1, float z1, float x2, float y2, float z2, int r, int g, int b, int a, int light, TextureAtlasSprite sprite, @Nullable Direction exclude) { + poseStack.pushPose(); for (Direction face : Direction.values()) { if (face != exclude) { - putFace(matrixStack, builder, x1, y1, z1, x2, y2, z2, r, g, b, a, light, sprite, face); + putFace(poseStack, builder, x1, y1, z1, x2, y2, z2, r, g, b, a, light, sprite, face); } } - matrixStack.pop(); + poseStack.popPose(); } - public void putFace(MatrixStack matrixStack, IVertexBuilder builder, float x1, float y1, float z1, float x2, float y2, float z2, int r, int g, int b, int a, int light, TextureAtlasSprite sprite, Direction face) { + public void putFace(PoseStack poseStack, VertexConsumer builder, float x1, float y1, float z1, float x2, float y2, float z2, int r, int g, int b, int a, int light, TextureAtlasSprite sprite, Direction face) { UvVector uv = getDefaultUv(face, sprite, x1, y1, z1, x2, y2, z2); switch (face) { case DOWN: - this.putVertexTR(builder, matrixStack, face, r, g, b, a, light, x2, y1, z1, uv); - this.putVertexBR(builder, matrixStack, face, r, g, b, a, light, x2, y1, z2, uv); - this.putVertexBL(builder, matrixStack, face, r, g, b, a, light, x1, y1, z2, uv); - this.putVertexTL(builder, matrixStack, face, r, g, b, a, light, x1, y1, z1, uv); + this.putVertexTR(builder, poseStack, face, r, g, b, a, light, x2, y1, z1, uv); + this.putVertexBR(builder, poseStack, face, r, g, b, a, light, x2, y1, z2, uv); + this.putVertexBL(builder, poseStack, face, r, g, b, a, light, x1, y1, z2, uv); + this.putVertexTL(builder, poseStack, face, r, g, b, a, light, x1, y1, z1, uv); break; case UP: - this.putVertexTL(builder, matrixStack, face, r, g, b, a, light, x1, y2, z1, uv); - this.putVertexBL(builder, matrixStack, face, r, g, b, a, light, x1, y2, z2, uv); - this.putVertexBR(builder, matrixStack, face, r, g, b, a, light, x2, y2, z2, uv); - this.putVertexTR(builder, matrixStack, face, r, g, b, a, light, x2, y2, z1, uv); + this.putVertexTL(builder, poseStack, face, r, g, b, a, light, x1, y2, z1, uv); + this.putVertexBL(builder, poseStack, face, r, g, b, a, light, x1, y2, z2, uv); + this.putVertexBR(builder, poseStack, face, r, g, b, a, light, x2, y2, z2, uv); + this.putVertexTR(builder, poseStack, face, r, g, b, a, light, x2, y2, z1, uv); break; case NORTH: - this.putVertexBR(builder, matrixStack, face, r, g, b, a, light, x2, y2, z1, uv); - this.putVertexTR(builder, matrixStack, face, r, g, b, a, light, x2, y1, z1, uv); - this.putVertexTL(builder, matrixStack, face, r, g, b, a, light, x1, y1, z1, uv); - this.putVertexBL(builder, matrixStack, face, r, g, b, a, light, x1, y2, z1, uv); + this.putVertexBR(builder, poseStack, face, r, g, b, a, light, x2, y2, z1, uv); + this.putVertexTR(builder, poseStack, face, r, g, b, a, light, x2, y1, z1, uv); + this.putVertexTL(builder, poseStack, face, r, g, b, a, light, x1, y1, z1, uv); + this.putVertexBL(builder, poseStack, face, r, g, b, a, light, x1, y2, z1, uv); break; case SOUTH: - this.putVertexBL(builder, matrixStack, face, r, g, b, a, light, x1, y2, z2, uv); - this.putVertexTL(builder, matrixStack, face, r, g, b, a, light, x1, y1, z2, uv); - this.putVertexTR(builder, matrixStack, face, r, g, b, a, light, x2, y1, z2, uv); - this.putVertexBR(builder, matrixStack, face, r, g, b, a, light, x2, y2, z2, uv); + this.putVertexBL(builder, poseStack, face, r, g, b, a, light, x1, y2, z2, uv); + this.putVertexTL(builder, poseStack, face, r, g, b, a, light, x1, y1, z2, uv); + this.putVertexTR(builder, poseStack, face, r, g, b, a, light, x2, y1, z2, uv); + this.putVertexBR(builder, poseStack, face, r, g, b, a, light, x2, y2, z2, uv); break; case WEST: - this.putVertexTL(builder, matrixStack, face, r, g, b, a, light, x1, y1, z1, uv); - this.putVertexTR(builder, matrixStack, face, r, g, b, a, light, x1, y1, z2, uv); - this.putVertexBR(builder, matrixStack, face, r, g, b, a, light, x1, y2, z2, uv); - this.putVertexBL(builder, matrixStack, face, r, g, b, a, light, x1, y2, z1, uv); + this.putVertexTL(builder, poseStack, face, r, g, b, a, light, x1, y1, z1, uv); + this.putVertexTR(builder, poseStack, face, r, g, b, a, light, x1, y1, z2, uv); + this.putVertexBR(builder, poseStack, face, r, g, b, a, light, x1, y2, z2, uv); + this.putVertexBL(builder, poseStack, face, r, g, b, a, light, x1, y2, z1, uv); break; case EAST: - this.putVertexBR(builder, matrixStack, face, r, g, b, a, light, x2, y2, z1, uv); - this.putVertexBL(builder, matrixStack, face, r, g, b, a, light, x2, y2, z2, uv); - this.putVertexTL(builder, matrixStack, face, r, g, b, a, light, x2, y1, z2, uv); - this.putVertexTR(builder, matrixStack, face, r, g, b, a, light, x2, y1, z1, uv); + this.putVertexBR(builder, poseStack, face, r, g, b, a, light, x2, y2, z1, uv); + this.putVertexBL(builder, poseStack, face, r, g, b, a, light, x2, y2, z2, uv); + this.putVertexTL(builder, poseStack, face, r, g, b, a, light, x2, y1, z2, uv); + this.putVertexTR(builder, poseStack, face, r, g, b, a, light, x2, y1, z1, uv); break; } @@ -80,40 +80,40 @@ private UvVector getDefaultUv(Direction face, TextureAtlasSprite texture, float switch (face) { case DOWN: - uv.u1 = texture.getInterpolatedU(x1 * 16); - uv.v1 = texture.getInterpolatedV(z1 * 16); - uv.u2 = texture.getInterpolatedU(x2 * 16); - uv.v2 = texture.getInterpolatedV(z2 * 16); + uv.u1 = texture.getU(x1 * 16); + uv.v1 = texture.getV(z1 * 16); + uv.u2 = texture.getU(x2 * 16); + uv.v2 = texture.getV(z2 * 16); break; case UP: - uv.u1 = texture.getInterpolatedU(x1 * 16); - uv.v1 = texture.getInterpolatedV(z1 * 16); - uv.u2 = texture.getInterpolatedU(x2 * 16); - uv.v2 = texture.getInterpolatedV(z2 * 16); + uv.u1 = texture.getU(x1 * 16); + uv.v1 = texture.getV(z1 * 16); + uv.u2 = texture.getU(x2 * 16); + uv.v2 = texture.getV(z2 * 16); break; case NORTH: - uv.u1 = texture.getInterpolatedU(x1 * 16); - uv.v1 = texture.getInterpolatedV(16 - y1 * 16); - uv.u2 = texture.getInterpolatedU(x2 * 16); - uv.v2 = texture.getInterpolatedV(16 - y2 * 16); + uv.u1 = texture.getU(x1 * 16); + uv.v1 = texture.getV(16 - y1 * 16); + uv.u2 = texture.getU(x2 * 16); + uv.v2 = texture.getV(16 - y2 * 16); break; case SOUTH: - uv.u1 = texture.getInterpolatedU(x1 * 16); - uv.v1 = texture.getInterpolatedV(16 - y1 * 16); - uv.u2 = texture.getInterpolatedU(x2 * 16); - uv.v2 = texture.getInterpolatedV(16 - y2 * 16); + uv.u1 = texture.getU(x1 * 16); + uv.v1 = texture.getV(16 - y1 * 16); + uv.u2 = texture.getU(x2 * 16); + uv.v2 = texture.getV(16 - y2 * 16); break; case WEST: - uv.u1 = texture.getInterpolatedU(z1 * 16); - uv.v1 = texture.getInterpolatedV(16 - y1 * 16); - uv.u2 = texture.getInterpolatedU(z2 * 16); - uv.v2 = texture.getInterpolatedV(16 - y2 * 16); + uv.u1 = texture.getU(z1 * 16); + uv.v1 = texture.getV(16 - y1 * 16); + uv.u2 = texture.getU(z2 * 16); + uv.v2 = texture.getV(16 - y2 * 16); break; case EAST: - uv.u1 = texture.getInterpolatedU(z2 * 16); - uv.v1 = texture.getInterpolatedV(16 - y1 * 16); - uv.u2 = texture.getInterpolatedU(z1 * 16); - uv.v2 = texture.getInterpolatedV(16 - y2 * 16); + uv.u1 = texture.getU(z2 * 16); + uv.v1 = texture.getV(16 - y1 * 16); + uv.u2 = texture.getU(z1 * 16); + uv.v2 = texture.getV(16 - y2 * 16); break; } @@ -121,7 +121,7 @@ private UvVector getDefaultUv(Direction face, TextureAtlasSprite texture, float } // uv.u1, uv.v1 - private void putVertexTL(IVertexBuilder builder, MatrixStack matrixStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { + private void putVertexTL(VertexConsumer builder, PoseStack poseStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { float u, v; switch (this.uvRotations[face.ordinal()]) { @@ -144,11 +144,11 @@ private void putVertexTL(IVertexBuilder builder, MatrixStack matrixStack, Direct break; } - this.putVertex(builder, matrixStack, r, g, b, a, light, x, y, z, u, v); + this.putVertex(builder, poseStack, r, g, b, a, light, x, y, z, u, v); } // uv.u2, uv.v1 - private void putVertexTR(IVertexBuilder builder, MatrixStack matrixStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { + private void putVertexTR(VertexConsumer builder, PoseStack poseStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { float u, v; switch (this.uvRotations[face.ordinal()]) { @@ -171,11 +171,11 @@ private void putVertexTR(IVertexBuilder builder, MatrixStack matrixStack, Direct break; } - this.putVertex(builder, matrixStack, r, g, b, a, light, x, y, z, u, v); + this.putVertex(builder, poseStack, r, g, b, a, light, x, y, z, u, v); } // uv.u2, uv.v2 - private void putVertexBR(IVertexBuilder builder, MatrixStack matrixStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { + private void putVertexBR(VertexConsumer builder, PoseStack poseStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { float u; float v; @@ -200,11 +200,11 @@ private void putVertexBR(IVertexBuilder builder, MatrixStack matrixStack, Direct break; } - this.putVertex(builder, matrixStack, r, g, b, a, light, x, y, z, u, v); + this.putVertex(builder, poseStack, r, g, b, a, light, x, y, z, u, v); } // uv.u1, uv.v2 - private void putVertexBL(IVertexBuilder builder, MatrixStack matrixStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { + private void putVertexBL(VertexConsumer builder, PoseStack poseStack, Direction face, int r, int g, int b, int a, int light, float x, float y, float z, UvVector uv) { float u; float v; @@ -229,14 +229,14 @@ private void putVertexBL(IVertexBuilder builder, MatrixStack matrixStack, Direct break; } - this.putVertex(builder, matrixStack, r, g, b, a, light, x, y, z, u, v); + this.putVertex(builder, poseStack, r, g, b, a, light, x, y, z, u, v); } - private void putVertex(IVertexBuilder builder, MatrixStack matrixStack, int r, int g, int b, int a, int light, float x, float y, float z, float u, float v) { - builder.pos(matrixStack.getLast().getMatrix(), x, y, z) + private void putVertex(VertexConsumer builder, PoseStack poseStack, int r, int g, int b, int a, int light, float x, float y, float z, float u, float v) { + builder.vertex(poseStack.last().pose(), x, y, z) .color(r, g, b, a) - .tex(u, v) - .lightmap(light) + .uv(u, v) + .uv2(light) .endVertex(); } diff --git a/src/main/java/com/refinedmods/refinedpipes/render/FluidPipeTileEntityRenderer.java b/src/main/java/com/refinedmods/refinedpipes/render/FluidPipeBlockEntityRenderer.java similarity index 77% rename from src/main/java/com/refinedmods/refinedpipes/render/FluidPipeTileEntityRenderer.java rename to src/main/java/com/refinedmods/refinedpipes/render/FluidPipeBlockEntityRenderer.java index b70717b..c71b4a5 100644 --- a/src/main/java/com/refinedmods/refinedpipes/render/FluidPipeTileEntityRenderer.java +++ b/src/main/java/com/refinedmods/refinedpipes/render/FluidPipeBlockEntityRenderer.java @@ -1,52 +1,47 @@ package com.refinedmods.refinedpipes.render; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.refinedmods.refinedpipes.block.FluidPipeBlock; -import com.refinedmods.refinedpipes.tile.FluidPipeTileEntity; -import net.minecraft.block.BlockState; +import com.refinedmods.refinedpipes.blockentity.FluidPipeBlockEntity; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.inventory.container.PlayerContainer; -import net.minecraft.util.Direction; -import net.minecraft.world.World; +import net.minecraft.core.Direction; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidStack; -public class FluidPipeTileEntityRenderer extends TileEntityRenderer { +public class FluidPipeBlockEntityRenderer implements BlockEntityRenderer { private static final float INSET = 0.001F; - public FluidPipeTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { - super(dispatcher); - } - @Override @SuppressWarnings("deprecation") - public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer bufferType, int combinedLight, int combinedOverlay) { - World world = tile.getWorld(); - if (world == null) { + public void render(FluidPipeBlockEntity blockEntity, float partialTicks, PoseStack poseStack, MultiBufferSource bufferType, int combinedLight, int combinedOverlay) { + Level level = blockEntity.getLevel(); + if (level == null) { return; } - BlockState state = world.getBlockState(tile.getPos()); + BlockState state = level.getBlockState(blockEntity.getBlockPos()); if (!(state.getBlock() instanceof FluidPipeBlock)) { return; } - FluidStack fluidStack = tile.getFluid(); + FluidStack fluidStack = blockEntity.getFluid(); if (fluidStack.isEmpty()) { - tile.updateAndGetRenderFullness(partialTicks); + blockEntity.updateAndGetRenderFullness(partialTicks); return; } - int light = WorldRenderer.getCombinedLight(tile.getWorld(), tile.getPos()); + int light = LevelRenderer.getLightColor(blockEntity.getLevel(), blockEntity.getBlockPos()); FluidAttributes attributes = fluidStack.getFluid().getAttributes(); - TextureAtlasSprite sprite = Minecraft.getInstance().getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(attributes.getStillTexture(fluidStack)); + TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(attributes.getStillTexture(fluidStack)); int fluidColor = attributes.getColor(fluidStack); int r = fluidColor >> 16 & 0xFF; @@ -54,14 +49,14 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat int b = fluidColor & 0xFF; int a = fluidColor >> 24 & 0xFF; - IVertexBuilder buffer = bufferType.getBuffer(RenderType.getText(sprite.getAtlasTexture().getTextureLocation())); + VertexConsumer buffer = bufferType.getBuffer(RenderType.text(sprite.atlas().location())); - float fullness = tile.updateAndGetRenderFullness(partialTicks); + float fullness = blockEntity.updateAndGetRenderFullness(partialTicks); if (fullness == 0) { return; } - if (state.get(FluidPipeBlock.NORTH)) { + if (state.getValue(FluidPipeBlock.NORTH)) { float x1 = 4; float y1 = 4; float z1 = 0; @@ -70,7 +65,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat float z2 = 4; CubeBuilder.INSTANCE.putCube( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -88,7 +83,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (state.get(FluidPipeBlock.EAST)) { + if (state.getValue(FluidPipeBlock.EAST)) { float x1 = 12; float y1 = 4; float z1 = 4; @@ -97,7 +92,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat float z2 = 12; CubeBuilder.INSTANCE.putCube( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -115,7 +110,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (state.get(FluidPipeBlock.SOUTH)) { + if (state.getValue(FluidPipeBlock.SOUTH)) { float x1 = 4; float y1 = 4; float z1 = 12; @@ -124,7 +119,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat float z2 = 16; CubeBuilder.INSTANCE.putCube( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -142,7 +137,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (state.get(FluidPipeBlock.WEST)) { + if (state.getValue(FluidPipeBlock.WEST)) { float x1 = 0; float y1 = 4; float z1 = 4; @@ -151,7 +146,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat float z2 = 12; CubeBuilder.INSTANCE.putCube( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -169,7 +164,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (state.get(FluidPipeBlock.UP)) { + if (state.getValue(FluidPipeBlock.UP)) { float x1 = 4; float y1 = 12; float z1 = 4; @@ -192,7 +187,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat y1 -= (1F - fullness) * (12F - 4F); CubeBuilder.INSTANCE.putCube( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -210,7 +205,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (state.get(FluidPipeBlock.DOWN)) { + if (state.getValue(FluidPipeBlock.DOWN)) { float x1 = 4; float y1 = 0; float z1 = 4; @@ -227,7 +222,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat z2 -= shrinkage; CubeBuilder.INSTANCE.putCube( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -253,10 +248,10 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat float y2 = 4 + (fullness * (12 - 4)); float z2 = 12; - matrixStack.push(); + poseStack.pushPose(); CubeBuilder.INSTANCE.putFace( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -274,7 +269,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); CubeBuilder.INSTANCE.putFace( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -291,9 +286,9 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat Direction.DOWN ); - if (!state.get(FluidPipeBlock.NORTH)) { + if (!state.getValue(FluidPipeBlock.NORTH)) { CubeBuilder.INSTANCE.putFace( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -311,9 +306,9 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (!state.get(FluidPipeBlock.EAST)) { + if (!state.getValue(FluidPipeBlock.EAST)) { CubeBuilder.INSTANCE.putFace( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -331,9 +326,9 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (!state.get(FluidPipeBlock.SOUTH)) { + if (!state.getValue(FluidPipeBlock.SOUTH)) { CubeBuilder.INSTANCE.putFace( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -351,9 +346,9 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - if (!state.get(FluidPipeBlock.WEST)) { + if (!state.getValue(FluidPipeBlock.WEST)) { CubeBuilder.INSTANCE.putFace( - matrixStack, + poseStack, buffer, (x1 / 16F) + INSET, (y1 / 16F) + INSET, @@ -371,7 +366,7 @@ public void render(FluidPipeTileEntity tile, float partialTicks, MatrixStack mat ); } - matrixStack.pop(); + poseStack.popPose(); } } } diff --git a/src/main/java/com/refinedmods/refinedpipes/render/FluidRenderer.java b/src/main/java/com/refinedmods/refinedpipes/render/FluidRenderer.java index 61b4217..791d902 100644 --- a/src/main/java/com/refinedmods/refinedpipes/render/FluidRenderer.java +++ b/src/main/java/com/refinedmods/refinedpipes/render/FluidRenderer.java @@ -1,14 +1,15 @@ package com.refinedmods.refinedpipes.render; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.fluid.Fluid; -import net.minecraft.inventory.container.PlayerContainer; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.level.material.Fluid; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidStack; @@ -35,15 +36,44 @@ public FluidRenderer(int capacityMb, int width, int height, int minHeight) { this.minHeight = minHeight; } - public void render(final int xPosition, final int yPosition, @Nonnull FluidStack fluidStack) { - RenderSystem.enableBlend(); - RenderSystem.enableAlphaTest(); + private static TextureAtlasSprite getStillFluidSprite(FluidStack fluidStack) { + Fluid fluid = fluidStack.getFluid(); + FluidAttributes attributes = fluid.getAttributes(); + ResourceLocation fluidStill = attributes.getStillTexture(fluidStack); + return Minecraft.getInstance().getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(fluidStill); + } - drawFluid(xPosition, yPosition, fluidStack); + private static void setGLColorFromInt(int color) { + float red = (color >> 16 & 0xFF) / 255.0F; + float green = (color >> 8 & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + float alpha = ((color >> 24) & 0xFF) / 255F; - RenderSystem.color4f(1, 1, 1, 1); + RenderSystem.setShaderColor(red, green, blue, alpha); + } - RenderSystem.disableAlphaTest(); + private static void drawTextureWithMasking(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel) { + double uMin = textureSprite.getU0(); + double uMax = textureSprite.getU1(); + double vMin = textureSprite.getV0(); + double vMax = textureSprite.getV1(); + uMax = uMax - (maskRight / 16.0 * (uMax - uMin)); + vMax = vMax - (maskTop / 16.0 * (vMax - vMin)); + + Tesselator tessellator = Tesselator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuilder(); + bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); + bufferBuilder.vertex(xCoord, yCoord + 16, zLevel).uv((float) uMin, (float) vMax).endVertex(); + bufferBuilder.vertex(xCoord + 16 - maskRight, yCoord + 16, zLevel).uv((float) uMax, (float) vMax).endVertex(); + bufferBuilder.vertex(xCoord + 16 - maskRight, yCoord + maskTop, zLevel).uv((float) uMax, (float) vMin).endVertex(); + bufferBuilder.vertex(xCoord, yCoord + maskTop, zLevel).uv((float) uMin, (float) vMin).endVertex(); + tessellator.end(); + } + + public void render(final int xPosition, final int yPosition, @Nonnull FluidStack fluidStack) { + RenderSystem.enableBlend(); + drawFluid(xPosition, yPosition, fluidStack); + RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.disableBlend(); } @@ -72,8 +102,8 @@ private void drawFluid(final int xPosition, final int yPosition, @Nonnull FluidS } private void drawTiledSprite(final int xPosition, final int yPosition, final int tiledWidth, final int tiledHeight, int color, int scaledAmount, TextureAtlasSprite sprite) { - Minecraft minecraft = Minecraft.getInstance(); - minecraft.getTextureManager().bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE); + RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS); + setGLColorFromInt(color); final int xTileCount = tiledWidth / TEX_WIDTH; @@ -98,38 +128,4 @@ private void drawTiledSprite(final int xPosition, final int yPosition, final int } } } - - private static TextureAtlasSprite getStillFluidSprite(FluidStack fluidStack) { - Fluid fluid = fluidStack.getFluid(); - FluidAttributes attributes = fluid.getAttributes(); - ResourceLocation fluidStill = attributes.getStillTexture(fluidStack); - return Minecraft.getInstance().getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(fluidStill); - } - - private static void setGLColorFromInt(int color) { - float red = (color >> 16 & 0xFF) / 255.0F; - float green = (color >> 8 & 0xFF) / 255.0F; - float blue = (color & 0xFF) / 255.0F; - float alpha = ((color >> 24) & 0xFF) / 255F; - - RenderSystem.color4f(red, green, blue, alpha); - } - - private static void drawTextureWithMasking(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel) { - double uMin = textureSprite.getMinU(); - double uMax = textureSprite.getMaxU(); - double vMin = textureSprite.getMinV(); - double vMax = textureSprite.getMaxV(); - uMax = uMax - (maskRight / 16.0 * (uMax - uMin)); - vMax = vMax - (maskTop / 16.0 * (vMax - vMin)); - - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferBuilder = tessellator.getBuffer(); - bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX); - bufferBuilder.pos(xCoord, yCoord + 16, zLevel).tex((float) uMin, (float) vMax).endVertex(); - bufferBuilder.pos(xCoord + 16 - maskRight, yCoord + 16, zLevel).tex((float) uMax, (float) vMax).endVertex(); - bufferBuilder.pos(xCoord + 16 - maskRight, yCoord + maskTop, zLevel).tex((float) uMax, (float) vMin).endVertex(); - bufferBuilder.pos(xCoord, yCoord + maskTop, zLevel).tex((float) uMin, (float) vMin).endVertex(); - tessellator.draw(); - } } diff --git a/src/main/java/com/refinedmods/refinedpipes/render/ItemPipeTileEntityRenderer.java b/src/main/java/com/refinedmods/refinedpipes/render/ItemPipeBlockEntityRenderer.java similarity index 54% rename from src/main/java/com/refinedmods/refinedpipes/render/ItemPipeTileEntityRenderer.java rename to src/main/java/com/refinedmods/refinedpipes/render/ItemPipeBlockEntityRenderer.java index 72bc8ee..ed36c3b 100644 --- a/src/main/java/com/refinedmods/refinedpipes/render/ItemPipeTileEntityRenderer.java +++ b/src/main/java/com/refinedmods/refinedpipes/render/ItemPipeBlockEntityRenderer.java @@ -1,25 +1,20 @@ package com.refinedmods.refinedpipes.render; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Quaternion; +import com.refinedmods.refinedpipes.blockentity.ItemPipeBlockEntity; import com.refinedmods.refinedpipes.network.pipe.transport.ItemTransportProps; -import com.refinedmods.refinedpipes.tile.ItemPipeTileEntity; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.model.ItemCameraTransforms; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.util.Direction; -import net.minecraft.util.math.vector.Quaternion; - -public class ItemPipeTileEntityRenderer extends TileEntityRenderer { - public ItemPipeTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { - super(dispatcher); - } +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.core.Direction; +public class ItemPipeBlockEntityRenderer implements BlockEntityRenderer { @Override @SuppressWarnings("deprecation") - public void render(ItemPipeTileEntity tile, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer bufferType, int combinedLight, int combinedOverlay) { - for (ItemTransportProps prop : tile.getProps()) { + public void render(ItemPipeBlockEntity blockEntity, float partialTicks, PoseStack poseStack, MultiBufferSource bufferType, int combinedLight, int combinedOverlay) { + for (ItemTransportProps prop : blockEntity.getProps()) { Direction dir = prop.getDirection(); double pipeLength = 1D; @@ -53,32 +48,33 @@ public void render(ItemPipeTileEntity tile, float partialTicks, MatrixStack matr } // If the next pipe is gone.. - if (v > 0.25 && tile.getWorld().isAirBlock(tile.getPos().offset(prop.getDirection()))) { + if (v > 0.25 && blockEntity.getLevel().isEmptyBlock(blockEntity.getBlockPos().relative(prop.getDirection()))) { continue; } v = Math.min(1F, v); - matrixStack.push(); + poseStack.pushPose(); - matrixStack.translate( - 0.5 + (dir.getXOffset() * v), - 0.5 + (dir.getYOffset() * v), - 0.5 + (dir.getZOffset() * v) + poseStack.translate( + 0.5 + (dir.getStepX() * v), + 0.5 + (dir.getStepY() * v), + 0.5 + (dir.getStepZ() * v) ); - matrixStack.rotate(new Quaternion(0, (float) ((Minecraft.getInstance().world.getGameTime() / 25D) % (Math.PI * 2) + (partialTicks / 25D)), 0, false)); - matrixStack.scale(0.5F, 0.5F, 0.5F); + poseStack.mulPose(new Quaternion(0, (float) ((Minecraft.getInstance().level.getGameTime() / 25D) % (Math.PI * 2) + (partialTicks / 25D)), 0, false)); + poseStack.scale(0.5F, 0.5F, 0.5F); - Minecraft.getInstance().getItemRenderer().renderItem( + Minecraft.getInstance().getItemRenderer().renderStatic( prop.getStack(), - ItemCameraTransforms.TransformType.FIXED, + ItemTransforms.TransformType.FIXED, combinedLight, combinedOverlay, - matrixStack, - bufferType + poseStack, + bufferType, + 0 ); - matrixStack.pop(); + poseStack.popPose(); } } } diff --git a/src/main/java/com/refinedmods/refinedpipes/render/PipeBakedModel.java b/src/main/java/com/refinedmods/refinedpipes/render/PipeBakedModel.java index 3ca6c7d..a3cf781 100644 --- a/src/main/java/com/refinedmods/refinedpipes/render/PipeBakedModel.java +++ b/src/main/java/com/refinedmods/refinedpipes/render/PipeBakedModel.java @@ -1,18 +1,18 @@ package com.refinedmods.refinedpipes.render; import com.google.common.collect.ImmutableList; +import com.mojang.math.Quaternion; +import com.mojang.math.Transformation; +import com.mojang.math.Vector3f; import com.refinedmods.refinedpipes.block.PipeBlock; -import com.refinedmods.refinedpipes.tile.PipeTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.model.BakedQuad; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.ItemOverrideList; +import com.refinedmods.refinedpipes.blockentity.PipeBlockEntity; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.vector.Quaternion; -import net.minecraft.util.math.vector.TransformationMatrix; -import net.minecraft.util.math.vector.Vector3f; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.client.model.data.EmptyModelData; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.pipeline.BakedQuadBuilder; @@ -24,16 +24,16 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; -public class PipeBakedModel implements IBakedModel { - private static final Map SIDE_TRANSFORMS = new EnumMap<>(Direction.class); - private final IBakedModel core; - private final IBakedModel extension; - private final IBakedModel straight; - private final IBakedModel inventoryAttachment; - private final Map attachmentModels; +public class PipeBakedModel implements BakedModel { + private static final Map SIDE_TRANSFORMS = new EnumMap<>(Direction.class); + private final BakedModel core; + private final BakedModel extension; + private final BakedModel straight; + private final BakedModel inventoryAttachment; + private final Map attachmentModels; private final Map> cache = new ConcurrentHashMap<>(); - public PipeBakedModel(IBakedModel core, IBakedModel extension, IBakedModel straight, IBakedModel inventoryAttachment, Map attachmentModels) { + public PipeBakedModel(BakedModel core, BakedModel extension, BakedModel straight, BakedModel inventoryAttachment, Map attachmentModels) { this.core = core; this.extension = extension; this.straight = straight; @@ -41,6 +41,42 @@ public PipeBakedModel(IBakedModel core, IBakedModel extension, IBakedModel strai this.attachmentModels = attachmentModels; } + private static List getTransformedQuads(BakedModel model, Direction facing, PipeState state) { + Transformation transformation = SIDE_TRANSFORMS.computeIfAbsent(facing, face -> { + Quaternion quaternion; + if (face == Direction.UP) { + quaternion = TransformationHelper.quatFromXYZ(new Vector3f(90, 0, 0), true); + } else if (face == Direction.DOWN) { + quaternion = TransformationHelper.quatFromXYZ(new Vector3f(270, 0, 0), true); + } else { + double r = Math.PI * (360 - face.getOpposite().get2DDataValue() * 90) / 180d; + + quaternion = TransformationHelper.quatFromXYZ(new Vector3f(0, (float) r, 0), false); + } + + return new Transformation(null, quaternion, null, null).blockCenterToCorner(); + }); + + ImmutableList.Builder quads = ImmutableList.builder(); + Direction side = state.getSide(); + + if (side != null && side.get2DDataValue() > -1) { + int faceOffset = 4 + Direction.NORTH.get2DDataValue() - facing.get2DDataValue(); + side = Direction.from2DDataValue((side.get2DDataValue() + faceOffset) % 4); + } + + for (BakedQuad quad : model.getQuads(state.getState(), side, state.getRand(), EmptyModelData.INSTANCE)) { + BakedQuadBuilder builder = new BakedQuadBuilder(quad.getSprite()); + TRSRTransformer transformer = new TRSRTransformer(builder, transformation); + + quad.pipe(transformer); + + quads.add(builder.build()); + } + + return quads.build(); + } + @Override public List getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { return getQuads(state, side, rand, EmptyModelData.INSTANCE); @@ -49,7 +85,7 @@ public List getQuads(@Nullable BlockState state, @Nullable Direction @Nonnull @Override public List getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) { - PipeState pipeState = new PipeState(state, extraData.getData(PipeTileEntity.ATTACHMENTS_PROPERTY), side, rand); + PipeState pipeState = new PipeState(state, extraData.getData(PipeBlockEntity.ATTACHMENTS_PROPERTY), side, rand); return cache.computeIfAbsent(pipeState, this::createQuads); } @@ -58,12 +94,12 @@ private List createQuads(PipeState state) { List quads = new ArrayList<>(); if (state.getState() != null) { - boolean north = state.getState().get(PipeBlock.NORTH); - boolean east = state.getState().get(PipeBlock.EAST); - boolean south = state.getState().get(PipeBlock.SOUTH); - boolean west = state.getState().get(PipeBlock.WEST); - boolean up = state.getState().get(PipeBlock.UP); - boolean down = state.getState().get(PipeBlock.DOWN); + boolean north = state.getState().getValue(PipeBlock.NORTH); + boolean east = state.getState().getValue(PipeBlock.EAST); + boolean south = state.getState().getValue(PipeBlock.SOUTH); + boolean west = state.getState().getValue(PipeBlock.WEST); + boolean up = state.getState().getValue(PipeBlock.UP); + boolean down = state.getState().getValue(PipeBlock.DOWN); if (north && south && !east && !west && !up && !down) { quads.addAll(straight.getQuads(state.getState(), state.getSide(), state.getRand(), EmptyModelData.INSTANCE)); @@ -113,12 +149,12 @@ private List createQuads(PipeState state) { } if (state.getState() != null) { - boolean invNorth = state.getState().get(PipeBlock.INV_NORTH); - boolean invEast = state.getState().get(PipeBlock.INV_EAST); - boolean invSouth = state.getState().get(PipeBlock.INV_SOUTH); - boolean invWest = state.getState().get(PipeBlock.INV_WEST); - boolean invUp = state.getState().get(PipeBlock.INV_UP); - boolean invDown = state.getState().get(PipeBlock.INV_DOWN); + boolean invNorth = state.getState().getValue(PipeBlock.INV_NORTH); + boolean invEast = state.getState().getValue(PipeBlock.INV_EAST); + boolean invSouth = state.getState().getValue(PipeBlock.INV_SOUTH); + boolean invWest = state.getState().getValue(PipeBlock.INV_WEST); + boolean invUp = state.getState().getValue(PipeBlock.INV_UP); + boolean invDown = state.getState().getValue(PipeBlock.INV_DOWN); if (invNorth && !state.hasAttachmentState(Direction.NORTH)) { quads.addAll(getTransformedQuads(inventoryAttachment, Direction.NORTH, state)); @@ -148,45 +184,9 @@ private List createQuads(PipeState state) { return quads; } - private static List getTransformedQuads(IBakedModel model, Direction facing, PipeState state) { - TransformationMatrix transformation = SIDE_TRANSFORMS.computeIfAbsent(facing, face -> { - Quaternion quaternion; - if (face == Direction.UP) { - quaternion = TransformationHelper.quatFromXYZ(new Vector3f(90, 0, 0), true); - } else if (face == Direction.DOWN) { - quaternion = TransformationHelper.quatFromXYZ(new Vector3f(270, 0, 0), true); - } else { - double r = Math.PI * (360 - face.getOpposite().getHorizontalIndex() * 90) / 180d; - - quaternion = TransformationHelper.quatFromXYZ(new Vector3f(0, (float) r, 0), false); - } - - return new TransformationMatrix(null, quaternion, null, null).blockCenterToCorner(); - }); - - ImmutableList.Builder quads = ImmutableList.builder(); - Direction side = state.getSide(); - - if (side != null && side.getHorizontalIndex() > -1) { - int faceOffset = 4 + Direction.NORTH.getHorizontalIndex() - facing.getHorizontalIndex(); - side = Direction.byHorizontalIndex((side.getHorizontalIndex() + faceOffset) % 4); - } - - for (BakedQuad quad : model.getQuads(state.getState(), side, state.getRand(), EmptyModelData.INSTANCE)) { - BakedQuadBuilder builder = new BakedQuadBuilder(quad.func_187508_a()); - TRSRTransformer transformer = new TRSRTransformer(builder, transformation); - - quad.pipe(transformer); - - quads.add(builder.build()); - } - - return quads.build(); - } - @Override - public boolean isAmbientOcclusion() { - return core.isAmbientOcclusion(); + public boolean useAmbientOcclusion() { + return core.useAmbientOcclusion(); } @Override @@ -195,23 +195,23 @@ public boolean isGui3d() { } @Override - public boolean func_230044_c_() { + public boolean usesBlockLight() { return true; } @Override - public boolean isBuiltInRenderer() { - return core.isBuiltInRenderer(); + public boolean isCustomRenderer() { + return core.isCustomRenderer(); } @Override @SuppressWarnings("deprecation") - public TextureAtlasSprite getParticleTexture() { - return core.getParticleTexture(); + public TextureAtlasSprite getParticleIcon() { + return core.getParticleIcon(); } @Override - public ItemOverrideList getOverrides() { + public ItemOverrides getOverrides() { return core.getOverrides(); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/render/PipeState.java b/src/main/java/com/refinedmods/refinedpipes/render/PipeState.java index ebd6754..8760e5d 100644 --- a/src/main/java/com/refinedmods/refinedpipes/render/PipeState.java +++ b/src/main/java/com/refinedmods/refinedpipes/render/PipeState.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedpipes.render; -import net.minecraft.block.BlockState; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.state.BlockState; import javax.annotation.Nullable; import java.util.Arrays; diff --git a/src/main/java/com/refinedmods/refinedpipes/screen/BaseScreen.java b/src/main/java/com/refinedmods/refinedpipes/screen/BaseScreen.java index 701d760..b2603f7 100644 --- a/src/main/java/com/refinedmods/refinedpipes/screen/BaseScreen.java +++ b/src/main/java/com/refinedmods/refinedpipes/screen/BaseScreen.java @@ -1,59 +1,47 @@ package com.refinedmods.refinedpipes.screen; -import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; -import com.refinedmods.refinedpipes.container.BaseContainer; +import com.mojang.blaze3d.vertex.PoseStack; +import com.refinedmods.refinedpipes.container.BaseContainerMenu; import com.refinedmods.refinedpipes.container.slot.FluidFilterSlot; import com.refinedmods.refinedpipes.render.FluidRenderer; -import net.minecraft.client.gui.screen.inventory.ContainerScreen; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.ITextProperties; -import net.minecraft.util.text.StringTextComponent; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.client.gui.GuiUtils; -import java.util.ArrayList; -import java.util.List; - -public abstract class BaseScreen extends ContainerScreen { - private final List fluidTooltip = new ArrayList<>(1); - - public BaseScreen(T screenContainer, PlayerInventory inv, ITextComponent title) { +public abstract class BaseScreen extends AbstractContainerScreen { + public BaseScreen(T screenContainer, Inventory inv, Component title) { super(screenContainer, inv, title); - - fluidTooltip.add(StringTextComponent.EMPTY); } @Override - protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) { - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); + protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) { + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - for (FluidFilterSlot slot : container.getFluidSlots()) { + for (FluidFilterSlot slot : menu.getFluidSlots()) { FluidStack stack = slot.getFluidInventory().getFluid(slot.getSlotIndex()); if (stack.isEmpty()) { continue; } - FluidRenderer.INSTANCE.render(guiLeft + slot.xPos, guiTop + slot.yPos, stack); + FluidRenderer.INSTANCE.render(leftPos + slot.x, topPos + slot.y, stack); } } @Override - protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) { - for (FluidFilterSlot slot : container.getFluidSlots()) { + protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) { + for (FluidFilterSlot slot : menu.getFluidSlots()) { FluidStack stack = slot.getFluidInventory().getFluid(slot.getSlotIndex()); if (stack.isEmpty()) { continue; } - if (!isPointInRegion(slot.xPos, slot.yPos, 17, 17, mouseX, mouseY)) { + if (!isHovering(slot.x, slot.y, 17, 17, mouseX, mouseY)) { continue; } - fluidTooltip.set(0, stack.getDisplayName()); - - GuiUtils.drawHoveringText(matrixStack, fluidTooltip, mouseX - guiLeft, mouseY - guiTop, width, height, -1, font); + renderTooltip(poseStack, stack.getDisplayName(), mouseX - leftPos, mouseY - topPos); } } } diff --git a/src/main/java/com/refinedmods/refinedpipes/screen/ExtractorAttachmentScreen.java b/src/main/java/com/refinedmods/refinedpipes/screen/ExtractorAttachmentScreen.java index f248fe0..df4e8d8 100644 --- a/src/main/java/com/refinedmods/refinedpipes/screen/ExtractorAttachmentScreen.java +++ b/src/main/java/com/refinedmods/refinedpipes/screen/ExtractorAttachmentScreen.java @@ -1,31 +1,33 @@ package com.refinedmods.refinedpipes.screen; -import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import com.refinedmods.refinedpipes.RefinedPipes; -import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainer; +import com.refinedmods.refinedpipes.container.ExtractorAttachmentContainerMenu; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.BlacklistWhitelist; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.ExtractorAttachment; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.RedstoneMode; import com.refinedmods.refinedpipes.network.pipe.attachment.extractor.RoutingMode; import com.refinedmods.refinedpipes.screen.widget.IconButton; import com.refinedmods.refinedpipes.screen.widget.IconButtonPreset; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.*; -import net.minecraftforge.fml.client.gui.GuiUtils; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -public class ExtractorAttachmentScreen extends BaseScreen { +public class ExtractorAttachmentScreen extends BaseScreen { private static final ResourceLocation RESOURCE = new ResourceLocation(RefinedPipes.ID, "textures/gui/extractor_attachment.png"); - private final List tooltip = new ArrayList<>(); + private final List tooltip = new ArrayList<>(); private Button redstoneModeButton; private Button blacklistWhitelistButton; @@ -38,88 +40,88 @@ public class ExtractorAttachmentScreen extends BaseScreen setRedstoneMode((IconButton) btn, container.getRedstoneMode().next()) + getRedstoneModeText(menu.getRedstoneMode()), + btn -> setRedstoneMode((IconButton) btn, menu.getRedstoneMode().next()) )); - redstoneModeButton.active = container.getExtractorAttachmentType().getCanSetRedstoneMode(); + redstoneModeButton.active = menu.getExtractorAttachmentType().getCanSetRedstoneMode(); - blacklistWhitelistButton = addButton(new IconButton( - this.guiLeft + 55, - this.guiTop + 76, + blacklistWhitelistButton = this.addRenderableWidget(new IconButton( + this.leftPos + 55, + this.topPos + 76, IconButtonPreset.NORMAL, - getBlacklistWhitelistX(container.getBlacklistWhitelist()), + getBlacklistWhitelistX(menu.getBlacklistWhitelist()), 82, - getBlacklistWhitelistText(container.getBlacklistWhitelist()), - btn -> setBlacklistWhitelist((IconButton) btn, container.getBlacklistWhitelist().next()) + getBlacklistWhitelistText(menu.getBlacklistWhitelist()), + btn -> setBlacklistWhitelist((IconButton) btn, menu.getBlacklistWhitelist().next()) )); - blacklistWhitelistButton.active = container.getExtractorAttachmentType().getCanSetWhitelistBlacklist(); + blacklistWhitelistButton.active = menu.getExtractorAttachmentType().getCanSetWhitelistBlacklist(); - exactModeButton = addButton(new IconButton( - this.guiLeft + 78, - this.guiTop + 76, + exactModeButton = this.addRenderableWidget(new IconButton( + this.leftPos + 78, + this.topPos + 76, IconButtonPreset.NORMAL, - getExactModeX(container.isExactMode()), + getExactModeX(menu.isExactMode()), 103, - getExactModeText(container.isExactMode()), - btn -> setExactMode((IconButton) btn, !container.isExactMode()) + getExactModeText(menu.isExactMode()), + btn -> setExactMode((IconButton) btn, !menu.isExactMode()) )); - exactModeButton.active = container.getExtractorAttachmentType().getCanSetExactMode(); + exactModeButton.active = menu.getExtractorAttachmentType().getCanSetExactMode(); - if (!container.isFluidMode()) { - routingModeButton = addButton(new IconButton( - this.guiLeft + 101, - this.guiTop + 76, + if (!menu.isFluidMode()) { + routingModeButton = this.addRenderableWidget(new IconButton( + this.leftPos + 101, + this.topPos + 76, IconButtonPreset.NORMAL, - getRoutingModeX(container.getRoutingMode()), + getRoutingModeX(menu.getRoutingMode()), 194, - getRoutingModeText(container.getRoutingMode()), - btn -> setRoutingMode((IconButton) btn, container.getRoutingMode().next()) + getRoutingModeText(menu.getRoutingMode()), + btn -> setRoutingMode((IconButton) btn, menu.getRoutingMode().next()) )); - routingModeButton.active = container.getExtractorAttachmentType().getCanSetWhitelistBlacklist(); + routingModeButton.active = menu.getExtractorAttachmentType().getCanSetWhitelistBlacklist(); - plusButton = addButton(new IconButton( - this.guiLeft + 125, - this.guiTop + 76 - 3, + plusButton = this.addRenderableWidget(new IconButton( + this.leftPos + 125, + this.topPos + 76 - 3, IconButtonPreset.SMALL, 198, 19, - new StringTextComponent("+"), + new TextComponent("+"), btn -> updateStackSize(1) )); - minusButton = addButton(new IconButton( - this.guiLeft + 125, - this.guiTop + 76 + 14 - 3, + minusButton = this.addRenderableWidget(new IconButton( + this.leftPos + 125, + this.topPos + 76 + 14 - 3, IconButtonPreset.SMALL, 198, 34, - new StringTextComponent("-"), + new TextComponent("-"), btn -> updateStackSize(-1) )); - minusButton.active = container.getStackSize() > 0; - plusButton.active = container.getStackSize() < container.getExtractorAttachmentType().getItemsToExtract(); + minusButton.active = menu.getStackSize() > 0; + plusButton.active = menu.getStackSize() < menu.getExtractorAttachmentType().getItemsToExtract(); } } @@ -128,19 +130,19 @@ private void updateStackSize(int amount) { amount *= 4; } - int newAmount = container.getStackSize() + amount; + int newAmount = menu.getStackSize() + amount; if (newAmount < 0) { newAmount = 0; } - if (newAmount > container.getExtractorAttachmentType().getItemsToExtract()) { - newAmount = container.getExtractorAttachmentType().getItemsToExtract(); + if (newAmount > menu.getExtractorAttachmentType().getItemsToExtract()) { + newAmount = menu.getExtractorAttachmentType().getItemsToExtract(); } minusButton.active = newAmount > 0; - plusButton.active = newAmount < container.getExtractorAttachmentType().getItemsToExtract(); + plusButton.active = newAmount < menu.getExtractorAttachmentType().getItemsToExtract(); - container.setStackSize(newAmount); + menu.setStackSize(newAmount); } private int getRedstoneModeX(RedstoneMode redstoneMode) { @@ -156,15 +158,15 @@ private int getRedstoneModeX(RedstoneMode redstoneMode) { } } - private IFormattableTextComponent getRedstoneModeText(RedstoneMode redstoneMode) { - return new TranslationTextComponent("misc.refinedpipes.redstone_mode." + redstoneMode.toString().toLowerCase()); + private MutableComponent getRedstoneModeText(RedstoneMode redstoneMode) { + return new TranslatableComponent("misc.refinedpipes.redstone_mode." + redstoneMode.toString().toLowerCase()); } private void setRedstoneMode(IconButton button, RedstoneMode redstoneMode) { button.setMessage(getRedstoneModeText(redstoneMode)); button.setOverlayTexX(getRedstoneModeX(redstoneMode)); - container.setRedstoneMode(redstoneMode); + menu.setRedstoneMode(redstoneMode); } private int getBlacklistWhitelistX(BlacklistWhitelist blacklistWhitelist) { @@ -178,15 +180,15 @@ private int getBlacklistWhitelistX(BlacklistWhitelist blacklistWhitelist) { } } - private IFormattableTextComponent getBlacklistWhitelistText(BlacklistWhitelist blacklistWhitelist) { - return new TranslationTextComponent("misc.refinedpipes.mode." + blacklistWhitelist.toString().toLowerCase()); + private MutableComponent getBlacklistWhitelistText(BlacklistWhitelist blacklistWhitelist) { + return new TranslatableComponent("misc.refinedpipes.mode." + blacklistWhitelist.toString().toLowerCase()); } private void setBlacklistWhitelist(IconButton button, BlacklistWhitelist blacklistWhitelist) { button.setMessage(getBlacklistWhitelistText(blacklistWhitelist)); button.setOverlayTexX(getBlacklistWhitelistX(blacklistWhitelist)); - container.setBlacklistWhitelist(blacklistWhitelist); + menu.setBlacklistWhitelist(blacklistWhitelist); } private int getRoutingModeX(RoutingMode routingMode) { @@ -204,81 +206,82 @@ private int getRoutingModeX(RoutingMode routingMode) { } } - private IFormattableTextComponent getRoutingModeText(RoutingMode routingMode) { - return new TranslationTextComponent("misc.refinedpipes.routing_mode." + routingMode.toString().toLowerCase()); + private MutableComponent getRoutingModeText(RoutingMode routingMode) { + return new TranslatableComponent("misc.refinedpipes.routing_mode." + routingMode.toString().toLowerCase()); } private void setRoutingMode(IconButton button, RoutingMode routingMode) { button.setMessage(getRoutingModeText(routingMode)); button.setOverlayTexX(getRoutingModeX(routingMode)); - container.setRoutingMode(routingMode); + menu.setRoutingMode(routingMode); } private int getExactModeX(boolean exactMode) { return exactMode ? 177 : 198; } - private IFormattableTextComponent getExactModeText(boolean exactMode) { - return new TranslationTextComponent("misc.refinedpipes.exact_mode." + (exactMode ? "on" : "off")); + private MutableComponent getExactModeText(boolean exactMode) { + return new TranslatableComponent("misc.refinedpipes.exact_mode." + (exactMode ? "on" : "off")); } private void setExactMode(IconButton button, boolean exactMode) { button.setMessage(getExactModeText(exactMode)); button.setOverlayTexX(getExactModeX(exactMode)); - container.setExactMode(exactMode); + menu.setExactMode(exactMode); } @Override - protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) { - font.drawString(matrixStack, title.getString(), 7, 7, 4210752); - font.drawString(matrixStack, I18n.format("container.inventory"), 7, 103 - 4, 4210752); + protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) { + font.draw(poseStack, title.getString(), 7, 7, 4210752); + font.draw(poseStack, I18n.get("container.inventory"), 7, 103 - 4, 4210752); - if (!container.isFluidMode()) { - font.drawString(matrixStack, "" + container.getStackSize(), 143, 83, 4210752); + if (!menu.isFluidMode()) { + font.draw(poseStack, "" + menu.getStackSize(), 143, 83, 4210752); } - func_230459_a_(matrixStack, mouseX - guiLeft, mouseY - guiTop); + renderTooltip(poseStack, mouseX - leftPos, mouseY - topPos); tooltip.clear(); - if (blacklistWhitelistButton.isHovered()) { - tooltip.add(new TranslationTextComponent("misc.refinedpipes.mode")); - tooltip.add(getBlacklistWhitelistText(container.getBlacklistWhitelist()).mergeStyle(TextFormatting.GRAY)); - } else if (redstoneModeButton.isHovered()) { - tooltip.add(new TranslationTextComponent("misc.refinedpipes.redstone_mode")); - tooltip.add(getRedstoneModeText(container.getRedstoneMode()).mergeStyle(TextFormatting.GRAY)); - } else if (routingModeButton != null && routingModeButton.isHovered()) { - tooltip.add(new TranslationTextComponent("misc.refinedpipes.routing_mode")); - tooltip.add(getRoutingModeText(container.getRoutingMode()).mergeStyle(TextFormatting.GRAY)); - } else if (exactModeButton.isHovered()) { - tooltip.add(new TranslationTextComponent("misc.refinedpipes.exact_mode")); - tooltip.add(getExactModeText(container.isExactMode()).mergeStyle(TextFormatting.GRAY)); + if (blacklistWhitelistButton.isHoveredOrFocused()) { + tooltip.add(new TranslatableComponent("misc.refinedpipes.mode")); + tooltip.add(getBlacklistWhitelistText(menu.getBlacklistWhitelist()).withStyle(ChatFormatting.GRAY)); + } else if (redstoneModeButton.isHoveredOrFocused()) { + tooltip.add(new TranslatableComponent("misc.refinedpipes.redstone_mode")); + tooltip.add(getRedstoneModeText(menu.getRedstoneMode()).withStyle(ChatFormatting.GRAY)); + } else if (routingModeButton != null && routingModeButton.isHoveredOrFocused()) { + tooltip.add(new TranslatableComponent("misc.refinedpipes.routing_mode")); + tooltip.add(getRoutingModeText(menu.getRoutingMode()).withStyle(ChatFormatting.GRAY)); + } else if (exactModeButton.isHoveredOrFocused()) { + tooltip.add(new TranslatableComponent("misc.refinedpipes.exact_mode")); + tooltip.add(getExactModeText(menu.isExactMode()).withStyle(ChatFormatting.GRAY)); } if (!tooltip.isEmpty()) { - GuiUtils.drawHoveringText(matrixStack, tooltip, mouseX - guiLeft, mouseY - guiTop, width, height, -1, Minecraft.getInstance().fontRenderer); + renderComponentTooltip(poseStack, tooltip, mouseX - leftPos, mouseY - topPos); } - super.drawGuiContainerForegroundLayer(matrixStack, mouseX, mouseY); + super.renderLabels(poseStack, mouseX, mouseY); } @Override - protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) { - renderBackground(matrixStack); + protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) { + renderBackground(poseStack); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - this.minecraft.getTextureManager().bindTexture(RESOURCE); - int i = (this.width - this.xSize) / 2; - int j = (this.height - this.ySize) / 2; - this.blit(matrixStack, i, j, 0, 0, this.xSize, this.ySize); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.setShaderTexture(0, RESOURCE); + + int i = (this.width - this.imageWidth) / 2; + int j = (this.height - this.imageHeight) / 2; + this.blit(poseStack, i, j, 0, 0, this.imageWidth, this.imageHeight); int x = 43; int y = 18; for (int filterSlotId = 1; filterSlotId <= ExtractorAttachment.MAX_FILTER_SLOTS; ++filterSlotId) { - if (filterSlotId > container.getExtractorAttachmentType().getFilterSlots()) { - this.blit(matrixStack, i + x, j + y, 198, 0, 18, 18); + if (filterSlotId > menu.getExtractorAttachmentType().getFilterSlots()) { + this.blit(poseStack, i + x, j + y, 198, 0, 18, 18); } if (filterSlotId % 5 == 0) { @@ -289,6 +292,6 @@ protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float pa } } - super.drawGuiContainerBackgroundLayer(matrixStack, partialTicks, mouseX, mouseY); + super.renderBg(poseStack, partialTicks, mouseX, mouseY); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/screen/widget/IconButton.java b/src/main/java/com/refinedmods/refinedpipes/screen/widget/IconButton.java index 19df996..0b7a550 100644 --- a/src/main/java/com/refinedmods/refinedpipes/screen/widget/IconButton.java +++ b/src/main/java/com/refinedmods/refinedpipes/screen/widget/IconButton.java @@ -1,12 +1,11 @@ package com.refinedmods.refinedpipes.screen.widget; -import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import com.refinedmods.refinedpipes.RefinedPipes; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.client.gui.components.Button; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; public class IconButton extends Button { private static final ResourceLocation RESOURCE = new ResourceLocation(RefinedPipes.ID, "textures/gui/extractor_attachment.png"); @@ -15,7 +14,7 @@ public class IconButton extends Button { private int overlayTexX; private int overlayTexY; - public IconButton(int x, int y, IconButtonPreset preset, int overlayTexX, int overlayTexY, ITextComponent text, IPressable onPress) { + public IconButton(int x, int y, IconButtonPreset preset, int overlayTexX, int overlayTexY, Component text, OnPress onPress) { super(x, y, preset.getWidth(), preset.getHeight(), text, onPress); this.preset = preset; @@ -28,9 +27,8 @@ public void setOverlayTexX(int overlayTexX) { } @Override - public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - Minecraft minecraft = Minecraft.getInstance(); - minecraft.getTextureManager().bindTexture(RESOURCE); + public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) { + RenderSystem.setShaderTexture(0, RESOURCE); RenderSystem.disableDepthTest(); @@ -41,10 +39,10 @@ public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float y = preset.getYTexHover(); } - blit(matrixStack, this.x, this.y, preset.getXTex(), y, this.width, this.height, 256, 256); + blit(poseStack, this.x, this.y, preset.getXTex(), y, this.width, this.height, 256, 256); // Fiddling with -1 to remove the blue border - blit(matrixStack, this.x + 1, this.y + 1, overlayTexX + 1, overlayTexY + 1, this.width - 2, this.height - 2, 256, 256); + blit(poseStack, this.x + 1, this.y + 1, overlayTexX + 1, overlayTexY + 1, this.width - 2, this.height - 2, 256, 256); RenderSystem.enableDepthTest(); } diff --git a/src/main/java/com/refinedmods/refinedpipes/setup/ClientSetup.java b/src/main/java/com/refinedmods/refinedpipes/setup/ClientSetup.java index cdc6402..5e40b0b 100644 --- a/src/main/java/com/refinedmods/refinedpipes/setup/ClientSetup.java +++ b/src/main/java/com/refinedmods/refinedpipes/setup/ClientSetup.java @@ -1,30 +1,29 @@ package com.refinedmods.refinedpipes.setup; import com.refinedmods.refinedpipes.RefinedPipes; +import com.refinedmods.refinedpipes.RefinedPipesBlockEntities; import com.refinedmods.refinedpipes.RefinedPipesBlocks; -import com.refinedmods.refinedpipes.RefinedPipesContainers; -import com.refinedmods.refinedpipes.RefinedPipesTileEntities; +import com.refinedmods.refinedpipes.RefinedPipesContainerMenus; import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentFactory; import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentRegistry; import com.refinedmods.refinedpipes.network.pipe.energy.EnergyPipeType; import com.refinedmods.refinedpipes.network.pipe.fluid.FluidPipeType; import com.refinedmods.refinedpipes.network.pipe.item.ItemPipeType; -import com.refinedmods.refinedpipes.render.FluidPipeTileEntityRenderer; -import com.refinedmods.refinedpipes.render.ItemPipeTileEntityRenderer; +import com.refinedmods.refinedpipes.render.FluidPipeBlockEntityRenderer; +import com.refinedmods.refinedpipes.render.ItemPipeBlockEntityRenderer; import com.refinedmods.refinedpipes.render.PipeBakedModel; import com.refinedmods.refinedpipes.screen.ExtractorAttachmentScreen; -import net.minecraft.client.gui.ScreenManager; +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.RenderTypeLookup; -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraft.client.renderer.model.ModelResourceLocation; -import net.minecraft.util.ResourceLocation; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.resources.ResourceLocation; import net.minecraftforge.client.event.ModelBakeEvent; -import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.client.model.ForgeModelBakery; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -32,74 +31,72 @@ import java.util.Map; import java.util.Map.Entry; -public class ClientSetup { +public final class ClientSetup { private static final Logger LOGGER = LogManager.getLogger(ClientSetup.class); - public ClientSetup() { + private ClientSetup() { + } + + @SubscribeEvent + public static void onClientSetup(FMLClientSetupEvent e) { for (AttachmentFactory factory : AttachmentRegistry.INSTANCE.all()) { LOGGER.debug("Registering attachment model {}", factory.getModelLocation()); - ModelLoader.addSpecialModel(factory.getModelLocation()); + ForgeModelBakery.addSpecialModel(factory.getModelLocation()); } - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup); - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onModelBake); - for (String type : new String[]{"item", "fluid", "energy"}) { - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/basic/core")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/basic/extension")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/basic/straight")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/basic/core")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/basic/extension")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/basic/straight")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/improved/core")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/improved/extension")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/improved/straight")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/improved/core")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/improved/extension")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/improved/straight")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/advanced/core")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/advanced/extension")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/advanced/straight")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/advanced/core")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/advanced/extension")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/advanced/straight")); if (type.equals("fluid") || type.equals("energy")) { - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/elite/core")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/elite/extension")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/elite/straight")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/elite/core")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/elite/extension")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/elite/straight")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/ultimate/core")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/ultimate/extension")); - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/ultimate/straight")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/ultimate/core")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/ultimate/extension")); + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/" + type + "/ultimate/straight")); } } - ModelLoader.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/attachment/inventory_attachment")); - } + ForgeModelBakery.addSpecialModel(new ResourceLocation(RefinedPipes.ID + ":block/pipe/attachment/inventory_attachment")); - @SubscribeEvent - public void onClientSetup(FMLClientSetupEvent e) { - ScreenManager.registerFactory(RefinedPipesContainers.EXTRACTOR_ATTACHMENT, ExtractorAttachmentScreen::new); - - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.BASIC_ITEM_PIPE, RenderType.getCutout()); - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.IMPROVED_ITEM_PIPE, RenderType.getCutout()); - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.ADVANCED_ITEM_PIPE, RenderType.getCutout()); - - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.BASIC_FLUID_PIPE, RenderType.getCutout()); - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.IMPROVED_FLUID_PIPE, RenderType.getCutout()); - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.ADVANCED_FLUID_PIPE, RenderType.getCutout()); - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.ELITE_FLUID_PIPE, RenderType.getCutout()); - RenderTypeLookup.setRenderLayer(RefinedPipesBlocks.ULTIMATE_FLUID_PIPE, RenderType.getCutout()); - - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.BASIC_ITEM_PIPE, ItemPipeTileEntityRenderer::new); - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.IMPROVED_ITEM_PIPE, ItemPipeTileEntityRenderer::new); - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.ADVANCED_ITEM_PIPE, ItemPipeTileEntityRenderer::new); - - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.BASIC_FLUID_PIPE, FluidPipeTileEntityRenderer::new); - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.IMPROVED_FLUID_PIPE, FluidPipeTileEntityRenderer::new); - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.ADVANCED_FLUID_PIPE, FluidPipeTileEntityRenderer::new); - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.ELITE_FLUID_PIPE, FluidPipeTileEntityRenderer::new); - ClientRegistry.bindTileEntityRenderer(RefinedPipesTileEntities.ULTIMATE_FLUID_PIPE, FluidPipeTileEntityRenderer::new); + MenuScreens.register(RefinedPipesContainerMenus.EXTRACTOR_ATTACHMENT, ExtractorAttachmentScreen::new); + + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.BASIC_ITEM_PIPE, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.IMPROVED_ITEM_PIPE, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.ADVANCED_ITEM_PIPE, RenderType.cutout()); + + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.BASIC_FLUID_PIPE, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.IMPROVED_FLUID_PIPE, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.ADVANCED_FLUID_PIPE, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.ELITE_FLUID_PIPE, RenderType.cutout()); + ItemBlockRenderTypes.setRenderLayer(RefinedPipesBlocks.ULTIMATE_FLUID_PIPE, RenderType.cutout()); + + BlockEntityRenderers.register(RefinedPipesBlockEntities.BASIC_ITEM_PIPE, ctx -> new ItemPipeBlockEntityRenderer()); + BlockEntityRenderers.register(RefinedPipesBlockEntities.IMPROVED_ITEM_PIPE, ctx -> new ItemPipeBlockEntityRenderer()); + BlockEntityRenderers.register(RefinedPipesBlockEntities.ADVANCED_ITEM_PIPE, ctx -> new ItemPipeBlockEntityRenderer()); + + BlockEntityRenderers.register(RefinedPipesBlockEntities.BASIC_FLUID_PIPE, ctx -> new FluidPipeBlockEntityRenderer()); + BlockEntityRenderers.register(RefinedPipesBlockEntities.IMPROVED_FLUID_PIPE, ctx -> new FluidPipeBlockEntityRenderer()); + BlockEntityRenderers.register(RefinedPipesBlockEntities.ADVANCED_FLUID_PIPE, ctx -> new FluidPipeBlockEntityRenderer()); + BlockEntityRenderers.register(RefinedPipesBlockEntities.ELITE_FLUID_PIPE, ctx -> new FluidPipeBlockEntityRenderer()); + BlockEntityRenderers.register(RefinedPipesBlockEntities.ULTIMATE_FLUID_PIPE, ctx -> new FluidPipeBlockEntityRenderer()); } @SubscribeEvent - public void onModelBake(ModelBakeEvent e) { - Map attachmentModels = new HashMap<>(); + public static void onModelBake(ModelBakeEvent e) { + Map attachmentModels = new HashMap<>(); for (AttachmentFactory factory : AttachmentRegistry.INSTANCE.all()) { attachmentModels.put(factory.getId(), e.getModelRegistry().get(factory.getModelLocation())); @@ -209,7 +206,7 @@ public void onModelBake(ModelBakeEvent e) { } } - private boolean isPipeModel(ResourceLocation modelId, ResourceLocation pipeId) { + private static boolean isPipeModel(ResourceLocation modelId, ResourceLocation pipeId) { return modelId instanceof ModelResourceLocation && modelId.getNamespace().equals(RefinedPipes.ID) && modelId.getPath().equals(pipeId.getPath()) diff --git a/src/main/java/com/refinedmods/refinedpipes/setup/CommonSetup.java b/src/main/java/com/refinedmods/refinedpipes/setup/CommonSetup.java index aee77a9..8aa7839 100644 --- a/src/main/java/com/refinedmods/refinedpipes/setup/CommonSetup.java +++ b/src/main/java/com/refinedmods/refinedpipes/setup/CommonSetup.java @@ -5,6 +5,9 @@ import com.refinedmods.refinedpipes.block.EnergyPipeBlock; import com.refinedmods.refinedpipes.block.FluidPipeBlock; import com.refinedmods.refinedpipes.block.ItemPipeBlock; +import com.refinedmods.refinedpipes.blockentity.EnergyPipeBlockEntity; +import com.refinedmods.refinedpipes.blockentity.FluidPipeBlockEntity; +import com.refinedmods.refinedpipes.blockentity.ItemPipeBlockEntity; import com.refinedmods.refinedpipes.container.factory.ExtractorAttachmentContainerFactory; import com.refinedmods.refinedpipes.item.AttachmentItem; import com.refinedmods.refinedpipes.item.EnergyPipeBlockItem; @@ -36,22 +39,25 @@ import com.refinedmods.refinedpipes.network.pipe.transport.callback.ItemInsertTransportCallback; import com.refinedmods.refinedpipes.network.pipe.transport.callback.ItemPipeGoneTransportCallback; import com.refinedmods.refinedpipes.network.pipe.transport.callback.TransportCallbackFactoryRegistry; -import com.refinedmods.refinedpipes.tile.EnergyPipeTileEntity; -import com.refinedmods.refinedpipes.tile.FluidPipeTileEntity; -import com.refinedmods.refinedpipes.tile.ItemPipeTileEntity; -import net.minecraft.block.Block; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.item.Item; -import net.minecraft.tileentity.TileEntityType; -import net.minecraftforge.common.extensions.IForgeContainerType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraftforge.common.extensions.IForgeMenuType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent; -public class CommonSetup { - private final PipeShapeCache pipeShapeCache = new PipeShapeCache(new PipeShapeFactory()); +public final class CommonSetup { + private static final PipeShapeCache PIPE_SHAPE_CACHE = new PipeShapeCache(new PipeShapeFactory()); - public CommonSetup() { + private CommonSetup() { + } + + @SubscribeEvent + public static void onConstructMod(FMLConstructModEvent e) { NetworkRegistry.INSTANCE.addFactory(ItemNetwork.TYPE, new ItemNetworkFactory()); for (FluidPipeType pipeType : FluidPipeType.values()) { @@ -75,31 +81,34 @@ public CommonSetup() { TransportCallbackFactoryRegistry.INSTANCE.addFactory(ItemInsertTransportCallback.ID, ItemInsertTransportCallback::of); TransportCallbackFactoryRegistry.INSTANCE.addFactory(ItemBounceBackTransportCallback.ID, ItemBounceBackTransportCallback::of); TransportCallbackFactoryRegistry.INSTANCE.addFactory(ItemPipeGoneTransportCallback.ID, ItemPipeGoneTransportCallback::of); + } + @SubscribeEvent + public static void onCommonSetup(FMLCommonSetupEvent e) { RefinedPipes.NETWORK.register(); } @SubscribeEvent - public void onRegisterBlocks(RegistryEvent.Register e) { - e.getRegistry().register(new ItemPipeBlock(pipeShapeCache, ItemPipeType.BASIC)); - e.getRegistry().register(new ItemPipeBlock(pipeShapeCache, ItemPipeType.IMPROVED)); - e.getRegistry().register(new ItemPipeBlock(pipeShapeCache, ItemPipeType.ADVANCED)); - - e.getRegistry().register(new FluidPipeBlock(pipeShapeCache, FluidPipeType.BASIC)); - e.getRegistry().register(new FluidPipeBlock(pipeShapeCache, FluidPipeType.IMPROVED)); - e.getRegistry().register(new FluidPipeBlock(pipeShapeCache, FluidPipeType.ADVANCED)); - e.getRegistry().register(new FluidPipeBlock(pipeShapeCache, FluidPipeType.ELITE)); - e.getRegistry().register(new FluidPipeBlock(pipeShapeCache, FluidPipeType.ULTIMATE)); - - e.getRegistry().register(new EnergyPipeBlock(pipeShapeCache, EnergyPipeType.BASIC)); - e.getRegistry().register(new EnergyPipeBlock(pipeShapeCache, EnergyPipeType.IMPROVED)); - e.getRegistry().register(new EnergyPipeBlock(pipeShapeCache, EnergyPipeType.ADVANCED)); - e.getRegistry().register(new EnergyPipeBlock(pipeShapeCache, EnergyPipeType.ELITE)); - e.getRegistry().register(new EnergyPipeBlock(pipeShapeCache, EnergyPipeType.ULTIMATE)); + public static void onRegisterBlocks(RegistryEvent.Register e) { + e.getRegistry().register(new ItemPipeBlock(PIPE_SHAPE_CACHE, ItemPipeType.BASIC)); + e.getRegistry().register(new ItemPipeBlock(PIPE_SHAPE_CACHE, ItemPipeType.IMPROVED)); + e.getRegistry().register(new ItemPipeBlock(PIPE_SHAPE_CACHE, ItemPipeType.ADVANCED)); + + e.getRegistry().register(new FluidPipeBlock(PIPE_SHAPE_CACHE, FluidPipeType.BASIC)); + e.getRegistry().register(new FluidPipeBlock(PIPE_SHAPE_CACHE, FluidPipeType.IMPROVED)); + e.getRegistry().register(new FluidPipeBlock(PIPE_SHAPE_CACHE, FluidPipeType.ADVANCED)); + e.getRegistry().register(new FluidPipeBlock(PIPE_SHAPE_CACHE, FluidPipeType.ELITE)); + e.getRegistry().register(new FluidPipeBlock(PIPE_SHAPE_CACHE, FluidPipeType.ULTIMATE)); + + e.getRegistry().register(new EnergyPipeBlock(PIPE_SHAPE_CACHE, EnergyPipeType.BASIC)); + e.getRegistry().register(new EnergyPipeBlock(PIPE_SHAPE_CACHE, EnergyPipeType.IMPROVED)); + e.getRegistry().register(new EnergyPipeBlock(PIPE_SHAPE_CACHE, EnergyPipeType.ADVANCED)); + e.getRegistry().register(new EnergyPipeBlock(PIPE_SHAPE_CACHE, EnergyPipeType.ELITE)); + e.getRegistry().register(new EnergyPipeBlock(PIPE_SHAPE_CACHE, EnergyPipeType.ULTIMATE)); } @SubscribeEvent - public void onRegisterItems(RegistryEvent.Register e) { + public static void onRegisterItems(RegistryEvent.Register e) { e.getRegistry().register(new ItemPipeBlockItem(RefinedPipesBlocks.BASIC_ITEM_PIPE)); e.getRegistry().register(new ItemPipeBlockItem(RefinedPipesBlocks.IMPROVED_ITEM_PIPE)); e.getRegistry().register(new ItemPipeBlockItem(RefinedPipesBlocks.ADVANCED_ITEM_PIPE)); @@ -122,32 +131,32 @@ public void onRegisterItems(RegistryEvent.Register e) { } @SubscribeEvent - public void onRegisterTileEntities(RegistryEvent.Register> e) { - e.getRegistry().register(TileEntityType.Builder.create(() -> new ItemPipeTileEntity(ItemPipeType.BASIC), RefinedPipesBlocks.BASIC_ITEM_PIPE).build(null).setRegistryName(ItemPipeType.BASIC.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new ItemPipeTileEntity(ItemPipeType.IMPROVED), RefinedPipesBlocks.IMPROVED_ITEM_PIPE).build(null).setRegistryName(ItemPipeType.IMPROVED.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new ItemPipeTileEntity(ItemPipeType.ADVANCED), RefinedPipesBlocks.ADVANCED_ITEM_PIPE).build(null).setRegistryName(ItemPipeType.ADVANCED.getId())); - - e.getRegistry().register(TileEntityType.Builder.create(() -> new FluidPipeTileEntity(FluidPipeType.BASIC), RefinedPipesBlocks.BASIC_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.BASIC.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new FluidPipeTileEntity(FluidPipeType.IMPROVED), RefinedPipesBlocks.IMPROVED_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.IMPROVED.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new FluidPipeTileEntity(FluidPipeType.ADVANCED), RefinedPipesBlocks.ADVANCED_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.ADVANCED.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new FluidPipeTileEntity(FluidPipeType.ELITE), RefinedPipesBlocks.ELITE_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.ELITE.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new FluidPipeTileEntity(FluidPipeType.ULTIMATE), RefinedPipesBlocks.ULTIMATE_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.ULTIMATE.getId())); - - e.getRegistry().register(TileEntityType.Builder.create(() -> new EnergyPipeTileEntity(EnergyPipeType.BASIC), RefinedPipesBlocks.BASIC_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.BASIC.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new EnergyPipeTileEntity(EnergyPipeType.IMPROVED), RefinedPipesBlocks.IMPROVED_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.IMPROVED.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new EnergyPipeTileEntity(EnergyPipeType.ADVANCED), RefinedPipesBlocks.ADVANCED_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.ADVANCED.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new EnergyPipeTileEntity(EnergyPipeType.ELITE), RefinedPipesBlocks.ELITE_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.ELITE.getId())); - e.getRegistry().register(TileEntityType.Builder.create(() -> new EnergyPipeTileEntity(EnergyPipeType.ULTIMATE), RefinedPipesBlocks.ULTIMATE_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.ULTIMATE.getId())); + public static void onRegisterBlockEntities(RegistryEvent.Register> e) { + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new ItemPipeBlockEntity(pos, state, ItemPipeType.BASIC), RefinedPipesBlocks.BASIC_ITEM_PIPE).build(null).setRegistryName(ItemPipeType.BASIC.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new ItemPipeBlockEntity(pos, state, ItemPipeType.IMPROVED), RefinedPipesBlocks.IMPROVED_ITEM_PIPE).build(null).setRegistryName(ItemPipeType.IMPROVED.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new ItemPipeBlockEntity(pos, state, ItemPipeType.ADVANCED), RefinedPipesBlocks.ADVANCED_ITEM_PIPE).build(null).setRegistryName(ItemPipeType.ADVANCED.getId())); + + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new FluidPipeBlockEntity(pos, state, FluidPipeType.BASIC), RefinedPipesBlocks.BASIC_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.BASIC.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new FluidPipeBlockEntity(pos, state, FluidPipeType.IMPROVED), RefinedPipesBlocks.IMPROVED_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.IMPROVED.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new FluidPipeBlockEntity(pos, state, FluidPipeType.ADVANCED), RefinedPipesBlocks.ADVANCED_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.ADVANCED.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new FluidPipeBlockEntity(pos, state, FluidPipeType.ELITE), RefinedPipesBlocks.ELITE_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.ELITE.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new FluidPipeBlockEntity(pos, state, FluidPipeType.ULTIMATE), RefinedPipesBlocks.ULTIMATE_FLUID_PIPE).build(null).setRegistryName(FluidPipeType.ULTIMATE.getId())); + + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new EnergyPipeBlockEntity(pos, state, EnergyPipeType.BASIC), RefinedPipesBlocks.BASIC_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.BASIC.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new EnergyPipeBlockEntity(pos, state, EnergyPipeType.IMPROVED), RefinedPipesBlocks.IMPROVED_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.IMPROVED.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new EnergyPipeBlockEntity(pos, state, EnergyPipeType.ADVANCED), RefinedPipesBlocks.ADVANCED_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.ADVANCED.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new EnergyPipeBlockEntity(pos, state, EnergyPipeType.ELITE), RefinedPipesBlocks.ELITE_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.ELITE.getId())); + e.getRegistry().register(BlockEntityType.Builder.of((pos, state) -> new EnergyPipeBlockEntity(pos, state, EnergyPipeType.ULTIMATE), RefinedPipesBlocks.ULTIMATE_ENERGY_PIPE).build(null).setRegistryName(EnergyPipeType.ULTIMATE.getId())); } @SubscribeEvent - public void onRegisterContainers(RegistryEvent.Register> e) { - e.getRegistry().register(IForgeContainerType.create(new ExtractorAttachmentContainerFactory()).setRegistryName(RefinedPipes.ID, "extractor_attachment")); + public static void onRegisterContainerMenus(RegistryEvent.Register> e) { + e.getRegistry().register(IForgeMenuType.create(new ExtractorAttachmentContainerFactory()).setRegistryName(RefinedPipes.ID, "extractor_attachment")); } @SubscribeEvent - public void onWorldTick(TickEvent.WorldTickEvent e) { - if (!e.world.isRemote && e.phase == TickEvent.Phase.END) { + public static void onLevelTick(TickEvent.WorldTickEvent e) { + if (!e.world.isClientSide && e.phase == TickEvent.Phase.END) { NetworkManager.get(e.world).getNetworks().forEach(n -> n.update(e.world)); } } diff --git a/src/main/java/com/refinedmods/refinedpipes/tile/BaseTileEntity.java b/src/main/java/com/refinedmods/refinedpipes/tile/BaseTileEntity.java deleted file mode 100644 index c1c2f1f..0000000 --- a/src/main/java/com/refinedmods/refinedpipes/tile/BaseTileEntity.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.refinedmods.refinedpipes.tile; - -import net.minecraft.block.BlockState; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.play.server.SUpdateTileEntityPacket; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityType; - -public abstract class BaseTileEntity extends TileEntity { - public BaseTileEntity(TileEntityType type) { - super(type); - } - - @Override - public final CompoundNBT getUpdateTag() { - return writeUpdate(super.getUpdateTag()); - } - - @Override - public final SUpdateTileEntityPacket getUpdatePacket() { - return new SUpdateTileEntityPacket(pos, 1, getUpdateTag()); - } - - @Override - public final void onDataPacket(net.minecraft.network.NetworkManager net, SUpdateTileEntityPacket packet) { - readUpdate(packet.getNbtCompound()); - } - - @Override - public final void handleUpdateTag(BlockState state, CompoundNBT tag) { - super.read(state, tag); - - readUpdate(tag); - } - - public CompoundNBT writeUpdate(CompoundNBT tag) { - return tag; - } - - public void readUpdate(CompoundNBT tag) { - } -} diff --git a/src/main/java/com/refinedmods/refinedpipes/tile/PipeTileEntity.java b/src/main/java/com/refinedmods/refinedpipes/tile/PipeTileEntity.java deleted file mode 100644 index 00e84da..0000000 --- a/src/main/java/com/refinedmods/refinedpipes/tile/PipeTileEntity.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.refinedmods.refinedpipes.tile; - -import com.refinedmods.refinedpipes.network.NetworkManager; -import com.refinedmods.refinedpipes.network.pipe.Pipe; -import com.refinedmods.refinedpipes.network.pipe.attachment.Attachment; -import com.refinedmods.refinedpipes.network.pipe.attachment.AttachmentManager; -import com.refinedmods.refinedpipes.network.pipe.attachment.ClientAttachmentManager; -import com.refinedmods.refinedpipes.network.pipe.attachment.DummyAttachmentManager; -import net.minecraft.block.BlockState; -import net.minecraft.inventory.InventoryHelper; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.client.model.data.IModelData; -import net.minecraftforge.client.model.data.ModelDataMap; -import net.minecraftforge.client.model.data.ModelProperty; - -import javax.annotation.Nonnull; - -public abstract class PipeTileEntity extends BaseTileEntity { - public static final ModelProperty ATTACHMENTS_PROPERTY = new ModelProperty<>(); - - public PipeTileEntity(TileEntityType type) { - super(type); - } - - private final AttachmentManager clientAttachmentManager = new ClientAttachmentManager(); - - public AttachmentManager getAttachmentManager() { - if (world.isRemote) { - return clientAttachmentManager; - } - - Pipe pipe = NetworkManager.get(world).getPipe(pos); - - if (pipe != null) { - return pipe.getAttachmentManager(); - } - - return DummyAttachmentManager.INSTANCE; - } - - @Override - public void validate() { - super.validate(); - - if (!world.isRemote) { - NetworkManager mgr = NetworkManager.get(world); - - if (mgr.getPipe(pos) == null) { - mgr.addPipe(createPipe(world, pos)); - } - } - } - - @Override - public void remove() { - super.remove(); - - if (!world.isRemote) { - NetworkManager mgr = NetworkManager.get(world); - - Pipe pipe = mgr.getPipe(pos); - if (pipe != null) { - spawnDrops(pipe); - - for (Attachment attachment : pipe.getAttachmentManager().getAttachments()) { - InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), attachment.getDrop()); - } - } - - mgr.removePipe(pos); - } - } - - protected void spawnDrops(Pipe pipe) { - } - - @Nonnull - @Override - public IModelData getModelData() { - return new ModelDataMap.Builder().withInitial(ATTACHMENTS_PROPERTY, getAttachmentManager().getState()).build(); - } - - @Override - public CompoundNBT writeUpdate(CompoundNBT tag) { - getAttachmentManager().writeUpdate(tag); - - return tag; - } - - @Override - public void readUpdate(CompoundNBT tag) { - getAttachmentManager().readUpdate(tag); - - requestModelDataUpdate(); - - BlockState state = world.getBlockState(pos); - world.notifyBlockUpdate(pos, state, state, 1 | 2); - } - - protected abstract Pipe createPipe(World world, BlockPos pos); -} diff --git a/src/main/java/com/refinedmods/refinedpipes/util/DirectionUtil.java b/src/main/java/com/refinedmods/refinedpipes/util/DirectionUtil.java index ed437b2..97d057d 100644 --- a/src/main/java/com/refinedmods/refinedpipes/util/DirectionUtil.java +++ b/src/main/java/com/refinedmods/refinedpipes/util/DirectionUtil.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.util; -import net.minecraft.util.Direction; +import net.minecraft.core.Direction; public class DirectionUtil { public static Direction safeGet(byte d) { diff --git a/src/main/java/com/refinedmods/refinedpipes/util/FluidUtil.java b/src/main/java/com/refinedmods/refinedpipes/util/FluidUtil.java index ad1ac19..1efde22 100644 --- a/src/main/java/com/refinedmods/refinedpipes/util/FluidUtil.java +++ b/src/main/java/com/refinedmods/refinedpipes/util/FluidUtil.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedpipes.util; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; diff --git a/src/main/java/com/refinedmods/refinedpipes/util/Raytracer.java b/src/main/java/com/refinedmods/refinedpipes/util/Raytracer.java index 40d80f3..7f44c5b 100644 --- a/src/main/java/com/refinedmods/refinedpipes/util/Raytracer.java +++ b/src/main/java/com/refinedmods/refinedpipes/util/Raytracer.java @@ -1,9 +1,13 @@ package com.refinedmods.refinedpipes.util; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.util.math.*; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.ForgeMod; import org.apache.commons.lang3.tuple.Pair; @@ -12,31 +16,31 @@ // https://github.com/mekanism/Mekanism/blob/9a3fe1a5d78bb38fa963a3bcbc8d3846412315e4/src/main/java/mekanism/common/util/MultipartUtils.java public class Raytracer { - public static Pair getVectors(Entity entity) { - float pitch = entity.rotationPitch; - float yaw = entity.rotationYaw; - Vector3d start = new Vector3d(entity.getPosX(), entity.getPosY() + entity.getEyeHeight(), entity.getPosZ()); - float f1 = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI); - float f2 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI); - float f3 = -MathHelper.cos(-pitch * 0.017453292F); - float f4 = MathHelper.sin(-pitch * 0.017453292F); + public static Pair getVectors(Entity entity) { + float pitch = entity.getXRot(); + float yaw = entity.getYRot(); + Vec3 start = new Vec3(entity.getX(), entity.getY() + entity.getEyeHeight(), entity.getZ()); + float f1 = Mth.cos(-yaw * 0.017453292F - (float) Math.PI); + float f2 = Mth.sin(-yaw * 0.017453292F - (float) Math.PI); + float f3 = -Mth.cos(-pitch * 0.017453292F); + float f4 = Mth.sin(-pitch * 0.017453292F); float f5 = f2 * f3; float f6 = f1 * f3; double d3 = 5.0D; - if (entity instanceof ServerPlayerEntity) { - d3 = ((ServerPlayerEntity) entity).getAttribute(ForgeMod.REACH_DISTANCE.get()).getValue(); + if (entity instanceof ServerPlayer) { + d3 = ((ServerPlayer) entity).getAttribute(ForgeMod.REACH_DISTANCE.get()).getValue(); } - Vector3d end = start.add(f5 * d3, f4 * d3, f6 * d3); + Vec3 end = start.add(f5 * d3, f4 * d3, f6 * d3); return Pair.of(start, end); } - public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vector3d start, Vector3d end, Collection boxes) { + public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3 start, Vec3 end, Collection boxes) { double minDistance = Double.POSITIVE_INFINITY; - AdvancedRayTraceResult hit = null; + AdvancedRayTraceResult hit = null; int i = -1; - for (AxisAlignedBB aabb : boxes) { - AdvancedRayTraceResult result = aabb == null ? null : collisionRayTrace(pos, start, end, aabb, i, null); + for (AABB aabb : boxes) { + AdvancedRayTraceResult result = aabb == null ? null : collisionRayTrace(pos, start, end, aabb, i, null); if (result != null) { double d = result.squareDistanceTo(start); if (d < minDistance) { @@ -50,42 +54,34 @@ public static AdvancedRayTraceResult collisionRayTrace(Bloc return hit; } - public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vector3d start, Vector3d end, AxisAlignedBB bounds, int subHit, Object hitInfo) { - BlockRayTraceResult result = AxisAlignedBB.rayTrace(Collections.singleton(bounds), start, end, pos); + public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3 start, Vec3 end, AABB bounds, int subHit, Object hitInfo) { + BlockHitResult result = AABB.clip(Collections.singleton(bounds), start, end, pos); if (result == null) { return null; } - - result.subHit = subHit; - result.hitInfo = hitInfo; - return new AdvancedRayTraceResult<>(result, bounds); } - public static class AdvancedRayTraceResult { - public final AxisAlignedBB bounds; + public static boolean inclusiveContains(AABB aabb, Vec3 hit) { + return hit.x >= aabb.minX + && hit.x <= aabb.maxX + && hit.y >= aabb.minY + && hit.y <= aabb.maxY + && hit.z >= aabb.minZ + && hit.z <= aabb.maxZ; + } + + public static class AdvancedRayTraceResult { + public final AABB bounds; public final T hit; - public AdvancedRayTraceResult(T mop, AxisAlignedBB aabb) { + public AdvancedRayTraceResult(T mop, AABB aabb) { hit = mop; bounds = aabb; } - public boolean valid() { - return hit != null && bounds != null; + public double squareDistanceTo(Vec3 vec) { + return hit.getLocation().distanceToSqr(vec); } - - public double squareDistanceTo(Vector3d vec) { - return hit.getHitVec().squareDistanceTo(vec); - } - } - - public static boolean inclusiveContains(AxisAlignedBB aabb, Vector3d hit) { - return hit.x >= aabb.minX - && hit.x <= aabb.maxX - && hit.y >= aabb.minY - && hit.y <= aabb.maxY - && hit.z >= aabb.minZ - && hit.z <= aabb.maxZ; } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index f15d63a..b0c0061 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,12 +1,11 @@ modLoader="javafml" -loaderVersion="[36,)" +loaderVersion="[39,)" issueTrackerURL="https://github.com/refinedmods/refinedpipes" license="MIT" [[mods]] modId="refinedpipes" version="${version}" displayName="Refined Pipes" -updateJSONURL="https://refinedmods.com/refined-pipes/update.json" displayURL="https://refinedmods.com/refined-pipes" authors="Refined Mods" description=''' diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index bc8ac4d..57ecf30 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { "description": "Refined Pipes resources", - "pack_format": 6 + "pack_format": 8 } }