Initial port to 1.21.1
TODO: * Fix the ghost block rendering * Fix the placement canceling on setting coordinates
This commit is contained in:
40
build.gradle
40
build.gradle
@@ -9,7 +9,7 @@ plugins {
|
||||
|
||||
jarJar.enable()
|
||||
|
||||
boolean flywheelInWorkspace = findProject(':Flywheel') != null
|
||||
boolean ponderInWorkspace = findProject(':Ponder') != null
|
||||
|
||||
ext.buildNumber = System.getenv('BUILD_NUMBER')
|
||||
|
||||
@@ -19,7 +19,7 @@ base {
|
||||
archivesName = "effortlessbuilding-${artifact_minecraft_version}"
|
||||
}
|
||||
|
||||
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
||||
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||
|
||||
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + ' (' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
|
||||
|
||||
@@ -47,9 +47,9 @@ runs {
|
||||
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
|
||||
systemProperty 'neoforge.enabledGameTestNamespaces', "effortlessbuilding"
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
if (ponderInWorkspace) {
|
||||
dependencies {
|
||||
runtime project(':Flywheel')
|
||||
runtime project(':Ponder')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,11 @@ repositories {
|
||||
name = 'tterrag maven'
|
||||
url = 'https://maven.tterrag.com'
|
||||
}
|
||||
maven {
|
||||
// Ponder, Flywheel
|
||||
url = "https://maven.createmod.net"
|
||||
}
|
||||
maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven" } // NeoForge config api port, needed by ponder
|
||||
exclusiveContent {
|
||||
forRepository {
|
||||
maven {
|
||||
@@ -101,15 +106,24 @@ repositories {
|
||||
dependencies {
|
||||
implementation "net.neoforged:neoforge:${neo_version}"
|
||||
|
||||
jarJar("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") {
|
||||
version { prefer "0.6.10" }
|
||||
jarJar("dev.engine-room.flywheel:flywheel-neoforge-${flywheel_minecraft_version}:${flywheel_version}") {
|
||||
version {
|
||||
strictly "[1.0.0-9,2.0)"
|
||||
}
|
||||
}
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
implementation project(':Flywheel')
|
||||
compileOnly("dev.engine-room.flywheel:flywheel-neoforge-api-${flywheel_minecraft_version}:${flywheel_version}")
|
||||
runtimeOnly("dev.engine-room.flywheel:flywheel-neoforge-${flywheel_minecraft_version}:${flywheel_version}")
|
||||
runtimeOnly("dev.engine-room.vanillin:vanillin-neoforge-${flywheel_minecraft_version}:${vanillin_version}")
|
||||
|
||||
if (ponderInWorkspace) {
|
||||
implementation(project(":ponder:Common"))
|
||||
implementation(project(":ponder:NeoForge"))
|
||||
} else {
|
||||
implementation "com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}"
|
||||
implementation("net.createmod.ponder:Ponder-NeoForge-${minecraft_version}:${ponder_version}")
|
||||
}
|
||||
|
||||
jarJar("net.createmod.ponder:Ponder-NeoForge-${minecraft_version}:${ponder_version}")
|
||||
}
|
||||
|
||||
sourceSets.main.resources {
|
||||
@@ -120,6 +134,14 @@ tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
|
||||
}
|
||||
|
||||
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
|
||||
idea {
|
||||
module {
|
||||
downloadSources = true
|
||||
downloadJavadoc = true
|
||||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.compilerArgs = ['-Xdiags:verbose']
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
mod_version = 3.5
|
||||
artifact_minecraft_version = 1.20.4
|
||||
artifact_minecraft_version = 1.21.1
|
||||
|
||||
minecraft_version = 1.20.4
|
||||
neo_version = 20.4.232
|
||||
neogradle.subsystems.parchment.minecraftVersion = 1.20.4
|
||||
neogradle.subsystems.parchment.mappingsVersion = 2024.02.25
|
||||
minecraft_version = 1.21.1
|
||||
neo_version = 21.1.127
|
||||
neogradle.subsystems.parchment.minecraftVersion = 1.21.1
|
||||
neogradle.subsystems.parchment.mappingsVersion = 2024.11.17
|
||||
neogradle.subsystems.conventions.runs.create-default-run-per-type = false
|
||||
|
||||
neogradle_version = 7.0.107
|
||||
neogradle_version = 7.0.181
|
||||
cursegradle_version = 1.4.0
|
||||
|
||||
flywheel_minecraft_version = 1.20.4
|
||||
flywheel_version = 0.6.10
|
||||
flywheel_minecraft_version = 1.21.1
|
||||
flywheel_version = 1.0.0-9
|
||||
vanillin_version = 1.0.0-beta-9
|
||||
ponder_version = 1.0.39
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
27
gradlew
vendored
27
gradlew
vendored
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -55,7 +57,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -83,7 +85,9 @@ done
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -130,10 +134,13 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
@@ -141,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
@@ -149,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -198,11 +205,11 @@ fi
|
||||
# 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"'
|
||||
|
||||
# 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.
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
|
||||
22
gradlew.bat
vendored
22
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.createmod.catnip.gui.UIRenderHelper;
|
||||
import net.createmod.catnip.gui.element.ScreenElement;
|
||||
import net.createmod.catnip.theme.Color;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
|
||||
public enum AllGuiTextures implements ScreenElement {
|
||||
ARRAY_ENTRY("modifiers", 226, 64),
|
||||
@@ -35,7 +35,7 @@ public enum AllGuiTextures implements ScreenElement {
|
||||
}
|
||||
|
||||
private AllGuiTextures(String namespace, String location, int startX, int startY, int width, int height) {
|
||||
this.location = new ResourceLocation(namespace, "textures/gui/" + location + ".png");
|
||||
this.location = ResourceLocation.fromNamespaceAndPath(namespace, "textures/gui/" + location + ".png");
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.startX = startX;
|
||||
|
||||
@@ -2,6 +2,9 @@ package nl.requios.effortlessbuilding;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.createmod.catnip.gui.element.DelegatedStencilElement;
|
||||
import net.createmod.catnip.gui.element.ScreenElement;
|
||||
import net.createmod.catnip.theme.Color;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
@@ -10,15 +13,11 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.DelegatedStencilElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public class AllIcons implements ScreenElement {
|
||||
|
||||
public static final ResourceLocation ICON_ATLAS = Create.asResource("textures/gui/icons.png");
|
||||
public static final ResourceLocation ICON_ATLAS = EffortlessBuilding.asResource("textures/gui/icons.png");
|
||||
public static final int ICON_ATLAS_SIZE = 256;
|
||||
private static int x = 0, y = -1;
|
||||
private int iconX;
|
||||
@@ -101,7 +100,6 @@ public class AllIcons implements ScreenElement {
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int x, int y) {
|
||||
guiGraphics.blit(ICON_ATLAS, x, y, 0, iconX, iconY, 16, 16, 256, 256);
|
||||
}
|
||||
@@ -131,11 +129,10 @@ public class AllIcons implements ScreenElement {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) {
|
||||
builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||
.color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||
.uv(u, v)
|
||||
.uv2(light)
|
||||
.endVertex();
|
||||
builder.addVertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||
.setColor(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||
.setUv(u, v)
|
||||
.setLight(light);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
||||
@@ -2,7 +2,9 @@ package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.*;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.Builder;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.IntValue;
|
||||
|
||||
public class ClientConfig {
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@ import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.client.event.InputEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.neoforged.neoforge.client.event.ScreenEvent;
|
||||
import net.neoforged.neoforge.client.settings.KeyConflictContext;
|
||||
import net.neoforged.neoforge.client.settings.KeyModifier;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod.EventBusSubscriber;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.gui.buildmode.PlayerSettingsGui;
|
||||
import nl.requios.effortlessbuilding.gui.buildmode.RadialMenu;
|
||||
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifiersScreen;
|
||||
@@ -55,31 +55,31 @@ public class ClientEvents {
|
||||
// @SubscribeEvent
|
||||
// public static void registerShaders(RegisterShadersEvent event) throws IOException {
|
||||
// event.registerShader(new ShaderInstance(event.getResourceManager(),
|
||||
// new ResourceLocation(EffortlessBuilding.MODID, "dissolve"),
|
||||
// EffortlessBuilding.modLoc("dissolve"),
|
||||
// DefaultVertexFormat.BLOCK),
|
||||
// shaderInstance -> BuildRenderTypes.dissolveShaderInstance = shaderInstance);
|
||||
// }
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
public static void onClientTickPre(ClientTickEvent.Pre event) {
|
||||
if (!isGameActive()) return;
|
||||
|
||||
if (event.phase == TickEvent.Phase.START) {
|
||||
EffortlessBuildingClient.BUILDER_CHAIN.onTick();
|
||||
|
||||
EffortlessBuildingClient.BUILDER_CHAIN.onTick();
|
||||
onMouseInput();
|
||||
|
||||
onMouseInput();
|
||||
EffortlessBuildingClient.BLOCK_PREVIEWS.onTick();
|
||||
}
|
||||
|
||||
EffortlessBuildingClient.BLOCK_PREVIEWS.onTick();
|
||||
@SubscribeEvent
|
||||
public static void onClientTickPost(ClientTickEvent.Post event) {
|
||||
if (!isGameActive()) return;
|
||||
|
||||
} else if (event.phase == TickEvent.Phase.END) {
|
||||
Screen gui = Minecraft.getInstance().screen;
|
||||
if (gui == null || !gui.isPauseScreen()) {
|
||||
ticksInGame++;
|
||||
}
|
||||
Screen gui = Minecraft.getInstance().screen;
|
||||
if (gui == null || !gui.isPauseScreen()) {
|
||||
ticksInGame++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void onMouseInput() {
|
||||
|
||||
@@ -2,7 +2,8 @@ package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.*;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.Builder;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.IntValue;
|
||||
|
||||
public class CommonConfig {
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@ import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.LogicalSide;
|
||||
import net.neoforged.fml.common.Mod.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.common.util.FakePlayer;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||
import net.neoforged.neoforge.event.tick.LevelTickEvent;
|
||||
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
||||
@@ -37,10 +36,10 @@ public class CommonEvents {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTick(TickEvent.LevelTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (event.side == LogicalSide.CLIENT) return;
|
||||
if (event.level.dimension() != Level.OVERWORLD) return;
|
||||
public static void onTick(LevelTickEvent.Pre event) {
|
||||
Level level = event.getLevel();
|
||||
if (level.isClientSide) return;
|
||||
if (!level.dimension().equals(Level.OVERWORLD)) return;
|
||||
|
||||
EffortlessBuilding.SERVER_BLOCK_PLACER.tick();
|
||||
}
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.DistExecutor;
|
||||
import net.neoforged.fml.ModLoadingContext;
|
||||
import net.neoforged.fml.ModContainer;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.config.ModConfig;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.fml.loading.FMLEnvironment;
|
||||
import net.neoforged.neoforge.attachment.AttachmentType;
|
||||
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
|
||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
|
||||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
||||
@@ -39,7 +42,6 @@ import nl.requios.effortlessbuilding.item.ReachUpgrade3Item;
|
||||
import nl.requios.effortlessbuilding.item.SingleItemLootModifier;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.proxy.ClientProxy;
|
||||
import nl.requios.effortlessbuilding.proxy.IProxy;
|
||||
import nl.requios.effortlessbuilding.proxy.ServerProxy;
|
||||
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
||||
import nl.requios.effortlessbuilding.systems.ServerBlockPlacer;
|
||||
@@ -57,7 +59,6 @@ public class EffortlessBuilding {
|
||||
public static final Logger logger = LogManager.getLogger();
|
||||
|
||||
public static EffortlessBuilding instance;
|
||||
public static IProxy proxy = DistExecutor.unsafeRunForDist(() -> ClientProxy::new, () -> ServerProxy::new);
|
||||
|
||||
public static final ServerBlockPlacer SERVER_BLOCK_PLACER = new ServerBlockPlacer();
|
||||
public static final UndoRedo UNDO_REDO = new UndoRedo();
|
||||
@@ -66,7 +67,7 @@ public class EffortlessBuilding {
|
||||
//Registration
|
||||
private static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);
|
||||
private static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(BuiltInRegistries.MENU, EffortlessBuilding.MODID);
|
||||
private static final DeferredRegister<Codec<? extends IGlobalLootModifier>> LOOT_MODIFIERS = DeferredRegister.create(NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, EffortlessBuilding.MODID);
|
||||
private static final DeferredRegister<MapCodec<? extends IGlobalLootModifier>> LOOT_MODIFIERS = DeferredRegister.create(NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, EffortlessBuilding.MODID);
|
||||
private static final DeferredRegister<AttachmentType<?>> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, EffortlessBuilding.MODID);
|
||||
|
||||
public static final DeferredItem<RandomizerBagItem> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
|
||||
@@ -83,24 +84,19 @@ public class EffortlessBuilding {
|
||||
public static final Supplier<MenuType<GoldenRandomizerBagContainer>> GOLDEN_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("golden_randomizer_bag", () -> registerContainer(GoldenRandomizerBagContainer::new));
|
||||
public static final Supplier<MenuType<DiamondRandomizerBagContainer>> DIAMOND_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("diamond_randomizer_bag", () -> registerContainer(DiamondRandomizerBagContainer::new));
|
||||
|
||||
public static final Supplier<Codec<SingleItemLootModifier>> SINGLE_ITEM_LOOT_MODIFIER = EffortlessBuilding.LOOT_MODIFIERS.register("single_item_loot_modifier", SingleItemLootModifier.CODEC);
|
||||
public static final Supplier<MapCodec<SingleItemLootModifier>> SINGLE_ITEM_LOOT_MODIFIER = EffortlessBuilding.LOOT_MODIFIERS.register("single_item_loot_modifier", SingleItemLootModifier.CODEC);
|
||||
|
||||
public static final Supplier<AttachmentType<PowerLevel>> POWER_LEVEL = ATTACHMENT_TYPES.register("power_level", () -> AttachmentType.serializable(PowerLevel::new).build());
|
||||
|
||||
public EffortlessBuilding(IEventBus modEventBus) {
|
||||
public EffortlessBuilding(IEventBus modEventBus, ModContainer container, Dist dist) {
|
||||
instance = this;
|
||||
|
||||
ModLoadingContext modLoadingContext = ModLoadingContext.get();
|
||||
IEventBus forgeEventBus = NeoForge.EVENT_BUS;
|
||||
|
||||
modEventBus.addListener(EffortlessBuilding::setup);
|
||||
modEventBus.addListener(EffortlessBuilding::addTabContents);
|
||||
modEventBus.addListener(PacketHandler::setupPackets);
|
||||
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
EffortlessBuildingClient.onConstructorClient(modEventBus, forgeEventBus);
|
||||
}
|
||||
|
||||
ITEMS.register(modEventBus);
|
||||
CONTAINERS.register(modEventBus);
|
||||
|
||||
@@ -108,9 +104,13 @@ public class EffortlessBuilding {
|
||||
ATTACHMENT_TYPES.register(modEventBus);
|
||||
|
||||
//Register config
|
||||
modLoadingContext.registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
|
||||
modLoadingContext.registerConfig(ModConfig.Type.CLIENT, ClientConfig.spec);
|
||||
modLoadingContext.registerConfig(ModConfig.Type.SERVER, ServerConfig.spec);
|
||||
container.registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
|
||||
container.registerConfig(ModConfig.Type.SERVER, ServerConfig.spec);
|
||||
if (dist.isClient()) {
|
||||
container.registerConfig(ModConfig.Type.CLIENT, ClientConfig.spec);
|
||||
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
|
||||
EffortlessBuildingClient.onConstructorClient(modEventBus, forgeEventBus);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setup(final FMLCommonSetupEvent event) {
|
||||
@@ -143,11 +143,18 @@ public class EffortlessBuilding {
|
||||
|
||||
//Log with translation supported, call either on client or server (which then sends a message)
|
||||
public static void logTranslate(Player player, String prefix, String translationKey, String suffix, boolean actionBar) {
|
||||
proxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
ClientProxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
|
||||
} else {
|
||||
ServerProxy.logTranslate(player, prefix, translationKey, suffix, actionBar);
|
||||
}
|
||||
}
|
||||
|
||||
public static void logError(String msg) {
|
||||
logger.error(msg);
|
||||
}
|
||||
|
||||
public static ResourceLocation asResource(String path) {
|
||||
return ResourceLocation.fromNamespaceAndPath(MODID, path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
|
||||
import nl.requios.effortlessbuilding.gui.DiamondRandomizerBagScreen;
|
||||
import nl.requios.effortlessbuilding.gui.GoldenRandomizerBagScreen;
|
||||
import nl.requios.effortlessbuilding.gui.RandomizerBagScreen;
|
||||
import nl.requios.effortlessbuilding.render.BlockPreviews;
|
||||
import nl.requios.effortlessbuilding.systems.*;
|
||||
import nl.requios.effortlessbuilding.systems.BuildSettings;
|
||||
import nl.requios.effortlessbuilding.systems.BuilderChain;
|
||||
import nl.requios.effortlessbuilding.systems.BuilderFilter;
|
||||
import nl.requios.effortlessbuilding.systems.ItemUsageTracker;
|
||||
|
||||
public class EffortlessBuildingClient {
|
||||
|
||||
@@ -22,12 +24,12 @@ public class EffortlessBuildingClient {
|
||||
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
||||
|
||||
public static void onConstructorClient(IEventBus modEventBus, IEventBus forgeEventBus) {
|
||||
modEventBus.addListener(EffortlessBuildingClient::clientSetup);
|
||||
modEventBus.addListener(EffortlessBuildingClient::registerMenuScreens);
|
||||
}
|
||||
|
||||
public static void clientSetup(final FMLClientSetupEvent event) {
|
||||
MenuScreens.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
|
||||
MenuScreens.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
|
||||
MenuScreens.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
|
||||
public static void registerMenuScreens(final RegisterMenuScreensEvent event) {
|
||||
event.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
|
||||
event.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
|
||||
event.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.*;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.BooleanValue;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.Builder;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.ConfigValue;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.IntValue;
|
||||
|
||||
public class ServerConfig {
|
||||
private static final Builder builder = new Builder();
|
||||
|
||||
@@ -8,7 +8,7 @@ import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.network.message.PowerLevelPacket;
|
||||
|
||||
public class AttachmentHandler {
|
||||
public static final ResourceLocation POWER_LEVEL_CAP = new ResourceLocation(EffortlessBuilding.MODID, "power_level");
|
||||
public static final ResourceLocation POWER_LEVEL_CAP = EffortlessBuilding.asResource("power_level");
|
||||
|
||||
public static void syncToClient(Player player) {
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package nl.requios.effortlessbuilding.attachment;
|
||||
|
||||
import net.minecraft.core.HolderLookup.Provider;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.neoforge.common.util.INBTSerializable;
|
||||
@@ -93,13 +94,13 @@ public class PowerLevel implements INBTSerializable<CompoundTag> {
|
||||
return player.getAbilities().instabuild;
|
||||
}
|
||||
|
||||
public CompoundTag serializeNBT() {
|
||||
public CompoundTag serializeNBT(Provider provider) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("powerLevel", getPowerLevel());
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
public void deserializeNBT(Provider provider, CompoundTag nbt) {
|
||||
setPowerLevel(nbt.getInt("powerLevel"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package nl.requios.effortlessbuilding.buildmode;
|
||||
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import net.createmod.catnip.theme.Color;
|
||||
|
||||
public enum BuildModeCategoryEnum {
|
||||
BASIC(new Color(0f, .5f, 1f, .8f)),
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
package nl.requios.effortlessbuilding.buildmode;
|
||||
|
||||
import nl.requios.effortlessbuilding.AllIcons;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.*;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Circle;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Cube;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Cylinder;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.DiagonalLine;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.DiagonalWall;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Disabled;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Floor;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Line;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Single;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.SlopeFloor;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Sphere;
|
||||
import nl.requios.effortlessbuilding.buildmode.buildmodes.Wall;
|
||||
|
||||
public enum BuildModeEnum {
|
||||
DISABLED("normal", new Disabled(), BuildModeCategoryEnum.BASIC, AllIcons.I_DISABLE),
|
||||
|
||||
@@ -30,7 +30,7 @@ public class BuildModes {
|
||||
public void setBuildMode(BuildModeEnum buildMode) {
|
||||
this.buildMode = buildMode;
|
||||
|
||||
PacketDistributor.SERVER.noArg().send(new IsUsingBuildModePacket(this.buildMode != BuildModeEnum.DISABLED));
|
||||
PacketDistributor.sendToServer(new IsUsingBuildModePacket(this.buildMode != BuildModeEnum.DISABLED));
|
||||
|
||||
EffortlessBuilding.log(Minecraft.getInstance().player, I18n.get(buildMode.getNameKey()), true);
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ public class ModeOptions {
|
||||
if (action == null) return;
|
||||
|
||||
switch (action) {
|
||||
case UNDO -> PacketDistributor.SERVER.noArg().send(new PerformUndoPacket());
|
||||
case REDO -> PacketDistributor.SERVER.noArg().send(new PerformRedoPacket());
|
||||
case UNDO -> PacketDistributor.sendToServer(new PerformUndoPacket());
|
||||
case REDO -> PacketDistributor.sendToServer(new PerformRedoPacket());
|
||||
case OPEN_MODIFIER_SETTINGS -> ClientEvents.openModifierSettings();
|
||||
case OPEN_PLAYER_SETTINGS -> ClientEvents.openPlayerSettings();
|
||||
case PREVIOUS_BUILD_MODE -> EffortlessBuildingClient.BUILD_MODES.activatePreviousBuildMode();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -3,9 +3,9 @@ package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package nl.requios.effortlessbuilding.buildmode.buildmodes;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package nl.requios.effortlessbuilding.buildmodifier;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package nl.requios.effortlessbuilding.buildmodifier;
|
||||
|
||||
import net.createmod.catnip.nbt.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.NBTHelper;
|
||||
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
@@ -96,7 +96,7 @@ public class BuildModifiers {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
PacketDistributor.SERVER.noArg().send(new ModifierSettingsPacket(serializeNBT()));
|
||||
PacketDistributor.sendToServer(new ModifierSettingsPacket(serializeNBT()));
|
||||
|
||||
//Save locally as well?
|
||||
// var listTag = NBTHelper.writeCompoundList(modifierSettingsList, BaseModifier::serializeNBT);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.buildmodifier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package nl.requios.effortlessbuilding.buildmodifier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package nl.requios.effortlessbuilding.compatibility;
|
||||
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import nl.requios.effortlessbuilding.create.foundation.item.ItemHelper;
|
||||
import nl.requios.effortlessbuilding.item.AbstractRandomizerBagItem;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.createmod.catnip.render.BindableTexture;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public enum AllSpecialTextures {
|
||||
public enum AllSpecialTextures implements BindableTexture {
|
||||
|
||||
BLANK("blank.png"),
|
||||
CHECKERED("checkerboard.png"),
|
||||
@@ -18,7 +19,7 @@ public enum AllSpecialTextures {
|
||||
public static final String ASSET_PATH = "textures/special/";
|
||||
private ResourceLocation location;
|
||||
|
||||
private AllSpecialTextures(String filename) {
|
||||
AllSpecialTextures(String filename) {
|
||||
location = Create.asResource(ASSET_PATH + filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@ public class Create {
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
public static ResourceLocation asResource(String path) {
|
||||
return new ResourceLocation(EffortlessBuilding.MODID, path);
|
||||
return ResourceLocation.fromNamespaceAndPath(EffortlessBuilding.MODID, path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create;
|
||||
|
||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperByteBufferCache;
|
||||
import net.createmod.catnip.render.SuperByteBufferCache;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.ghost.GhostBlocks;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.outliner.Outliner;
|
||||
|
||||
public class CreateClient {
|
||||
public static final SuperByteBufferCache BUFFER_CACHE = new SuperByteBufferCache();
|
||||
public static final Outliner OUTLINER = new Outliner();
|
||||
public static final GhostBlocks GHOST_BLOCKS = new GhostBlocks();
|
||||
|
||||
public static void invalidateRenderers() {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create;
|
||||
|
||||
//@Mod.EventBusSubscriber(Dist.CLIENT)
|
||||
public class CreateClientTest {
|
||||
|
||||
// @SubscribeEvent
|
||||
// public static void onTick(TickEvent.ClientTickEvent event) {
|
||||
// CreateClient.GHOST_BLOCKS.showGhostState(1, Blocks.SPRUCE_LOG.defaultBlockState())
|
||||
// .at(0, 120, 0)
|
||||
// .breathingAlpha();
|
||||
// CreateClient.GHOST_BLOCKS.showGhostState(2, Blocks.SPRUCE_LOG.defaultBlockState())
|
||||
// .at(1, 120, 0)
|
||||
// .breathingAlpha();
|
||||
//
|
||||
// CreateClient.OUTLINER.showAABB(1, new AABB(0, 0, 0, 10, 2, 6)
|
||||
// .move(10, 120, 0))
|
||||
// .withFaceTexture(AllSpecialTextures.CHECKERED)
|
||||
// .colored(new Color(0.11f, 0.49f, 0.7f, 1f))
|
||||
//// .colored(0xbfbfbf)
|
||||
// .disableNormals()
|
||||
// .lineWidth(1 / 32f);
|
||||
// }
|
||||
}
|
||||
@@ -2,46 +2,46 @@ package nl.requios.effortlessbuilding.create.events;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||
import net.createmod.catnip.levelWrappers.WrappedClientLevel;
|
||||
import net.createmod.catnip.render.DefaultSuperRenderTypeBuffer;
|
||||
import net.createmod.catnip.render.SuperRenderTypeBuffer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
|
||||
import net.neoforged.neoforge.client.event.ViewportEvent;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
import net.neoforged.neoforge.event.TickEvent.ClientTickEvent;
|
||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperRenderTypeBuffer;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.AnimationTickHolder;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.CameraAngleAnimationService;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.worldWrappers.WrappedClientWorld;
|
||||
|
||||
@Mod.EventBusSubscriber(Dist.CLIENT)
|
||||
@EventBusSubscriber(Dist.CLIENT)
|
||||
public class ClientEvents {
|
||||
|
||||
private static final String ITEM_PREFIX = "item." + Create.ID;
|
||||
private static final String BLOCK_PREFIX = "block." + Create.ID;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTick(ClientTickEvent event) {
|
||||
if (!isGameActive() || event.phase != TickEvent.Phase.END) return;
|
||||
public static void onTick(ClientTickEvent.Post event) {
|
||||
if (!isGameActive()) return;
|
||||
|
||||
AnimationTickHolder.tick();
|
||||
|
||||
CreateClient.GHOST_BLOCKS.tickGhosts();
|
||||
CreateClient.OUTLINER.tickOutlines();
|
||||
// CreateClient.OUTLINER.tickOutlines();
|
||||
CameraAngleAnimationService.tick();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLoadWorld(LevelEvent.Load event) {
|
||||
LevelAccessor world = event.getLevel();
|
||||
if (world.isClientSide() && world instanceof ClientLevel && !(world instanceof WrappedClientWorld)) {
|
||||
if (world.isClientSide() && world instanceof ClientLevel && !(world instanceof WrappedClientLevel)) {
|
||||
CreateClient.invalidateRenderers();
|
||||
AnimationTickHolder.reset();
|
||||
}
|
||||
@@ -67,11 +67,11 @@ public class ClientEvents {
|
||||
PoseStack ms = event.getPoseStack();
|
||||
ms.pushPose();
|
||||
ms.translate(-cameraPos.x(), -cameraPos.y(), -cameraPos.z());
|
||||
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
||||
SuperRenderTypeBuffer buffer = DefaultSuperRenderTypeBuffer.getInstance();
|
||||
|
||||
CreateClient.GHOST_BLOCKS.renderAll(ms, buffer);
|
||||
|
||||
CreateClient.OUTLINER.renderOutlines(ms, buffer, pt);
|
||||
// CreateClient.OUTLINER.renderOutlines(ms, buffer, pt);
|
||||
buffer.draw();
|
||||
RenderSystem.enableCull();
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package nl.requios.effortlessbuilding.create.events;
|
||||
|
||||
import net.createmod.catnip.data.WorldAttached;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.WorldAttached;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
@EventBusSubscriber
|
||||
public class CommonEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation;
|
||||
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.LangNumberFormat;
|
||||
import net.createmod.catnip.lang.LangNumberFormat;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
//package nl.requios.effortlessbuilding.create.foundation;
|
||||
//
|
||||
//import net.neoforged.neoforgespi.locating.IModFile;
|
||||
//import net.neoforged.neoforge.resource.PathPackResources;
|
||||
//
|
||||
//import java.nio.file.Path;
|
||||
//
|
||||
//public class ModFilePackResources extends PathPackResources {
|
||||
// protected final IModFile modFile;
|
||||
// protected final String sourcePath;
|
||||
//
|
||||
// public ModFilePackResources(String name, IModFile modFile, String sourcePath) {
|
||||
// super(name, true, modFile.findResource(sourcePath));
|
||||
// this.modFile = modFile;
|
||||
// this.sourcePath = sourcePath;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Path resolve(String... paths) {
|
||||
// String[] allPaths = new String[paths.length + 1];
|
||||
// allPaths[0] = sourcePath;
|
||||
// System.arraycopy(paths, 0, allPaths, 1, paths.length);
|
||||
// return modFile.findResource(allPaths);
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,29 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||
|
||||
import net.createmod.catnip.render.SpriteShiftEntry;
|
||||
|
||||
public class CTSpriteShiftEntry extends SpriteShiftEntry {
|
||||
|
||||
protected final CTType type;
|
||||
|
||||
public CTSpriteShiftEntry(CTType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public CTType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public float getTargetU(float localU, int index) {
|
||||
float uOffset = (index % type.getSheetSize());
|
||||
return getTarget().getU(
|
||||
(getUnInterpolatedU(getOriginal(), localU) + uOffset) / ((float) type.getSheetSize()));
|
||||
}
|
||||
|
||||
public float getTargetV(float localV, int index) {
|
||||
float vOffset = (index / type.getSheetSize());
|
||||
return getTarget().getV(
|
||||
(getUnInterpolatedV(getOriginal(), localV) + vOffset) / ((float) type.getSheetSize()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import nl.requios.effortlessbuilding.create.foundation.block.render.ConnectedTextureBehaviour.CTContext;
|
||||
import nl.requios.effortlessbuilding.create.foundation.block.render.ConnectedTextureBehaviour.ContextRequirement;
|
||||
|
||||
public interface CTType {
|
||||
ResourceLocation getId();
|
||||
|
||||
int getSheetSize();
|
||||
|
||||
ContextRequirement getContextRequirement();
|
||||
|
||||
int getTextureIndex(CTContext context);
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Direction.Axis;
|
||||
import net.minecraft.core.Direction.AxisDirection;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ConnectedTextureBehaviour {
|
||||
|
||||
@Nullable
|
||||
public CTSpriteShiftEntry getShift(BlockState state, RandomSource rand, Direction direction,
|
||||
@NotNull TextureAtlasSprite sprite) {
|
||||
return getShift(state, direction, sprite);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract CTSpriteShiftEntry getShift(BlockState state, Direction direction,
|
||||
@NotNull TextureAtlasSprite sprite);
|
||||
|
||||
// TODO: allow more than one data type per state/face?
|
||||
@Nullable
|
||||
public abstract CTType getDataType(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction direction);
|
||||
|
||||
public boolean buildContextForOccludedDirections() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isBeingBlocked(BlockState state, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos,
|
||||
Direction face) {
|
||||
BlockPos blockingPos = otherPos.relative(face);
|
||||
BlockState blockState = reader.getBlockState(pos);
|
||||
BlockState blockingState = reader.getBlockState(blockingPos);
|
||||
|
||||
if (!Block.isFaceFull(blockingState.getShape(reader, blockingPos), face.getOpposite()))
|
||||
return false;
|
||||
if (face.getAxis()
|
||||
.choose(pos.getX(), pos.getY(), pos.getZ()) != face.getAxis()
|
||||
.choose(otherPos.getX(), otherPos.getY(), otherPos.getZ()))
|
||||
return false;
|
||||
|
||||
return connectsTo(state,
|
||||
getCTBlockState(reader, blockState, face.getOpposite(), pos.relative(face), blockingPos), reader, pos,
|
||||
blockingPos, face);
|
||||
}
|
||||
|
||||
public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos,
|
||||
BlockPos otherPos, Direction face, Direction primaryOffset, Direction secondaryOffset) {
|
||||
return connectsTo(state, other, reader, pos, otherPos, face);
|
||||
}
|
||||
|
||||
public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos,
|
||||
BlockPos otherPos, Direction face) {
|
||||
return !isBeingBlocked(state, reader, pos, otherPos, face) && state.getBlock() == other.getBlock();
|
||||
}
|
||||
|
||||
private boolean testConnection(BlockAndTintGetter reader, BlockPos currentPos, BlockState connectiveCurrentState,
|
||||
Direction textureSide, final Direction horizontal, final Direction vertical, int sh, int sv) {
|
||||
BlockState trueCurrentState = reader.getBlockState(currentPos);
|
||||
BlockPos targetPos = currentPos.relative(horizontal, sh)
|
||||
.relative(vertical, sv);
|
||||
BlockState connectiveTargetState =
|
||||
getCTBlockState(reader, trueCurrentState, textureSide, currentPos, targetPos);
|
||||
return connectsTo(connectiveCurrentState, connectiveTargetState, reader, currentPos, targetPos, textureSide,
|
||||
sh == 0 ? null : sh == -1 ? horizontal.getOpposite() : horizontal,
|
||||
sv == 0 ? null : sv == -1 ? vertical.getOpposite() : vertical);
|
||||
}
|
||||
|
||||
public BlockState getCTBlockState(BlockAndTintGetter reader, BlockState reference, Direction face, BlockPos fromPos,
|
||||
BlockPos toPos) {
|
||||
BlockState blockState = reader.getBlockState(toPos);
|
||||
return blockState.getAppearance(reader, toPos, face, reference, fromPos);
|
||||
}
|
||||
|
||||
protected boolean reverseUVs(BlockState state, Direction face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean reverseUVsHorizontally(BlockState state, Direction face) {
|
||||
return reverseUVs(state, face);
|
||||
}
|
||||
|
||||
protected boolean reverseUVsVertically(BlockState state, Direction face) {
|
||||
return reverseUVs(state, face);
|
||||
}
|
||||
|
||||
protected Direction getUpDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) {
|
||||
Axis axis = face.getAxis();
|
||||
return axis.isHorizontal() ? Direction.UP : Direction.NORTH;
|
||||
}
|
||||
|
||||
protected Direction getRightDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) {
|
||||
Axis axis = face.getAxis();
|
||||
return axis == Axis.X ? Direction.SOUTH : Direction.WEST;
|
||||
}
|
||||
|
||||
public CTContext buildContext(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face,
|
||||
ContextRequirement requirement) {
|
||||
boolean positive = face.getAxisDirection() == AxisDirection.POSITIVE;
|
||||
Direction h = getRightDirection(reader, pos, state, face);
|
||||
Direction v = getUpDirection(reader, pos, state, face);
|
||||
h = positive ? h.getOpposite() : h;
|
||||
if (face == Direction.DOWN) {
|
||||
v = v.getOpposite();
|
||||
h = h.getOpposite();
|
||||
}
|
||||
|
||||
final Direction horizontal = h;
|
||||
final Direction vertical = v;
|
||||
|
||||
boolean flipH = reverseUVsHorizontally(state, face);
|
||||
boolean flipV = reverseUVsVertically(state, face);
|
||||
int sh = flipH ? -1 : 1;
|
||||
int sv = flipV ? -1 : 1;
|
||||
|
||||
CTContext context = new CTContext();
|
||||
|
||||
if (requirement.up) {
|
||||
context.up = testConnection(reader, pos, state, face, horizontal, vertical, 0, sv);
|
||||
}
|
||||
if (requirement.down) {
|
||||
context.down = testConnection(reader, pos, state, face, horizontal, vertical, 0, -sv);
|
||||
}
|
||||
if (requirement.left) {
|
||||
context.left = testConnection(reader, pos, state, face, horizontal, vertical, -sh, 0);
|
||||
}
|
||||
if (requirement.right) {
|
||||
context.right = testConnection(reader, pos, state, face, horizontal, vertical, sh, 0);
|
||||
}
|
||||
|
||||
if (requirement.topLeft) {
|
||||
context.topLeft =
|
||||
context.up && context.left && testConnection(reader, pos, state, face, horizontal, vertical, -sh, sv);
|
||||
}
|
||||
if (requirement.topRight) {
|
||||
context.topRight =
|
||||
context.up && context.right && testConnection(reader, pos, state, face, horizontal, vertical, sh, sv);
|
||||
}
|
||||
if (requirement.bottomLeft) {
|
||||
context.bottomLeft = context.down && context.left
|
||||
&& testConnection(reader, pos, state, face, horizontal, vertical, -sh, -sv);
|
||||
}
|
||||
if (requirement.bottomRight) {
|
||||
context.bottomRight = context.down && context.right
|
||||
&& testConnection(reader, pos, state, face, horizontal, vertical, sh, -sv);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
public static class CTContext {
|
||||
public static final CTContext EMPTY = new CTContext();
|
||||
|
||||
public boolean up, down, left, right;
|
||||
public boolean topLeft, topRight, bottomLeft, bottomRight;
|
||||
}
|
||||
|
||||
public static class ContextRequirement {
|
||||
public final boolean up, down, left, right;
|
||||
public final boolean topLeft, topRight, bottomLeft, bottomRight;
|
||||
|
||||
public ContextRequirement(boolean up, boolean down, boolean left, boolean right, boolean topLeft,
|
||||
boolean topRight, boolean bottomLeft, boolean bottomRight) {
|
||||
this.up = up;
|
||||
this.down = down;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.topLeft = topLeft;
|
||||
this.topRight = topRight;
|
||||
this.bottomLeft = bottomLeft;
|
||||
this.bottomRight = bottomRight;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private boolean up, down, left, right;
|
||||
private boolean topLeft, topRight, bottomLeft, bottomRight;
|
||||
|
||||
public Builder up() {
|
||||
up = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder down() {
|
||||
down = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder left() {
|
||||
left = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder right() {
|
||||
right = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder topLeft() {
|
||||
topLeft = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder topRight() {
|
||||
topRight = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bottomLeft() {
|
||||
bottomLeft = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder bottomRight() {
|
||||
bottomRight = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder horizontal() {
|
||||
left();
|
||||
right();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder vertical() {
|
||||
up();
|
||||
down();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder axisAligned() {
|
||||
horizontal();
|
||||
vertical();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder corners() {
|
||||
topLeft();
|
||||
topRight();
|
||||
bottomLeft();
|
||||
bottomRight();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder all() {
|
||||
axisAligned();
|
||||
corners();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContextRequirement build() {
|
||||
return new ContextRequirement(up, down, left, right, topLeft, topRight, bottomLeft, bottomRight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class Base extends ConnectedTextureBehaviour {
|
||||
@Override
|
||||
@Nullable
|
||||
public abstract CTSpriteShiftEntry getShift(BlockState state, Direction direction,
|
||||
@Nullable TextureAtlasSprite sprite);
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public CTType getDataType(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction direction) {
|
||||
CTSpriteShiftEntry shift = getShift(state, direction, null);
|
||||
if (shift == null) {
|
||||
return null;
|
||||
}
|
||||
return shift.getType();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.block.render;
|
||||
|
||||
import com.jozufozu.flywheel.core.StitchedSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class SpriteShiftEntry {
|
||||
protected StitchedSprite original;
|
||||
protected StitchedSprite target;
|
||||
|
||||
public void set(ResourceLocation originalTextureLocation, ResourceLocation targetTextureLocation) {
|
||||
original = new StitchedSprite(originalTextureLocation);
|
||||
target = new StitchedSprite(targetTextureLocation);
|
||||
}
|
||||
|
||||
public ResourceLocation getOriginalResourceLocation() {
|
||||
return original.getLocation();
|
||||
}
|
||||
|
||||
public ResourceLocation getTargetResourceLocation() {
|
||||
return target.getLocation();
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getOriginal() {
|
||||
return original.get();
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getTarget() {
|
||||
return target.get();
|
||||
}
|
||||
|
||||
public float getTargetU(float localU) {
|
||||
return getTarget().getU(getUnInterpolatedU(getOriginal(), localU));
|
||||
}
|
||||
|
||||
public float getTargetV(float localV) {
|
||||
return getTarget().getV(getUnInterpolatedV(getOriginal(), localV));
|
||||
}
|
||||
|
||||
public static float getUnInterpolatedU(TextureAtlasSprite sprite, float u) {
|
||||
float f = sprite.getU1() - sprite.getU0();
|
||||
return (u - sprite.getU0()) / f * 16.0F;
|
||||
}
|
||||
|
||||
public static float getUnInterpolatedV(TextureAtlasSprite sprite, float v) {
|
||||
float f = sprite.getV1() - sprite.getV0();
|
||||
return (v - sprite.getV0()) / f * 16.0F;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||
import net.createmod.catnip.gui.TickableGuiEventListener;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
@@ -106,7 +108,7 @@ public abstract class AbstractSimiScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
partialTicks = minecraft.getFrameTime();
|
||||
partialTicks = AnimationTickHolder.getPartialTicksUI();
|
||||
PoseStack ms = graphics.pose();
|
||||
|
||||
ms.pushPose();
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.createmod.catnip.gui.UIRenderHelper;
|
||||
import net.createmod.catnip.gui.element.ScreenElement;
|
||||
import net.createmod.catnip.theme.Color;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
|
||||
public enum AllGuiTextures implements ScreenElement {
|
||||
|
||||
@@ -60,7 +61,7 @@ public enum AllGuiTextures implements ScreenElement {
|
||||
}
|
||||
|
||||
private AllGuiTextures(String namespace, String location, int startX, int startY, int width, int height) {
|
||||
this.location = new ResourceLocation(namespace, "textures/gui/" + location + ".png");
|
||||
this.location = ResourceLocation.fromNamespaceAndPath(namespace, "textures/gui/" + location + ".png");
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.startX = startX;
|
||||
|
||||
@@ -3,6 +3,9 @@ package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.createmod.catnip.gui.element.DelegatedStencilElement;
|
||||
import net.createmod.catnip.gui.element.ScreenElement;
|
||||
import net.createmod.catnip.theme.Color;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
@@ -12,9 +15,6 @@ import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.DelegatedStencilElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public class AllIcons implements ScreenElement {
|
||||
@@ -202,11 +202,10 @@ public class AllIcons implements ScreenElement {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) {
|
||||
builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||
.color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||
.uv(u, v)
|
||||
.uv2(light)
|
||||
.endVertex();
|
||||
builder.addVertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z)
|
||||
.setColor(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255)
|
||||
.setUv(u, v)
|
||||
.setLight(light);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.BoxElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.TextStencilElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.BoxWidget;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ConfirmationScreen extends AbstractSimiScreen {
|
||||
|
||||
private Screen source;
|
||||
private Consumer<Response> action = _success -> {
|
||||
};
|
||||
private List<FormattedText> text = new ArrayList<>();
|
||||
private boolean centered = false;
|
||||
private int x;
|
||||
private int y;
|
||||
private int textWidth;
|
||||
private int textHeight;
|
||||
private boolean tristate;
|
||||
|
||||
private BoxWidget confirm;
|
||||
private BoxWidget confirmDontSave;
|
||||
private BoxWidget cancel;
|
||||
private BoxElement textBackground;
|
||||
|
||||
public enum Response {
|
||||
Confirm, ConfirmDontSave, Cancel
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes text lines from the back of the list
|
||||
* */
|
||||
public ConfirmationScreen removeTextLines(int amount) {
|
||||
if (amount > text.size())
|
||||
return clearText();
|
||||
|
||||
text.subList(text.size() - amount, text.size()).clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfirmationScreen clearText() {
|
||||
this.text.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfirmationScreen addText(FormattedText text) {
|
||||
this.text.add(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfirmationScreen withText(FormattedText text) {
|
||||
return clearText().addText(text);
|
||||
}
|
||||
|
||||
public ConfirmationScreen at(int x, int y) {
|
||||
this.x = Math.max(x, 0);
|
||||
this.y = Math.max(y, 0);
|
||||
this.centered = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfirmationScreen centered() {
|
||||
this.centered = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfirmationScreen withAction(Consumer<Boolean> action) {
|
||||
this.action = r -> action.accept(r == Response.Confirm);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfirmationScreen withThreeActions(Consumer<Response> action) {
|
||||
this.action = action;
|
||||
this.tristate = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void open(@Nonnull Screen source) {
|
||||
this.source = source;
|
||||
Minecraft client = source.getMinecraft();
|
||||
this.init(client, client.getWindow().getGuiScaledWidth(), client.getWindow().getGuiScaledHeight());
|
||||
this.minecraft.screen = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
source.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
ArrayList<FormattedText> copy = new ArrayList<>(text);
|
||||
text.clear();
|
||||
copy.forEach(t -> text.addAll(font.getSplitter().splitLines(t, 300, Style.EMPTY)));
|
||||
|
||||
textHeight = text.size() * (font.lineHeight + 1) + 4;
|
||||
textWidth = 300;
|
||||
|
||||
if (centered) {
|
||||
x = width/2 - textWidth/2 - 2;
|
||||
y = height/2 - textHeight/2 - 16;
|
||||
} else {
|
||||
x = Math.max(0, x - textWidth / 2);
|
||||
y = Math.max(0, y -= textHeight);
|
||||
}
|
||||
|
||||
if (x + textWidth > width) {
|
||||
x = width - textWidth;
|
||||
}
|
||||
|
||||
if (y + textHeight + 30 > height) {
|
||||
y = height - textHeight - 30;
|
||||
}
|
||||
|
||||
int buttonX = x + textWidth / 2 - 6 - (int) (70 * (tristate ? 1.5f : 1));
|
||||
|
||||
TextStencilElement confirmText =
|
||||
new TextStencilElement(font, tristate ? "Save" : "Confirm").centered(true, true);
|
||||
confirm = new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.Confirm));
|
||||
confirm.showingElement(confirmText.withElementRenderer(BoxWidget.gradientFactory.apply(confirm)));
|
||||
addRenderableWidget(confirm);
|
||||
|
||||
buttonX += 12 + 70;
|
||||
|
||||
if (tristate) {
|
||||
TextStencilElement confirmDontSaveText =
|
||||
new TextStencilElement(font, "Don't Save").centered(true, true);
|
||||
confirmDontSave =
|
||||
new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.ConfirmDontSave));
|
||||
confirmDontSave.showingElement(
|
||||
confirmDontSaveText.withElementRenderer(BoxWidget.gradientFactory.apply(confirmDontSave)));
|
||||
addRenderableWidget(confirmDontSave);
|
||||
buttonX += 12 + 70;
|
||||
}
|
||||
|
||||
TextStencilElement cancelText = new TextStencilElement(font, "Cancel").centered(true, true);
|
||||
cancel = new BoxWidget(buttonX, y + textHeight + 6, 70, 16)
|
||||
.withCallback(() -> accept(Response.Cancel));
|
||||
cancel.showingElement(cancelText.withElementRenderer(BoxWidget.gradientFactory.apply(cancel)));
|
||||
addRenderableWidget(cancel);
|
||||
|
||||
textBackground = new BoxElement()
|
||||
.gradientBorder(Theme.p(Theme.Key.BUTTON_DISABLE))
|
||||
.withBounds(width + 10, textHeight + 35)
|
||||
.at(-5, y - 5);
|
||||
|
||||
if (text.size() == 1)
|
||||
x = (width - font.width(text.get(0))) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
accept(Response.Cancel);
|
||||
}
|
||||
|
||||
private void accept(Response success) {
|
||||
minecraft.screen = source;
|
||||
action.accept(success);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderWindow(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
textBackground.render(graphics);
|
||||
int offset = font.lineHeight + 1;
|
||||
int lineY = y - offset;
|
||||
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
ms.translate(0, 0, 200);
|
||||
|
||||
for (FormattedText line : text) {
|
||||
lineY += offset;
|
||||
if (line == null)
|
||||
continue;
|
||||
graphics.drawString(font, line.getString(), x, lineY, 0xeaeaea, false);
|
||||
}
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderWindowBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
endFrame();
|
||||
|
||||
source.render(graphics, 0, 0, 10); // zero mouse coords to prevent further tooltips
|
||||
|
||||
prepareFrame();
|
||||
|
||||
graphics.fillGradient(0, 0, this.width, this.height, 0x70101010, 0x80101010);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void prepareFrame() {
|
||||
UIRenderHelper.swapAndBlitColor(minecraft.getMainRenderTarget(), UIRenderHelper.framebuffer);
|
||||
RenderSystem.clear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void endFrame() {
|
||||
UIRenderHelper.swapAndBlitColor(UIRenderHelper.framebuffer, minecraft.getMainRenderTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(@Nonnull Minecraft client, int width, int height) {
|
||||
super.resize(client, width, height);
|
||||
source.resize(client, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPauseScreen() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.math.Axis;
|
||||
import net.createmod.catnip.gui.ILightingSettings;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class CustomLightingSettings implements ILightingSettings {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CustomLightingSettings implements ILightingSettings {
|
||||
|
||||
@Override
|
||||
public void applyLighting() {
|
||||
RenderSystem.setupLevelDiffuseLighting(light1, light2, lightMatrix);
|
||||
RenderSystem.setShaderLights(light1, light2);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.Lighting;
|
||||
|
||||
public interface ILightingSettings {
|
||||
|
||||
void applyLighting();
|
||||
|
||||
static final ILightingSettings DEFAULT_3D = () -> Lighting.setupFor3DItems();
|
||||
static final ILightingSettings DEFAULT_FLAT = () -> Lighting.setupForFlatItems();
|
||||
|
||||
}
|
||||
@@ -1,18 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.neoforged.neoforge.client.event.RenderTooltipEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
@@ -21,7 +10,14 @@ import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.client.ClientHooks;
|
||||
import net.neoforged.neoforge.client.event.RenderTooltipEvent;
|
||||
import net.neoforged.neoforge.client.extensions.IGuiGraphicsExtension;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RemovedGuiUtils {
|
||||
@Nonnull
|
||||
@@ -179,8 +175,7 @@ public class RemovedGuiUtils {
|
||||
graphics.fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 2,
|
||||
tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, zLevel, borderColorEnd, borderColorEnd);
|
||||
|
||||
MultiBufferSource.BufferSource renderType = MultiBufferSource.immediate(Tesselator.getInstance()
|
||||
.getBuilder());
|
||||
MultiBufferSource.BufferSource renderType = graphics.bufferSource();
|
||||
pStack.translate(0.0D, 0.0D, zLevel);
|
||||
|
||||
for (int lineNumber = 0; lineNumber < list.size(); ++lineNumber) {
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
||||
import net.createmod.catnip.data.Couple;
|
||||
import net.createmod.catnip.theme.Color;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Theme {
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
|
||||
public interface TickableGuiEventListener extends GuiEventListener {
|
||||
void tick();
|
||||
}
|
||||
@@ -1,327 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||
import com.mojang.blaze3d.platform.GlConst;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
public class UIRenderHelper {
|
||||
|
||||
/**
|
||||
* An FBO that has a stencil buffer for use wherever stencil are necessary. Forcing the main FBO to have a stencil
|
||||
* buffer will cause GL error spam when using fabulous graphics.
|
||||
*/
|
||||
public static CustomRenderTarget framebuffer;
|
||||
|
||||
public static void init() {
|
||||
RenderSystem.recordRenderCall(() -> {
|
||||
Window mainWindow = Minecraft.getInstance().getWindow();
|
||||
framebuffer = CustomRenderTarget.create(mainWindow);
|
||||
});
|
||||
}
|
||||
|
||||
public static void updateWindowSize(Window mainWindow) {
|
||||
if (framebuffer != null)
|
||||
framebuffer.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX);
|
||||
}
|
||||
|
||||
public static void drawFramebuffer(float alpha) {
|
||||
framebuffer.renderWithAlpha(alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch from src to dst, after copying the contents of src to dst.
|
||||
*/
|
||||
public static void swapAndBlitColor(RenderTarget src, RenderTarget dst) {
|
||||
GlStateManager._glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, src.frameBufferId);
|
||||
GlStateManager._glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, dst.frameBufferId);
|
||||
GlStateManager._glBlitFrameBuffer(0, 0, src.viewWidth, src.viewHeight, 0, 0, dst.viewWidth, dst.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
|
||||
|
||||
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, dst.frameBufferId);
|
||||
}
|
||||
|
||||
public static void streak(GuiGraphics graphics, float angle, int x, int y, int breadth, int length) {
|
||||
streak(graphics, angle, x, y, breadth, length, Theme.i(Theme.Key.STREAK));
|
||||
}
|
||||
// angle in degrees; 0° -> fading to the right
|
||||
// x and y specify the middle point of the starting edge
|
||||
// breadth is the total width of the streak
|
||||
|
||||
public static void streak(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, int color) {
|
||||
int a1 = 0xa0 << 24;
|
||||
int a2 = 0x80 << 24;
|
||||
int a3 = 0x10 << 24;
|
||||
int a4 = 0x00 << 24;
|
||||
|
||||
color &= 0x00FFFFFF;
|
||||
int c1 = a1 | color;
|
||||
int c2 = a2 | color;
|
||||
int c3 = a3 | color;
|
||||
int c4 = a4 | color;
|
||||
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
ms.translate(x, y, 0);
|
||||
ms.mulPose(Axis.ZP.rotationDegrees(angle - 90));
|
||||
|
||||
streak(graphics, breadth / 2, length, c1, c2, c3, c4);
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
public static void streak(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, Color c) {
|
||||
Color color = c.copy().setImmutable();
|
||||
int c1 = color.scaleAlpha(0.625f).getRGB();
|
||||
int c2 = color.scaleAlpha(0.5f).getRGB();
|
||||
int c3 = color.scaleAlpha(0.0625f).getRGB();
|
||||
int c4 = color.scaleAlpha(0f).getRGB();
|
||||
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
ms.translate(x, y, 0);
|
||||
ms.mulPose(Axis.ZP.rotationDegrees(angle - 90));
|
||||
|
||||
streak(graphics, breadth / 2, length, c1, c2, c3, c4);
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
private static void streak(GuiGraphics graphics, int width, int height, int c1, int c2, int c3, int c4) {
|
||||
double split1 = .5;
|
||||
double split2 = .75;
|
||||
graphics.fillGradient(-width, 0, width, (int) (split1 * height), 0, c1, c2);
|
||||
graphics.fillGradient(-width, (int) (split1 * height), width, (int) (split2 * height), 0, c2, c3);
|
||||
graphics.fillGradient(-width, (int) (split2 * height), width, height, 0, c3, c4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #angledGradient(GuiGraphics, float, int, int, int, int, int, Color, Color)
|
||||
*/
|
||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, Couple<Color> c) {
|
||||
angledGradient(graphics, angle, x, y, 0, breadth, length, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #angledGradient(GuiGraphics, float, int, int, int, int, int, Color, Color)
|
||||
*/
|
||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int z, int breadth, int length, Couple<Color> c) {
|
||||
angledGradient(graphics, angle, x, y, z, breadth, length, c.getFirst(), c.getSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #angledGradient(GuiGraphics, float, int, int, int, int, int, Color, Color)
|
||||
*/
|
||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int breadth, int length, Color color1, Color color2) {
|
||||
angledGradient(graphics, angle, x, y, 0, breadth, length, color1, color2);
|
||||
}
|
||||
|
||||
/**
|
||||
* x and y specify the middle point of the starting edge
|
||||
*
|
||||
* @param angle the angle of the gradient in degrees; 0° means from left to right
|
||||
* @param color1 the color at the starting edge
|
||||
* @param color2 the color at the ending edge
|
||||
* @param breadth the total width of the gradient
|
||||
*/
|
||||
public static void angledGradient(GuiGraphics graphics, float angle, int x, int y, int z, int breadth, int length, Color color1, Color color2) {
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
ms.translate(x, y, z);
|
||||
ms.mulPose(Axis.ZP.rotationDegrees(angle - 90));
|
||||
|
||||
int w = breadth / 2;
|
||||
graphics.fillGradient(-w, 0, w, length, 0, color1.getRGB(), color2.getRGB());
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
public static void breadcrumbArrow(GuiGraphics graphics, int x, int y, int z, int width, int height, int indent, Couple<Color> colors) {breadcrumbArrow(graphics, x, y, z, width, height, indent, colors.getFirst(), colors.getSecond());}
|
||||
|
||||
// draws a wide chevron-style breadcrumb arrow pointing left
|
||||
public static void breadcrumbArrow(GuiGraphics graphics, int x, int y, int z, int width, int height, int indent, Color startColor, Color endColor) {
|
||||
PoseStack matrixStack = graphics.pose();
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(x - indent, y, z);
|
||||
|
||||
breadcrumbArrow(graphics, width, height, indent, startColor, endColor);
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
private static void breadcrumbArrow(GuiGraphics graphics, int width, int height, int indent, Color c1, Color c2) {
|
||||
|
||||
/*
|
||||
* 0,0 x1,y1 ********************* x4,y4 ***** x7,y7
|
||||
* **** ****
|
||||
* **** ****
|
||||
* x0,y0 x2,y2 x5,y5
|
||||
* **** ****
|
||||
* **** ****
|
||||
* x3,y3 ********************* x6,y6 ***** x8,y8
|
||||
*
|
||||
*/
|
||||
|
||||
float x0 = 0, y0 = height / 2f;
|
||||
float x1 = indent, y1 = 0;
|
||||
float x2 = indent, y2 = height / 2f;
|
||||
float x3 = indent, y3 = height;
|
||||
float x4 = width, y4 = 0;
|
||||
float x5 = width, y5 = height / 2f;
|
||||
float x6 = width, y6 = height;
|
||||
float x7 = indent + width, y7 = 0;
|
||||
float x8 = indent + width, y8 = height;
|
||||
|
||||
indent = Math.abs(indent);
|
||||
width = Math.abs(width);
|
||||
Color fc1 = Color.mixColors(c1, c2, 0);
|
||||
Color fc2 = Color.mixColors(c1, c2, (indent) / (width + 2f * indent));
|
||||
Color fc3 = Color.mixColors(c1, c2, (indent + width) / (width + 2f * indent));
|
||||
Color fc4 = Color.mixColors(c1, c2, 1);
|
||||
|
||||
// RenderSystem.disableTexture();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder bufferbuilder = tessellator.getBuilder();
|
||||
Matrix4f model = graphics.pose().last().pose();
|
||||
bufferbuilder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
bufferbuilder.vertex(model, x0, y0, 0).color(fc1.getRed(), fc1.getGreen(), fc1.getBlue(), fc1.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x1, y1, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x2, y2, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
||||
|
||||
bufferbuilder.vertex(model, x0, y0, 0).color(fc1.getRed(), fc1.getGreen(), fc1.getBlue(), fc1.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x2, y2, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x3, y3, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
||||
|
||||
bufferbuilder.vertex(model, x3, y3, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x1, y1, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x4, y4, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
||||
|
||||
bufferbuilder.vertex(model, x3, y3, 0).color(fc2.getRed(), fc2.getGreen(), fc2.getBlue(), fc2.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x4, y4, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x6, y6, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
||||
|
||||
bufferbuilder.vertex(model, x5, y5, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x4, y4, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x7, y7, 0).color(fc4.getRed(), fc4.getGreen(), fc4.getBlue(), fc4.getAlpha()).endVertex();
|
||||
|
||||
bufferbuilder.vertex(model, x6, y6, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x5, y5, 0).color(fc3.getRed(), fc3.getGreen(), fc3.getBlue(), fc3.getAlpha()).endVertex();
|
||||
bufferbuilder.vertex(model, x8, y8, 0).color(fc4.getRed(), fc4.getGreen(), fc4.getBlue(), fc4.getAlpha()).endVertex();
|
||||
|
||||
tessellator.end();
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.disableBlend();
|
||||
// RenderSystem.enableTexture();
|
||||
}
|
||||
|
||||
//just like AbstractGui#drawTexture, but with a color at every vertex
|
||||
public static void drawColoredTexture(GuiGraphics graphics, Color c, int x, int y, int tex_left, int tex_top, int width, int height) {
|
||||
drawColoredTexture(graphics, c, x, y, 0, (float) tex_left, (float) tex_top, width, height, 256, 256);
|
||||
}
|
||||
|
||||
public static void drawColoredTexture(GuiGraphics graphics, Color c, int x, int y, int z, float tex_left, float tex_top, int width, int height, int sheet_width, int sheet_height) {
|
||||
drawColoredTexture(graphics, c, x, x + width, y, y + height, z, width, height, tex_left, tex_top, sheet_width, sheet_height);
|
||||
}
|
||||
|
||||
public static void drawStretched(GuiGraphics graphics, int left, int top, int w, int h, int z, AllGuiTextures tex) {
|
||||
tex.bind();
|
||||
drawTexturedQuad(graphics.pose().last()
|
||||
.pose(), Color.WHITE, left, left + w, top, top + h, z, tex.startX / 256f, (tex.startX + tex.width) / 256f,
|
||||
tex.startY / 256f, (tex.startY + tex.height) / 256f);
|
||||
}
|
||||
|
||||
public static void drawCropped(GuiGraphics graphics, int left, int top, int w, int h, int z, AllGuiTextures tex) {
|
||||
tex.bind();
|
||||
drawTexturedQuad(graphics.pose().last()
|
||||
.pose(), Color.WHITE, left, left + w, top, top + h, z, tex.startX / 256f, (tex.startX + w) / 256f,
|
||||
tex.startY / 256f, (tex.startY + h) / 256f);
|
||||
}
|
||||
|
||||
private static void drawColoredTexture(GuiGraphics graphics, Color c, int left, int right, int top, int bot, int z, int tex_width, int tex_height, float tex_left, float tex_top, int sheet_width, int sheet_height) {
|
||||
drawTexturedQuad(graphics.pose().last().pose(), c, left, right, top, bot, z, (tex_left + 0.0F) / (float) sheet_width, (tex_left + (float) tex_width) / (float) sheet_width, (tex_top + 0.0F) / (float) sheet_height, (tex_top + (float) tex_height) / (float) sheet_height);
|
||||
}
|
||||
|
||||
private static void drawTexturedQuad(Matrix4f m, Color c, int left, int right, int top, int bot, int z, float u1, float u2, float v1, float v2) {
|
||||
Tesselator tesselator = Tesselator.getInstance();
|
||||
BufferBuilder bufferbuilder = tesselator.getBuilder();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorTexShader);
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX);
|
||||
bufferbuilder.vertex(m, (float) left , (float) bot, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u1, v2).endVertex();
|
||||
bufferbuilder.vertex(m, (float) right, (float) bot, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u2, v2).endVertex();
|
||||
bufferbuilder.vertex(m, (float) right, (float) top, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u2, v1).endVertex();
|
||||
bufferbuilder.vertex(m, (float) left , (float) top, (float) z).color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()).uv(u1, v1).endVertex();
|
||||
tesselator.end();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public static void flipForGuiRender(PoseStack poseStack) {
|
||||
poseStack.mulPoseMatrix(new Matrix4f().scaling(1, -1, 1));
|
||||
}
|
||||
|
||||
public static class CustomRenderTarget extends RenderTarget {
|
||||
|
||||
public CustomRenderTarget(boolean useDepth) {
|
||||
super(useDepth);
|
||||
}
|
||||
|
||||
public static CustomRenderTarget create(Window mainWindow) {
|
||||
CustomRenderTarget framebuffer = new CustomRenderTarget(true);
|
||||
framebuffer.resize(mainWindow.getWidth(), mainWindow.getHeight(), Minecraft.ON_OSX);
|
||||
framebuffer.setClearColor(0, 0, 0, 0);
|
||||
framebuffer.enableStencil();
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
public void renderWithAlpha(float alpha) {
|
||||
Window window = Minecraft.getInstance().getWindow();
|
||||
|
||||
float vx = (float) window.getGuiScaledWidth();
|
||||
float vy = (float) window.getGuiScaledHeight();
|
||||
float tx = (float) viewWidth / (float) width;
|
||||
float ty = (float) viewHeight / (float) height;
|
||||
|
||||
// RenderSystem.enableTexture();
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.setShader(() -> Minecraft.getInstance().gameRenderer.blitShader);
|
||||
RenderSystem.getShader().setSampler("DiffuseSampler", colorTextureId);
|
||||
|
||||
bindRead();
|
||||
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder bufferbuilder = tessellator.getBuilder();
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX);
|
||||
|
||||
bufferbuilder.vertex(0, vy, 0).color(1, 1, 1, alpha).uv(0, 0).endVertex();
|
||||
bufferbuilder.vertex(vx, vy, 0).color(1, 1, 1, alpha).uv(tx, 0).endVertex();
|
||||
bufferbuilder.vertex(vx, 0, 0).color(1, 1, 1, alpha).uv(tx, ty).endVertex();
|
||||
bufferbuilder.vertex(0, 0, 0).color(1, 1, 1, alpha).uv(0, ty).endVertex();
|
||||
|
||||
tessellator.end();
|
||||
unbindRead();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||
import net.createmod.catnip.gui.TickableGuiEventListener;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
@@ -15,7 +17,6 @@ import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -92,7 +93,7 @@ public abstract class AbstractSimiContainerScreen<T extends AbstractContainerMen
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
partialTicks = minecraft.getFrameTime();
|
||||
partialTicks = AnimationTickHolder.getPartialTicksUI();
|
||||
|
||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
//package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
||||
//
|
||||
//import net.minecraft.network.FriendlyByteBuf;
|
||||
//import net.minecraft.server.level.ServerPlayer;
|
||||
//import net.neoforged.neoforge.network.NetworkEvent.Context;
|
||||
//import nl.requios.effortlessbuilding.create.foundation.networking.SimplePacketBase;
|
||||
//
|
||||
//public class ClearMenuPacket extends SimplePacketBase {
|
||||
//
|
||||
// public ClearMenuPacket() {}
|
||||
//
|
||||
// public ClearMenuPacket(FriendlyByteBuf buffer) {}
|
||||
//
|
||||
// @Override
|
||||
// public void write(FriendlyByteBuf buffer) {}
|
||||
//
|
||||
// @Override
|
||||
// public boolean handle(Context context) {
|
||||
// context.enqueueWork(() -> {
|
||||
// ServerPlayer player = context.getSender();
|
||||
// if (player == null)
|
||||
// return;
|
||||
// if (!(player.containerMenu instanceof IClearableMenu))
|
||||
// return;
|
||||
// ((IClearableMenu) player.containerMenu).clearContents();
|
||||
// });
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -7,7 +7,6 @@ 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.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
|
||||
public abstract class GhostItemMenu<T> extends MenuBase<T> implements IClearableMenu {
|
||||
@@ -88,7 +87,7 @@ public abstract class GhostItemMenu<T> extends MenuBase<T> implements IClearable
|
||||
ItemStack stackToInsert = playerInventory.getItem(index);
|
||||
for (int i = 0; i < ghostInventory.getSlots(); i++) {
|
||||
ItemStack stack = ghostInventory.getStackInSlot(i);
|
||||
if (!allowRepeats() && ItemHandlerHelper.canItemStacksStack(stack, stackToInsert))
|
||||
if (!allowRepeats() && ItemStack.isSameItemSameComponents(stack, stackToInsert))
|
||||
break;
|
||||
if (stack.isEmpty()) {
|
||||
ItemStack copy = stackToInsert.copy();
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
//package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
||||
//
|
||||
//import net.minecraft.network.FriendlyByteBuf;
|
||||
//import net.minecraft.server.level.ServerPlayer;
|
||||
//import net.minecraft.world.item.ItemStack;
|
||||
//import net.neoforged.neoforge.network.NetworkEvent.Context;
|
||||
//import nl.requios.effortlessbuilding.create.foundation.networking.SimplePacketBase;
|
||||
//
|
||||
//public class GhostItemSubmitPacket extends SimplePacketBase {
|
||||
//
|
||||
// private final ItemStack item;
|
||||
// private final int slot;
|
||||
//
|
||||
// public GhostItemSubmitPacket(ItemStack item, int slot) {
|
||||
// this.item = item;
|
||||
// this.slot = slot;
|
||||
// }
|
||||
//
|
||||
// public GhostItemSubmitPacket(FriendlyByteBuf buffer) {
|
||||
// item = buffer.readItem();
|
||||
// slot = buffer.readInt();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void write(FriendlyByteBuf buffer) {
|
||||
// buffer.writeItem(item);
|
||||
// buffer.writeInt(slot);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean handle(Context context) {
|
||||
// context.enqueueWork(() -> {
|
||||
// ServerPlayer player = context.getSender();
|
||||
// if (player == null)
|
||||
// return;
|
||||
//
|
||||
// if (player.containerMenu instanceof GhostItemMenu<?> menu) {
|
||||
// menu.ghostInventory.setStackInSlot(slot, item);
|
||||
// menu.getSlot(36 + slot).setChanged();
|
||||
// }
|
||||
// });
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -1,158 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public class BoxElement extends RenderElement {
|
||||
|
||||
protected Color background = new Color(0xff000000, true);
|
||||
protected Color borderTop = new Color(0x40ffeedd, true);
|
||||
protected Color borderBot = new Color(0x20ffeedd, true);
|
||||
protected int borderOffset = 2;
|
||||
|
||||
public <T extends BoxElement> T withBackground(Color color) {
|
||||
this.background = color;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxElement> T withBackground(int color) {
|
||||
return withBackground(new Color(color, true));
|
||||
}
|
||||
|
||||
public <T extends BoxElement> T flatBorder(Color color) {
|
||||
this.borderTop = color;
|
||||
this.borderBot = color;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxElement> T flatBorder(int color) {
|
||||
return flatBorder(new Color(color, true));
|
||||
}
|
||||
|
||||
public <T extends BoxElement> T gradientBorder(Couple<Color> colors) {
|
||||
this.borderTop = colors.getFirst();
|
||||
this.borderBot = colors.getSecond();
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxElement> T gradientBorder(Color top, Color bot) {
|
||||
this.borderTop = top;
|
||||
this.borderBot = bot;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxElement> T gradientBorder(int top, int bot) {
|
||||
return gradientBorder(new Color(top, true), new Color(bot, true));
|
||||
}
|
||||
|
||||
public <T extends BoxElement> T withBorderOffset(int offset) {
|
||||
this.borderOffset = offset;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics) {
|
||||
renderBox(graphics.pose());
|
||||
}
|
||||
|
||||
//total box width = 1 * 2 (outer border) + 1 * 2 (inner color border) + 2 * borderOffset + width
|
||||
//defaults to 2 + 2 + 4 + 16 = 24px
|
||||
//batch everything together to save a bunch of gl calls over ScreenUtils
|
||||
protected void renderBox(PoseStack ms) {
|
||||
/*
|
||||
* _____________
|
||||
* _|_____________|_
|
||||
* | | ___________ | |
|
||||
* | | | | | | |
|
||||
* | | | | | | |
|
||||
* | | |--* | | | |
|
||||
* | | | h | | |
|
||||
* | | | --w-+ | | |
|
||||
* | | | | | |
|
||||
* | | |_________| | |
|
||||
* |_|_____________|_|
|
||||
* |_____________|
|
||||
*
|
||||
* */
|
||||
// RenderSystem.disableTexture();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
|
||||
Matrix4f model = ms.last().pose();
|
||||
int f = borderOffset;
|
||||
Color c1 = background.copy().scaleAlpha(alpha);
|
||||
Color c2 = borderTop.copy().scaleAlpha(alpha);
|
||||
Color c3 = borderBot.copy().scaleAlpha(alpha);
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder b = tessellator.getBuilder();
|
||||
|
||||
b.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
//outer top
|
||||
b.vertex(model, x - f - 1 , y - f - 2 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y - f - 2 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
//outer left
|
||||
b.vertex(model, x - f - 2 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 2 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
//outer bottom
|
||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y + f + 2 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y + f + 2 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
//outer right
|
||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 2 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 2 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
//inner background - also render behind the inner edges
|
||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c1.getRed(), c1.getGreen(), c1.getBlue(), c1.getAlpha()).endVertex();
|
||||
tessellator.end();
|
||||
b.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
//inner top - includes corners
|
||||
b.vertex(model, x - f - 1 , y - f - 1 , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y - f - 1 , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
//inner left - excludes corners
|
||||
b.vertex(model, x - f - 1 , y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f , y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f , y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
//inner bottom - includes corners
|
||||
b.vertex(model, x - f - 1 , y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
b.vertex(model, x - f - 1 , y + f + 1 + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y + f + 1 + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
//inner right - excludes corners
|
||||
b.vertex(model, x + f + width, y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y + f + height, z).color(c3.getRed(), c3.getGreen(), c3.getBlue(), c3.getAlpha()).endVertex();
|
||||
b.vertex(model, x + f + 1 + width, y - f , z).color(c2.getRed(), c2.getGreen(), c2.getBlue(), c2.getAlpha()).endVertex();
|
||||
|
||||
tessellator.end();
|
||||
|
||||
RenderSystem.disableBlend();
|
||||
// RenderSystem.enableTexture();
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
|
||||
public class CombinedStencilElement extends StencilElement {
|
||||
|
||||
private StencilElement element1;
|
||||
private StencilElement element2;
|
||||
private ElementMode mode;
|
||||
|
||||
private CombinedStencilElement() {}
|
||||
|
||||
public static CombinedStencilElement of(@Nonnull StencilElement element1, @Nonnull StencilElement element2) {
|
||||
return of(element1, element2, ElementMode.FIRST);
|
||||
}
|
||||
|
||||
public static CombinedStencilElement of(@Nonnull StencilElement element1, @Nonnull StencilElement element2, ElementMode mode) {
|
||||
CombinedStencilElement e = new CombinedStencilElement();
|
||||
e.element1 = element1;
|
||||
e.element2 = element2;
|
||||
e.mode = mode;
|
||||
return e;
|
||||
}
|
||||
|
||||
public <T extends CombinedStencilElement> T withFirst(StencilElement element) {
|
||||
this.element1 = element;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends CombinedStencilElement> T withSecond(StencilElement element) {
|
||||
this.element2 = element;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends CombinedStencilElement> T withMode(ElementMode mode) {
|
||||
this.mode = mode;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderStencil(GuiGraphics graphics) {
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
element1.transform(ms);
|
||||
element1.withBounds(width, height);
|
||||
element1.renderStencil(graphics);
|
||||
ms.popPose();
|
||||
ms.pushPose();
|
||||
element2.transform(ms);
|
||||
element2.withBounds(width, height);
|
||||
element2.renderStencil(graphics);
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderElement(GuiGraphics graphics) {
|
||||
if (mode.rendersFirst())
|
||||
element1.<StencilElement>withBounds(width, height).renderElement(graphics);
|
||||
|
||||
if (mode.rendersSecond())
|
||||
element2.<StencilElement>withBounds(width, height).renderElement(graphics);
|
||||
}
|
||||
|
||||
public enum ElementMode {
|
||||
FIRST, SECOND, BOTH;
|
||||
|
||||
boolean rendersFirst() {
|
||||
return this == FIRST || this == BOTH;
|
||||
}
|
||||
|
||||
boolean rendersSecond() {
|
||||
return this == SECOND || this == BOTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
|
||||
public class DelegatedStencilElement extends StencilElement {
|
||||
|
||||
protected static final ElementRenderer EMPTY_RENDERER = (graphics, width, height, alpha) -> {};
|
||||
protected static final ElementRenderer DEFAULT_ELEMENT = (graphics, width, height, alpha) -> UIRenderHelper.angledGradient(graphics, 0, -3, 5, height+4, width+6, new Color(0xff_10dd10).scaleAlpha(alpha), new Color(0xff_1010dd).scaleAlpha(alpha));
|
||||
|
||||
protected ElementRenderer stencil;
|
||||
protected ElementRenderer element;
|
||||
|
||||
public DelegatedStencilElement() {
|
||||
stencil = EMPTY_RENDERER;
|
||||
element = DEFAULT_ELEMENT;
|
||||
}
|
||||
|
||||
public DelegatedStencilElement(ElementRenderer stencil, ElementRenderer element) {
|
||||
this.stencil = stencil;
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public <T extends DelegatedStencilElement> T withStencilRenderer(ElementRenderer renderer) {
|
||||
stencil = renderer;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends DelegatedStencilElement> T withElementRenderer(ElementRenderer renderer) {
|
||||
element = renderer;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderStencil(GuiGraphics graphics) {
|
||||
stencil.render(graphics, width, height, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderElement(GuiGraphics graphics) {
|
||||
element.render(graphics, width, height, alpha);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ElementRenderer {
|
||||
void render(GuiGraphics graphics, int width, int height, float alpha);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,301 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
||||
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
||||
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
||||
import com.mojang.blaze3d.platform.Lighting;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.BaseFireBlock;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.LiquidBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.neoforge.client.RenderTypeHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.ILightingSettings;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.VecHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GuiGameElement {
|
||||
|
||||
public static GuiRenderBuilder of(ItemStack stack) {
|
||||
return new GuiItemRenderBuilder(stack);
|
||||
}
|
||||
|
||||
public static GuiRenderBuilder of(ItemLike itemProvider) {
|
||||
return new GuiItemRenderBuilder(itemProvider);
|
||||
}
|
||||
|
||||
public static GuiRenderBuilder of(BlockState state) {
|
||||
return new GuiBlockStateRenderBuilder(state);
|
||||
}
|
||||
|
||||
public static GuiRenderBuilder of(PartialModel partial) {
|
||||
return new GuiBlockPartialRenderBuilder(partial);
|
||||
}
|
||||
|
||||
public static GuiRenderBuilder of(Fluid fluid) {
|
||||
return new GuiBlockStateRenderBuilder(fluid.defaultFluidState()
|
||||
.createLegacyBlock()
|
||||
.setValue(LiquidBlock.LEVEL, 0));
|
||||
}
|
||||
|
||||
public static abstract class GuiRenderBuilder extends RenderElement {
|
||||
protected double xLocal, yLocal, zLocal;
|
||||
protected double xRot, yRot, zRot;
|
||||
protected double scale = 1;
|
||||
protected int color = 0xFFFFFF;
|
||||
protected Vec3 rotationOffset = Vec3.ZERO;
|
||||
protected ILightingSettings customLighting = null;
|
||||
|
||||
public GuiRenderBuilder atLocal(double x, double y, double z) {
|
||||
this.xLocal = x;
|
||||
this.yLocal = y;
|
||||
this.zLocal = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiRenderBuilder rotate(double xRot, double yRot, double zRot) {
|
||||
this.xRot = xRot;
|
||||
this.yRot = yRot;
|
||||
this.zRot = zRot;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiRenderBuilder rotateBlock(double xRot, double yRot, double zRot) {
|
||||
return this.rotate(xRot, yRot, zRot)
|
||||
.withRotationOffset(VecHelper.getCenterOf(BlockPos.ZERO));
|
||||
}
|
||||
|
||||
public GuiRenderBuilder scale(double scale) {
|
||||
this.scale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiRenderBuilder color(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiRenderBuilder withRotationOffset(Vec3 offset) {
|
||||
this.rotationOffset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiRenderBuilder lighting(ILightingSettings lighting) {
|
||||
customLighting = lighting;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void prepareMatrix(PoseStack matrixStack) {
|
||||
matrixStack.pushPose();
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
prepareLighting(matrixStack);
|
||||
}
|
||||
|
||||
protected void transformMatrix(PoseStack matrixStack) {
|
||||
matrixStack.translate(x, y, z);
|
||||
matrixStack.scale((float) scale, (float) scale, (float) scale);
|
||||
matrixStack.translate(xLocal, yLocal, zLocal);
|
||||
UIRenderHelper.flipForGuiRender(matrixStack);
|
||||
matrixStack.translate(rotationOffset.x, rotationOffset.y, rotationOffset.z);
|
||||
matrixStack.mulPose(Axis.ZP.rotationDegrees((float) zRot));
|
||||
matrixStack.mulPose(Axis.XP.rotationDegrees((float) xRot));
|
||||
matrixStack.mulPose(Axis.YP.rotationDegrees((float) yRot));
|
||||
matrixStack.translate(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z);
|
||||
}
|
||||
|
||||
protected void cleanUpMatrix(PoseStack matrixStack) {
|
||||
matrixStack.popPose();
|
||||
cleanUpLighting(matrixStack);
|
||||
}
|
||||
|
||||
protected void prepareLighting(PoseStack matrixStack) {
|
||||
if (customLighting != null) {
|
||||
customLighting.applyLighting();
|
||||
} else {
|
||||
Lighting.setupFor3DItems();
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanUpLighting(PoseStack matrixStack) {
|
||||
if (customLighting != null) {
|
||||
Lighting.setupFor3DItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class GuiBlockModelRenderBuilder extends GuiRenderBuilder {
|
||||
|
||||
protected BakedModel blockModel;
|
||||
protected BlockState blockState;
|
||||
|
||||
public GuiBlockModelRenderBuilder(BakedModel blockmodel, @Nullable BlockState blockState) {
|
||||
this.blockState = blockState == null ? Blocks.AIR.defaultBlockState() : blockState;
|
||||
this.blockModel = blockmodel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics) {
|
||||
PoseStack matrixStack = graphics.pose();
|
||||
prepareMatrix(matrixStack);
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
BlockRenderDispatcher blockRenderer = mc.getBlockRenderer();
|
||||
MultiBufferSource.BufferSource buffer = mc.renderBuffers()
|
||||
.bufferSource();
|
||||
|
||||
transformMatrix(matrixStack);
|
||||
|
||||
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
|
||||
renderModel(blockRenderer, buffer, matrixStack);
|
||||
|
||||
cleanUpMatrix(matrixStack);
|
||||
}
|
||||
|
||||
protected void renderModel(BlockRenderDispatcher blockRenderer, MultiBufferSource.BufferSource buffer,
|
||||
PoseStack ms) {
|
||||
if (blockState.getBlock() == Blocks.AIR) {
|
||||
RenderType renderType = Sheets.translucentCullBlockSheet();
|
||||
blockRenderer.getModelRenderer()
|
||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel, 1, 1, 1,
|
||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelUtil.VIRTUAL_DATA, null);
|
||||
} else {
|
||||
int color = Minecraft.getInstance()
|
||||
.getBlockColors()
|
||||
.getColor(blockState, null, null, 0);
|
||||
Color rgb = new Color(color == -1 ? this.color : color);
|
||||
|
||||
for (RenderType chunkType : blockModel.getRenderTypes(blockState, RandomSource.create(42L), ModelUtil.VIRTUAL_DATA)) {
|
||||
RenderType renderType = RenderTypeHelper.getEntityRenderType(chunkType, true);
|
||||
blockRenderer.getModelRenderer()
|
||||
.renderModel(ms.last(), buffer.getBuffer(renderType), blockState, blockModel,
|
||||
rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(),
|
||||
LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, ModelUtil.VIRTUAL_DATA, chunkType);
|
||||
}
|
||||
}
|
||||
|
||||
buffer.endBatch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GuiBlockStateRenderBuilder extends GuiBlockModelRenderBuilder {
|
||||
|
||||
public GuiBlockStateRenderBuilder(BlockState blockstate) {
|
||||
super(Minecraft.getInstance()
|
||||
.getBlockRenderer()
|
||||
.getBlockModel(blockstate), blockstate);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderModel(BlockRenderDispatcher blockRenderer, MultiBufferSource.BufferSource buffer,
|
||||
PoseStack ms) {
|
||||
if (blockState.getBlock() instanceof BaseFireBlock) {
|
||||
Lighting.setupForFlatItems();
|
||||
super.renderModel(blockRenderer, buffer, ms);
|
||||
Lighting.setupFor3DItems();
|
||||
return;
|
||||
}
|
||||
|
||||
super.renderModel(blockRenderer, buffer, ms);
|
||||
|
||||
if (blockState.getFluidState()
|
||||
.isEmpty())
|
||||
return;
|
||||
|
||||
// FluidRenderer.renderFluidBox(new FluidStack(blockState.getFluidState()
|
||||
// .getType(), 1000), 0, 0, 0, 1, 1, 1, buffer, ms, LightTexture.FULL_BRIGHT, false);
|
||||
// buffer.endBatch();
|
||||
}
|
||||
}
|
||||
|
||||
public static class GuiBlockPartialRenderBuilder extends GuiBlockModelRenderBuilder {
|
||||
|
||||
public GuiBlockPartialRenderBuilder(PartialModel partial) {
|
||||
super(partial.get(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GuiItemRenderBuilder extends GuiRenderBuilder {
|
||||
|
||||
private final ItemStack stack;
|
||||
|
||||
public GuiItemRenderBuilder(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public GuiItemRenderBuilder(ItemLike provider) {
|
||||
this(new ItemStack(provider));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics) {
|
||||
PoseStack matrixStack = graphics.pose();
|
||||
prepareMatrix(matrixStack);
|
||||
transformMatrix(matrixStack);
|
||||
renderItemIntoGUI(matrixStack, stack, customLighting == null);
|
||||
cleanUpMatrix(matrixStack);
|
||||
}
|
||||
|
||||
public static void renderItemIntoGUI(PoseStack matrixStack, ItemStack stack, boolean useDefaultLighting) {
|
||||
ItemRenderer renderer = Minecraft.getInstance().getItemRenderer();
|
||||
BakedModel bakedModel = renderer.getModel(stack, null, null, 0);
|
||||
|
||||
Minecraft.getInstance().textureManager.getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
|
||||
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0, 0, 100.0F);
|
||||
matrixStack.translate(8.0F, -8.0F, 0.0F);
|
||||
matrixStack.scale(16.0F, 16.0F, 16.0F);
|
||||
MultiBufferSource.BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
boolean flatLighting = !bakedModel.usesBlockLight();
|
||||
if (useDefaultLighting && flatLighting) {
|
||||
Lighting.setupForFlatItems();
|
||||
}
|
||||
|
||||
renderer.render(stack, ItemDisplayContext.GUI, false, matrixStack, buffer, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, bakedModel);
|
||||
RenderSystem.disableDepthTest();
|
||||
buffer.endBatch();
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
if (useDefaultLighting && flatLighting) {
|
||||
Lighting.setupFor3DItems();
|
||||
}
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
|
||||
public abstract class RenderElement implements ScreenElement {
|
||||
|
||||
public static final RenderElement EMPTY = new RenderElement() {
|
||||
@Override
|
||||
public void render(GuiGraphics graphics) {
|
||||
}
|
||||
};
|
||||
|
||||
public static RenderElement of(ScreenElement renderable) {
|
||||
return new SimpleRenderElement(renderable);
|
||||
}
|
||||
|
||||
protected int width = 16, height = 16;
|
||||
protected float x = 0, y = 0, z = 0;
|
||||
protected float alpha = 1f;
|
||||
|
||||
public <T extends RenderElement> T at(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends RenderElement> T at(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends RenderElement> T withBounds(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends RenderElement> T withAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public abstract void render(GuiGraphics graphics);
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int x, int y) {
|
||||
this.at(x, y).render(graphics);
|
||||
}
|
||||
|
||||
public static class SimpleRenderElement extends RenderElement {
|
||||
|
||||
private ScreenElement renderable;
|
||||
|
||||
public SimpleRenderElement(ScreenElement renderable) {
|
||||
this.renderable = renderable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics) {
|
||||
renderable.render(graphics, (int) x, (int) y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
public interface ScreenElement {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
void render(GuiGraphics graphics, int x, int y);
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
|
||||
public abstract class StencilElement extends RenderElement {
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics) {
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
transform(ms);
|
||||
prepareStencil(ms);
|
||||
renderStencil(graphics);
|
||||
prepareElement(ms);
|
||||
renderElement(graphics);
|
||||
cleanUp(ms);
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
protected abstract void renderStencil(GuiGraphics graphics);
|
||||
|
||||
protected abstract void renderElement(GuiGraphics graphics);
|
||||
|
||||
protected void transform(PoseStack ms) {
|
||||
ms.translate(x, y, z);
|
||||
}
|
||||
|
||||
protected void prepareStencil(PoseStack ms) {
|
||||
GL11.glDisable(GL11.GL_STENCIL_TEST);
|
||||
RenderSystem.stencilMask(~0);
|
||||
RenderSystem.clear(GL11.GL_STENCIL_BUFFER_BIT, Minecraft.ON_OSX);
|
||||
GL11.glEnable(GL11.GL_STENCIL_TEST);
|
||||
RenderSystem.stencilOp(GL11.GL_REPLACE, GL11.GL_KEEP, GL11.GL_KEEP);
|
||||
RenderSystem.stencilMask(0xFF);
|
||||
RenderSystem.stencilFunc(GL11.GL_NEVER, 1, 0xFF);
|
||||
}
|
||||
|
||||
protected void prepareElement(PoseStack ms) {
|
||||
GL11.glEnable(GL11.GL_STENCIL_TEST);
|
||||
RenderSystem.stencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
|
||||
RenderSystem.stencilFunc(GL11.GL_EQUAL, 1, 0xFF);
|
||||
}
|
||||
|
||||
protected void cleanUp(PoseStack ms) {
|
||||
GL11.glDisable(GL11.GL_STENCIL_TEST);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
|
||||
public class TextStencilElement extends DelegatedStencilElement {
|
||||
|
||||
protected Font font;
|
||||
protected MutableComponent component;
|
||||
protected boolean centerVertically = false;
|
||||
protected boolean centerHorizontally = false;
|
||||
|
||||
public TextStencilElement(Font font) {
|
||||
super();
|
||||
this.font = font;
|
||||
height = 10;
|
||||
}
|
||||
|
||||
public TextStencilElement(Font font, String text) {
|
||||
this(font);
|
||||
component = Components.literal(text);
|
||||
}
|
||||
|
||||
public TextStencilElement(Font font, MutableComponent component) {
|
||||
this(font);
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public TextStencilElement withText(String text) {
|
||||
component = Components.literal(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextStencilElement withText(MutableComponent component) {
|
||||
this.component = component;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextStencilElement centered(boolean vertical, boolean horizontal) {
|
||||
this.centerVertically = vertical;
|
||||
this.centerHorizontally = horizontal;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderStencil(GuiGraphics graphics) {
|
||||
float x = 0, y = 0;
|
||||
if (centerHorizontally)
|
||||
x = width / 2f - font.width(component) / 2f;
|
||||
|
||||
if (centerVertically)
|
||||
y = height / 2f - (font.lineHeight - 1) / 2f;
|
||||
|
||||
graphics.drawString(font, component, Math.round(x), Math.round(y), 0xff_000000, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderElement(GuiGraphics graphics) {
|
||||
float x = 0, y = 0;
|
||||
if (centerHorizontally)
|
||||
x = width / 2f - font.width(component) / 2f;
|
||||
|
||||
if (centerVertically)
|
||||
y = height / 2f - (font.lineHeight - 1) / 2f;
|
||||
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
ms.translate(x, y, 0);
|
||||
element.render(graphics, font.width(component), font.lineHeight + 2, alpha);
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
public MutableComponent getComponent() {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||
|
||||
import net.createmod.catnip.gui.TickableGuiEventListener;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -1,226 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.Theme;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.UIRenderHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.BoxElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.DelegatedStencilElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.animation.LerpedFloat;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BoxWidget extends ElementWidget {
|
||||
|
||||
public static final Function<BoxWidget, DelegatedStencilElement.ElementRenderer> gradientFactory = (box) -> (ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, w/2, -2, w + 4, h + 4, box.gradientColor1, box.gradientColor2);
|
||||
|
||||
protected BoxElement box;
|
||||
|
||||
protected Color customBorderTop;
|
||||
protected Color customBorderBot;
|
||||
protected Color customBackground;
|
||||
protected boolean animateColors = true;
|
||||
protected LerpedFloat colorAnimation = LerpedFloat.linear();
|
||||
|
||||
protected Color gradientColor1, gradientColor2;
|
||||
private Color previousColor1, previousColor2;
|
||||
private Color colorTarget1 = Theme.c(getIdleTheme(), true).copy();
|
||||
private Color colorTarget2 = Theme.c(getIdleTheme(), false).copy();
|
||||
|
||||
public BoxWidget() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public BoxWidget(int x, int y) {
|
||||
this(x, y, 16, 16);
|
||||
}
|
||||
|
||||
public BoxWidget(int x, int y, int width, int height) {
|
||||
super(x, y, width, height);
|
||||
box = new BoxElement()
|
||||
.at(x, y)
|
||||
.withBounds(width, height);
|
||||
gradientColor1 = colorTarget1;
|
||||
gradientColor2 = colorTarget2;
|
||||
}
|
||||
|
||||
public <T extends BoxWidget> T withBounds(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxWidget> T withBorderColors(Couple<Color> colors) {
|
||||
this.customBorderTop = colors.getFirst();
|
||||
this.customBorderBot = colors.getSecond();
|
||||
updateColorsFromState();
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxWidget> T withBorderColors(Color top, Color bot) {
|
||||
this.customBorderTop = top;
|
||||
this.customBorderBot = bot;
|
||||
updateColorsFromState();
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxWidget> T withCustomBackground(Color color) {
|
||||
this.customBackground = color;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends BoxWidget> T animateColors(boolean b) {
|
||||
this.animateColors = b;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
colorAnimation.tickChaser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(double x, double y) {
|
||||
super.onClick(x, y);
|
||||
|
||||
gradientColor1 = Theme.c(getClickTheme(), true);
|
||||
gradientColor2 = Theme.c(getClickTheme(), false);
|
||||
startGradientAnimation(getColorForState(true), getColorForState(false), true, 0.15);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
super.beforeRender(graphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
if (isHovered != wasHovered) {
|
||||
startGradientAnimation(
|
||||
getColorForState(true),
|
||||
getColorForState(false),
|
||||
isHovered
|
||||
);
|
||||
}
|
||||
|
||||
if (colorAnimation.settled()) {
|
||||
gradientColor1 = colorTarget1;
|
||||
gradientColor2 = colorTarget2;
|
||||
} else {
|
||||
float animationValue = 1 - Math.abs(colorAnimation.getValue(partialTicks));
|
||||
gradientColor1 = Color.mixColors(previousColor1, colorTarget1, animationValue);
|
||||
gradientColor2 = Color.mixColors(previousColor2, colorTarget2, animationValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
float fadeValue = fade.getValue(partialTicks);
|
||||
if (fadeValue < .1f)
|
||||
return;
|
||||
|
||||
box.withAlpha(fadeValue);
|
||||
box.withBackground(customBackground != null ? customBackground : Theme.c(Theme.Key.PONDER_BACKGROUND_TRANSPARENT))
|
||||
.gradientBorder(gradientColor1, gradientColor2)
|
||||
.at(getX(), getY(), z)
|
||||
.withBounds(width, height)
|
||||
.render(graphics);
|
||||
|
||||
super.doRender(graphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
wasHovered = isHovered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(double mX, double mY) {
|
||||
if (!active || !visible)
|
||||
return false;
|
||||
|
||||
float padX = 2 + paddingX;
|
||||
float padY = 2 + paddingY;
|
||||
|
||||
return getX() - padX <= mX && getY() - padY <= mY && mX < getX() + padX + width && mY < getY() + padY + height;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean clicked(double pMouseX, double pMouseY) {
|
||||
if (!active || !visible)
|
||||
return false;
|
||||
return isMouseOver(pMouseX, pMouseY);
|
||||
}
|
||||
|
||||
public BoxElement getBox() {
|
||||
return box;
|
||||
}
|
||||
|
||||
public void updateColorsFromState() {
|
||||
colorTarget1 = getColorForState(true);
|
||||
colorTarget2 = getColorForState(false);
|
||||
}
|
||||
|
||||
public void animateGradientFromState() {
|
||||
startGradientAnimation(
|
||||
getColorForState(true),
|
||||
getColorForState(false),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
private void startGradientAnimation(Color c1, Color c2, boolean positive, double expSpeed) {
|
||||
if (!animateColors)
|
||||
return;
|
||||
|
||||
colorAnimation.startWithValue(positive ? 1 : -1);
|
||||
colorAnimation.chase(0, expSpeed, LerpedFloat.Chaser.EXP);
|
||||
colorAnimation.tickChaser();
|
||||
|
||||
previousColor1 = gradientColor1;
|
||||
previousColor2 = gradientColor2;
|
||||
|
||||
colorTarget1 = c1;
|
||||
colorTarget2 = c2;
|
||||
}
|
||||
|
||||
private void startGradientAnimation(Color c1, Color c2, boolean positive) {
|
||||
startGradientAnimation(c1, c2, positive, 0.6);
|
||||
}
|
||||
|
||||
private Color getColorForState(boolean first) {
|
||||
if (!active)
|
||||
return Theme.p(getDisabledTheme()).get(first);
|
||||
|
||||
if (isHovered) {
|
||||
if (first)
|
||||
return customBorderTop != null ? customBorderTop.darker() : Theme.c(getHoverTheme(), true);
|
||||
else
|
||||
return customBorderBot != null ? customBorderBot.darker() : Theme.c(getHoverTheme(), false);
|
||||
}
|
||||
|
||||
if (first)
|
||||
return customBorderTop != null ? customBorderTop : Theme.c(getIdleTheme(), true);
|
||||
else
|
||||
return customBorderBot != null ? customBorderBot : Theme.c(getIdleTheme(), false);
|
||||
}
|
||||
|
||||
public Theme.Key getDisabledTheme() {
|
||||
return Theme.Key.BUTTON_DISABLE;
|
||||
}
|
||||
|
||||
public Theme.Key getIdleTheme() {
|
||||
return Theme.Key.BUTTON_IDLE;
|
||||
}
|
||||
|
||||
public Theme.Key getHoverTheme() {
|
||||
return Theme.Key.BUTTON_HOVER;
|
||||
}
|
||||
|
||||
public Theme.Key getClickTheme() {
|
||||
return Theme.Key.BUTTON_CLICK;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.RenderElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.animation.LerpedFloat;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class ElementWidget extends AbstractSimiWidget {
|
||||
|
||||
protected RenderElement element = RenderElement.EMPTY;
|
||||
|
||||
protected boolean usesFade = false;
|
||||
protected int fadeModX;
|
||||
protected int fadeModY;
|
||||
protected LerpedFloat fade = LerpedFloat.linear().startWithValue(1);
|
||||
|
||||
protected boolean rescaleElement = false;
|
||||
protected float rescaleSizeX;
|
||||
protected float rescaleSizeY;
|
||||
|
||||
protected float paddingX = 0;
|
||||
protected float paddingY = 0;
|
||||
|
||||
public ElementWidget(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
|
||||
public ElementWidget(int x, int y, int width, int height) {
|
||||
super(x, y, width, height);
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T showingElement(RenderElement element) {
|
||||
this.element = element;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T showing(ScreenElement renderable) {
|
||||
return this.showingElement(RenderElement.of(renderable));
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T modifyElement(Consumer<RenderElement> consumer) {
|
||||
if (element != null)
|
||||
consumer.accept(element);
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T mapElement(UnaryOperator<RenderElement> function) {
|
||||
if (element != null)
|
||||
element = function.apply(element);
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T withPadding(float paddingX, float paddingY) {
|
||||
this.paddingX = paddingX;
|
||||
this.paddingY = paddingY;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T enableFade(int fadeModifierX, int fadeModifierY) {
|
||||
this.fade.startWithValue(0);
|
||||
this.usesFade = true;
|
||||
this.fadeModX = fadeModifierX;
|
||||
this.fadeModY = fadeModifierY;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T disableFade() {
|
||||
this.fade.startWithValue(1);
|
||||
this.usesFade = false;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public LerpedFloat fade() {
|
||||
return fade;
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T fade(float target) {
|
||||
fade.chase(target, 0.1, LerpedFloat.Chaser.EXP);
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rescaling and its effects aren't properly tested with most elements.
|
||||
* Thought it should work fine when using a TextStencilElement.
|
||||
* Check BaseConfigScreen's title for such an example.
|
||||
*/
|
||||
@Deprecated
|
||||
public <T extends ElementWidget> T rescaleElement(float rescaleSizeX, float rescaleSizeY) {
|
||||
this.rescaleElement = true;
|
||||
this.rescaleSizeX = rescaleSizeX;
|
||||
this.rescaleSizeY = rescaleSizeY;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public <T extends ElementWidget> T disableRescale() {
|
||||
this.rescaleElement = false;
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
fade.tickChaser();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
super.beforeRender(graphics, mouseX, mouseY, partialTicks);
|
||||
isHovered = isMouseOver(mouseX, mouseY);
|
||||
|
||||
float fadeValue = fade.getValue(partialTicks);
|
||||
element.withAlpha(fadeValue);
|
||||
if (fadeValue < 1) {
|
||||
graphics.pose().translate((1 - fadeValue) * fadeModX, (1 - fadeValue) * fadeModY, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRender(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
PoseStack ms = graphics.pose();
|
||||
ms.pushPose();
|
||||
ms.translate(getX() + paddingX, getY() + paddingY, z);
|
||||
float innerWidth = width - 2 * paddingX;
|
||||
float innerHeight = height - 2 * paddingY;
|
||||
float eX = element.getX(), eY = element.getY();
|
||||
if (rescaleElement) {
|
||||
float xScale = innerWidth / rescaleSizeX;
|
||||
float yScale = innerHeight / rescaleSizeY;
|
||||
ms.scale(xScale, yScale, 1);
|
||||
element.at(eX / xScale, eY / yScale);
|
||||
innerWidth /= xScale;
|
||||
innerHeight /= yScale;
|
||||
}
|
||||
element.withBounds((int) innerWidth, (int) innerHeight).render(graphics);
|
||||
ms.popPose();
|
||||
if (rescaleElement) {
|
||||
element.at(eX, eY);
|
||||
}
|
||||
}
|
||||
|
||||
public RenderElement getRenderElement() {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.createmod.catnip.gui.element.ScreenElement;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.element.ScreenElement;
|
||||
|
||||
public class IconButton extends AbstractSimiWidget {
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TooltipArea extends AbstractSimiWidget {
|
||||
|
||||
public TooltipArea(int x, int y, int width, int height) {
|
||||
|
||||
@@ -11,7 +11,20 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.ChatFormatting.*;
|
||||
import static net.minecraft.ChatFormatting.AQUA;
|
||||
import static net.minecraft.ChatFormatting.BLUE;
|
||||
import static net.minecraft.ChatFormatting.DARK_GRAY;
|
||||
import static net.minecraft.ChatFormatting.DARK_GREEN;
|
||||
import static net.minecraft.ChatFormatting.DARK_PURPLE;
|
||||
import static net.minecraft.ChatFormatting.DARK_RED;
|
||||
import static net.minecraft.ChatFormatting.GOLD;
|
||||
import static net.minecraft.ChatFormatting.GRAY;
|
||||
import static net.minecraft.ChatFormatting.GREEN;
|
||||
import static net.minecraft.ChatFormatting.LIGHT_PURPLE;
|
||||
import static net.minecraft.ChatFormatting.RED;
|
||||
import static net.minecraft.ChatFormatting.STRIKETHROUGH;
|
||||
import static net.minecraft.ChatFormatting.WHITE;
|
||||
import static net.minecraft.ChatFormatting.YELLOW;
|
||||
import static nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper.cutStringTextComponent;
|
||||
import static nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper.cutTextComponent;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||
|
||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Pair;
|
||||
import net.createmod.catnip.data.Pair;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -40,9 +40,9 @@ public class ItemHelper {
|
||||
|
||||
public static void addToList(ItemStack stack, List<ItemStack> stacks) {
|
||||
for (ItemStack s : stacks) {
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, s))
|
||||
if (!ItemStack.isSameItemSameComponents(stack, s))
|
||||
continue;
|
||||
int transferred = Math.min(s.getMaxStackSize() - s.getCount(), stack.getCount());
|
||||
int transferred = Math.min(s.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) - s.getCount(), stack.getCount());
|
||||
s.grow(transferred);
|
||||
stack.shrink(transferred);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public class ItemHelper {
|
||||
|
||||
if (!extracting.isEmpty() && !hasEnoughItems && potentialOtherMatch) {
|
||||
ItemStack blackListed = extracting.copy();
|
||||
test = test.and(i -> !ItemHandlerHelper.canItemStacksStack(i, blackListed));
|
||||
test = test.and(i -> !ItemStack.isSameItemSameComponents(i, blackListed));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ public class ItemHelper {
|
||||
}
|
||||
|
||||
public static boolean canItemStackAmountsStack(ItemStack a, ItemStack b) {
|
||||
return ItemHandlerHelper.canItemStacksStack(a, b) && a.getCount() + b.getCount() <= a.getMaxStackSize();
|
||||
return ItemStack.isSameItemSameComponents(a, b) && a.getCount() + b.getCount() <= a.getOrDefault(DataComponents.MAX_STACK_SIZE, 64);
|
||||
}
|
||||
|
||||
public static ItemStack findFirstMatch(IItemHandler inv, Predicate<ItemStack> test) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import net.createmod.catnip.data.Couple;
|
||||
import net.createmod.catnip.lang.ClientFontHelper;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
@@ -12,8 +14,6 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import nl.requios.effortlessbuilding.create.foundation.item.ItemDescription.Palette;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Couple;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.FontHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Lang;
|
||||
|
||||
import java.text.BreakIterator;
|
||||
@@ -81,7 +81,7 @@ public class TooltipHelper {
|
||||
}
|
||||
|
||||
Font font = Minecraft.getInstance().font;
|
||||
List<String> lines = FontHelper.cutString(font, markedUp, maxWidthPerLine);
|
||||
List<String> lines = ClientFontHelper.cutString(font, markedUp, maxWidthPerLine);
|
||||
|
||||
// Format
|
||||
String lineStart = Strings.repeat(" ", indent);
|
||||
|
||||
@@ -2,6 +2,7 @@ package nl.requios.effortlessbuilding.create.foundation.item.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.createmod.catnip.data.Iterate;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
@@ -14,7 +15,6 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
|
||||
import net.neoforged.neoforge.client.model.data.ModelData;
|
||||
import nl.requios.effortlessbuilding.create.foundation.render.RenderTypes;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Iterate;
|
||||
|
||||
public class PartialItemModelRenderer {
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//package nl.requios.effortlessbuilding.create.foundation.networking;
|
||||
//
|
||||
//import net.minecraft.client.Minecraft;
|
||||
//import net.minecraft.nbt.CompoundTag;
|
||||
//import net.minecraft.network.FriendlyByteBuf;
|
||||
//import net.minecraft.world.entity.Entity;
|
||||
//import net.neoforged.neoforge.network.NetworkEvent.Context;
|
||||
//
|
||||
//import java.util.HashSet;
|
||||
//
|
||||
//public interface ISyncPersistentData {
|
||||
//
|
||||
// void onPersistentDataUpdated();
|
||||
//
|
||||
// public static class PersistentDataPacket extends SimplePacketBase {
|
||||
//
|
||||
// private int entityId;
|
||||
// private Entity entity;
|
||||
// private CompoundTag readData;
|
||||
//
|
||||
// public PersistentDataPacket(Entity entity) {
|
||||
// this.entity = entity;
|
||||
// this.entityId = entity.getId();
|
||||
// }
|
||||
//
|
||||
// public PersistentDataPacket(FriendlyByteBuf buffer) {
|
||||
// entityId = buffer.readInt();
|
||||
// readData = buffer.readNbt();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void write(FriendlyByteBuf buffer) {
|
||||
// buffer.writeInt(entityId);
|
||||
// buffer.writeNbt(entity.getPersistentData());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean handle(Context context) {
|
||||
// context.enqueueWork(() -> {
|
||||
// Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
||||
// CompoundTag data = entityByID.getPersistentData();
|
||||
// new HashSet<>(data.getAllKeys()).forEach(data::remove);
|
||||
// data.merge(readData);
|
||||
// if (!(entityByID instanceof ISyncPersistentData))
|
||||
// return;
|
||||
// ((ISyncPersistentData) entityByID).onPersistentDataUpdated();
|
||||
// });
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -1,12 +0,0 @@
|
||||
//package nl.requios.effortlessbuilding.create.foundation.networking;
|
||||
//
|
||||
//import net.minecraft.network.FriendlyByteBuf;
|
||||
//import net.neoforged.neoforge.network.NetworkEvent.Context;
|
||||
//
|
||||
//public abstract class SimplePacketBase {
|
||||
//
|
||||
// public abstract void write(FriendlyByteBuf buffer);
|
||||
//
|
||||
// public abstract boolean handle(Context context);
|
||||
//
|
||||
//}
|
||||
@@ -1,30 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import com.jozufozu.flywheel.core.model.ModelUtil;
|
||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferedData;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BakedModelRenderHelper {
|
||||
|
||||
public static SuperByteBuffer standardBlockRender(BlockState renderedState) {
|
||||
BlockRenderDispatcher dispatcher = Minecraft.getInstance()
|
||||
.getBlockRenderer();
|
||||
return standardModelRender(dispatcher.getBlockModel(renderedState), renderedState);
|
||||
}
|
||||
|
||||
public static SuperByteBuffer standardModelRender(BakedModel model, BlockState referenceState) {
|
||||
return standardModelRender(model, referenceState, new PoseStack());
|
||||
}
|
||||
|
||||
public static SuperByteBuffer standardModelRender(BakedModel model, BlockState referenceState, PoseStack ms) {
|
||||
ShadeSeparatedBufferedData data = ModelUtil.getBufferedData(model, referenceState, ms);
|
||||
SuperByteBuffer sbb = new SuperByteBuffer(data);
|
||||
data.release();
|
||||
return sbb;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.engine_room.flywheel.api.visualization.VisualizationManager;
|
||||
import dev.engine_room.flywheel.lib.transform.TransformStack;
|
||||
import dev.engine_room.flywheel.lib.visualization.VisualizationHelper;
|
||||
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||
import net.createmod.catnip.registry.RegisteredObjectsHelper;
|
||||
import net.createmod.catnip.render.SuperByteBuffer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import nl.requios.effortlessbuilding.create.foundation.virtualWorld.VirtualRenderWorld;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class BlockEntityRenderHelper {
|
||||
|
||||
public static void renderBlockEntities(Level world, Iterable<BlockEntity> customRenderBEs, PoseStack ms,
|
||||
MultiBufferSource buffer) {
|
||||
renderBlockEntities(world, null, customRenderBEs, ms, null, buffer);
|
||||
}
|
||||
|
||||
public static void renderBlockEntities(Level world, Iterable<BlockEntity> customRenderBEs, PoseStack ms,
|
||||
MultiBufferSource buffer, float pt) {
|
||||
renderBlockEntities(world, null, customRenderBEs, ms, null, buffer, pt);
|
||||
}
|
||||
|
||||
public static void renderBlockEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
||||
Iterable<BlockEntity> customRenderBEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer) {
|
||||
renderBlockEntities(world, renderWorld, customRenderBEs, ms, lightTransform, buffer,
|
||||
AnimationTickHolder.getPartialTicks());
|
||||
}
|
||||
|
||||
public static void renderBlockEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
||||
Iterable<BlockEntity> customRenderBEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer,
|
||||
float pt) {
|
||||
Iterator<BlockEntity> iterator = customRenderBEs.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
BlockEntity blockEntity = iterator.next();
|
||||
if (VisualizationManager.supportsVisualization(world) && VisualizationHelper.skipVanillaRender(blockEntity))
|
||||
continue;
|
||||
|
||||
BlockEntityRenderer<BlockEntity> renderer = Minecraft.getInstance().getBlockEntityRenderDispatcher().getRenderer(blockEntity);
|
||||
if (renderer == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos pos = blockEntity.getBlockPos();
|
||||
ms.pushPose();
|
||||
TransformStack.of(ms)
|
||||
.translate(pos);
|
||||
|
||||
try {
|
||||
int worldLight = getCombinedLight(world, getLightPos(lightTransform, pos), renderWorld, pos);
|
||||
|
||||
if (renderWorld != null) {
|
||||
// Swap the real world for the render world so that the renderer gets contraption-local information
|
||||
blockEntity.setLevel(renderWorld);
|
||||
renderer.render(blockEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
||||
blockEntity.setLevel(world);
|
||||
} else {
|
||||
renderer.render(blockEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
iterator.remove();
|
||||
|
||||
String message = "BlockEntity " + RegisteredObjectsHelper.getKeyOrThrow(blockEntity.getType())
|
||||
.toString() + " could not be rendered virtually.";
|
||||
// if (AllConfigs.CLIENT.explainRenderErrors.get())
|
||||
Create.LOGGER.error(message, e);
|
||||
// else
|
||||
// Create.LOGGER.error(message);
|
||||
}
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockPos getLightPos(@Nullable Matrix4f lightTransform, BlockPos contraptionPos) {
|
||||
if (lightTransform != null) {
|
||||
Vector4f lightVec = new Vector4f(contraptionPos.getX() + .5f, contraptionPos.getY() + .5f, contraptionPos.getZ() + .5f, 1);
|
||||
lightVec.mul(lightTransform);
|
||||
return BlockPos.containing(lightVec.x(), lightVec.y(), lightVec.z());
|
||||
} else {
|
||||
return contraptionPos;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getCombinedLight(Level world, BlockPos worldPos, @Nullable VirtualRenderWorld renderWorld,
|
||||
BlockPos renderWorldPos) {
|
||||
int worldLight = LevelRenderer.getLightColor(world, worldPos);
|
||||
|
||||
if (renderWorld != null) {
|
||||
int renderWorldLight = LevelRenderer.getLightColor(renderWorld, renderWorldPos);
|
||||
return SuperByteBuffer.maxLight(worldLight, renderWorldLight);
|
||||
}
|
||||
|
||||
return worldLight;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import nl.requios.effortlessbuilding.create.CreateClient;
|
||||
import nl.requios.effortlessbuilding.create.foundation.render.SuperByteBufferCache.Compartment;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.AngleHelper;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING;
|
||||
|
||||
public class CachedBufferer {
|
||||
|
||||
public static final Compartment<BlockState> GENERIC_TILE = new Compartment<>();
|
||||
public static final Compartment<PartialModel> PARTIAL = new Compartment<>();
|
||||
public static final Compartment<Pair<Direction, PartialModel>> DIRECTIONAL_PARTIAL = new Compartment<>();
|
||||
|
||||
public static SuperByteBuffer block(BlockState toRender) {
|
||||
return block(GENERIC_TILE, toRender);
|
||||
}
|
||||
|
||||
public static SuperByteBuffer block(Compartment<BlockState> compartment, BlockState toRender) {
|
||||
return CreateClient.BUFFER_CACHE.get(compartment, toRender, () -> BakedModelRenderHelper.standardBlockRender(toRender));
|
||||
}
|
||||
|
||||
public static SuperByteBuffer partial(PartialModel partial, BlockState referenceState) {
|
||||
return CreateClient.BUFFER_CACHE.get(PARTIAL, partial,
|
||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState));
|
||||
}
|
||||
|
||||
public static SuperByteBuffer partial(PartialModel partial, BlockState referenceState,
|
||||
Supplier<PoseStack> modelTransform) {
|
||||
return CreateClient.BUFFER_CACHE.get(PARTIAL, partial,
|
||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState, modelTransform.get()));
|
||||
}
|
||||
|
||||
public static SuperByteBuffer partialFacing(PartialModel partial, BlockState referenceState) {
|
||||
Direction facing = referenceState.getValue(FACING);
|
||||
return partialFacing(partial, referenceState, facing);
|
||||
}
|
||||
|
||||
public static SuperByteBuffer partialFacing(PartialModel partial, BlockState referenceState, Direction facing) {
|
||||
return partialDirectional(partial, referenceState, facing,
|
||||
rotateToFace(facing));
|
||||
}
|
||||
|
||||
public static SuperByteBuffer partialFacingVertical(PartialModel partial, BlockState referenceState, Direction facing) {
|
||||
return partialDirectional(partial, referenceState, facing,
|
||||
rotateToFaceVertical(facing));
|
||||
}
|
||||
|
||||
public static SuperByteBuffer partialDirectional(PartialModel partial, BlockState referenceState, Direction dir,
|
||||
Supplier<PoseStack> modelTransform) {
|
||||
return CreateClient.BUFFER_CACHE.get(DIRECTIONAL_PARTIAL, Pair.of(dir, partial),
|
||||
() -> BakedModelRenderHelper.standardModelRender(partial.get(), referenceState, modelTransform.get()));
|
||||
}
|
||||
|
||||
public static Supplier<PoseStack> rotateToFace(Direction facing) {
|
||||
return () -> {
|
||||
PoseStack stack = new PoseStack();
|
||||
TransformStack.cast(stack)
|
||||
.centre()
|
||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
||||
.rotateX(AngleHelper.verticalAngle(facing))
|
||||
.unCentre();
|
||||
return stack;
|
||||
};
|
||||
}
|
||||
|
||||
public static Supplier<PoseStack> rotateToFaceVertical(Direction facing) {
|
||||
return () -> {
|
||||
PoseStack stack = new PoseStack();
|
||||
TransformStack.cast(stack)
|
||||
.centre()
|
||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
||||
.rotateX(AngleHelper.verticalAngle(facing) + 90)
|
||||
.unCentre();
|
||||
return stack;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class ForcedDiffuseState {
|
||||
private static final ThreadLocal<ObjectArrayList<DiffuseLightCalculator>> FORCED_DIFFUSE = ThreadLocal.withInitial(ObjectArrayList::new);
|
||||
|
||||
private ForcedDiffuseState() {
|
||||
}
|
||||
|
||||
public static void pushCalculator(DiffuseLightCalculator calculator) {
|
||||
FORCED_DIFFUSE.get().push(calculator);
|
||||
}
|
||||
|
||||
public static void popCalculator() {
|
||||
FORCED_DIFFUSE.get().pop();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DiffuseLightCalculator getForcedCalculator() {
|
||||
ObjectArrayList<DiffuseLightCalculator> stack = FORCED_DIFFUSE.get();
|
||||
if (stack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return stack.top();
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@ package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import net.minecraft.client.renderer.RenderStateShard;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import nl.requios.effortlessbuilding.create.AllSpecialTextures;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
|
||||
// TODO 1.17: use custom shaders instead of vanilla ones
|
||||
public class RenderTypes extends RenderStateShard {
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
/**
|
||||
* Taken from EntityRendererManager
|
||||
*/
|
||||
public class ShadowRenderHelper {
|
||||
|
||||
private static final RenderType SHADOW_LAYER =
|
||||
RenderType.entityNoOutline(new ResourceLocation("textures/misc/shadow.png"));
|
||||
|
||||
public static void renderShadow(PoseStack matrixStack, MultiBufferSource buffer, float opacity, float radius) {
|
||||
PoseStack.Pose entry = matrixStack.last();
|
||||
VertexConsumer builder = buffer.getBuffer(SHADOW_LAYER);
|
||||
|
||||
opacity /= 2;
|
||||
shadowVertex(entry, builder, opacity, -1 * radius, 0, -1 * radius, 0, 0);
|
||||
shadowVertex(entry, builder, opacity, -1 * radius, 0, 1 * radius, 0, 1);
|
||||
shadowVertex(entry, builder, opacity, 1 * radius, 0, 1 * radius, 1, 1);
|
||||
shadowVertex(entry, builder, opacity, 1 * radius, 0, -1 * radius, 1, 0);
|
||||
}
|
||||
|
||||
public static void renderShadow(PoseStack matrixStack, MultiBufferSource buffer, LevelReader world,
|
||||
Vec3 pos, float opacity, float radius) {
|
||||
float f = radius;
|
||||
|
||||
double d2 = pos.x();
|
||||
double d0 = pos.y();
|
||||
double d1 = pos.z();
|
||||
int i = Mth.floor(d2 - (double) f);
|
||||
int j = Mth.floor(d2 + (double) f);
|
||||
int k = Mth.floor(d0 - (double) f);
|
||||
int l = Mth.floor(d0);
|
||||
int i1 = Mth.floor(d1 - (double) f);
|
||||
int j1 = Mth.floor(d1 + (double) f);
|
||||
PoseStack.Pose entry = matrixStack.last();
|
||||
VertexConsumer builder = buffer.getBuffer(SHADOW_LAYER);
|
||||
|
||||
for (BlockPos blockpos : BlockPos.betweenClosed(new BlockPos(i, k, i1), new BlockPos(j, l, j1))) {
|
||||
renderBlockShadow(entry, builder, world, blockpos, d2, d0, d1, f,
|
||||
opacity);
|
||||
}
|
||||
}
|
||||
|
||||
private static void renderBlockShadow(PoseStack.Pose entry, VertexConsumer builder,
|
||||
LevelReader world, BlockPos pos, double x, double y, double z,
|
||||
float radius, float opacity) {
|
||||
BlockPos blockpos = pos.below();
|
||||
BlockState blockstate = world.getBlockState(blockpos);
|
||||
if (blockstate.getRenderShape() != RenderShape.INVISIBLE && world.getMaxLocalRawBrightness(pos) > 3) {
|
||||
if (blockstate.isCollisionShapeFullBlock(world, blockpos)) {
|
||||
VoxelShape voxelshape = blockstate.getShape(world, pos.below());
|
||||
if (!voxelshape.isEmpty()) {
|
||||
float brightness = LightTexture.getBrightness(world.dimensionType(), world.getMaxLocalRawBrightness(pos));
|
||||
float f = (float) ((opacity - (y - pos.getY()) / 2.0D) * 0.5D * brightness);
|
||||
if (f >= 0.0F) {
|
||||
if (f > 1.0F) {
|
||||
f = 1.0F;
|
||||
}
|
||||
|
||||
AABB AABB = voxelshape.bounds();
|
||||
double d0 = (double) pos.getX() + AABB.minX;
|
||||
double d1 = (double) pos.getX() + AABB.maxX;
|
||||
double d2 = (double) pos.getY() + AABB.minY;
|
||||
double d3 = (double) pos.getZ() + AABB.minZ;
|
||||
double d4 = (double) pos.getZ() + AABB.maxZ;
|
||||
float f1 = (float) (d0 - x);
|
||||
float f2 = (float) (d1 - x);
|
||||
float f3 = (float) (d2 - y + 0.015625D);
|
||||
float f4 = (float) (d3 - z);
|
||||
float f5 = (float) (d4 - z);
|
||||
float f6 = -f1 / 2.0F / radius + 0.5F;
|
||||
float f7 = -f2 / 2.0F / radius + 0.5F;
|
||||
float f8 = -f4 / 2.0F / radius + 0.5F;
|
||||
float f9 = -f5 / 2.0F / radius + 0.5F;
|
||||
shadowVertex(entry, builder, f, f1, f3, f4, f6, f8);
|
||||
shadowVertex(entry, builder, f, f1, f3, f5, f6, f9);
|
||||
shadowVertex(entry, builder, f, f2, f3, f5, f7, f9);
|
||||
shadowVertex(entry, builder, f, f2, f3, f4, f7, f8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void shadowVertex(PoseStack.Pose entry, VertexConsumer builder, float alpha,
|
||||
float x, float y, float z, float u, float v) {
|
||||
builder.vertex(entry.pose(), x, y, z)
|
||||
.color(1.0F, 1.0F, 1.0F, alpha)
|
||||
.uv(u, v)
|
||||
.overlayCoords(OverlayTexture.NO_OVERLAY)
|
||||
.uv2(LightTexture.FULL_BRIGHT)
|
||||
.normal(entry.normal(), 0.0F, 1.0F, 0.0F)
|
||||
.endVertex();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,492 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
|
||||
import com.jozufozu.flywheel.api.vertex.ShadedVertexList;
|
||||
import com.jozufozu.flywheel.api.vertex.VertexList;
|
||||
import com.jozufozu.flywheel.backend.ShadersModHandler;
|
||||
import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferedData;
|
||||
import com.jozufozu.flywheel.core.vertex.BlockVertexList;
|
||||
import com.jozufozu.flywheel.util.Color;
|
||||
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
|
||||
import com.jozufozu.flywheel.util.transform.TStack;
|
||||
import com.jozufozu.flywheel.util.transform.Transform;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
import nl.requios.effortlessbuilding.create.foundation.block.render.SpriteShiftEntry;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
public class SuperByteBuffer implements Transform<SuperByteBuffer>, TStack<SuperByteBuffer> {
|
||||
|
||||
private final VertexList template;
|
||||
private final IntPredicate shadedPredicate;
|
||||
|
||||
// Vertex Position
|
||||
private final PoseStack transforms = new PoseStack();
|
||||
|
||||
// Vertex Coloring
|
||||
private boolean shouldColor;
|
||||
private int r, g, b, a;
|
||||
private boolean disableDiffuseMult;
|
||||
private DiffuseLightCalculator diffuseCalculator;
|
||||
|
||||
// Vertex Texture Coords
|
||||
private SpriteShiftFunc spriteShiftFunc;
|
||||
|
||||
// Vertex Overlay Color
|
||||
private boolean hasOverlay;
|
||||
private int overlay = OverlayTexture.NO_OVERLAY;
|
||||
|
||||
// Vertex Lighting
|
||||
private boolean useWorldLight;
|
||||
private Matrix4f lightTransform;
|
||||
private boolean hasCustomLight;
|
||||
private int packedLightCoords;
|
||||
private boolean hybridLight;
|
||||
|
||||
// Vertex Normals
|
||||
private boolean fullNormalTransform;
|
||||
|
||||
// Temporary
|
||||
private static final Long2IntMap WORLD_LIGHT_CACHE = new Long2IntOpenHashMap();
|
||||
|
||||
public SuperByteBuffer(ByteBuffer vertexBuffer, BufferBuilder.DrawState drawState, int unshadedStartVertex) {
|
||||
int vertexCount = drawState.vertexCount();
|
||||
int stride = drawState.format().getVertexSize();
|
||||
|
||||
ShadedVertexList template = new BlockVertexList.Shaded(vertexBuffer, vertexCount, stride, unshadedStartVertex);
|
||||
shadedPredicate = template::isShaded;
|
||||
this.template = template;
|
||||
|
||||
transforms.pushPose();
|
||||
}
|
||||
|
||||
public SuperByteBuffer(ShadeSeparatedBufferedData data) {
|
||||
this(data.vertexBuffer(), data.drawState(), data.unshadedStartVertex());
|
||||
}
|
||||
|
||||
public SuperByteBuffer(ByteBuffer vertexBuffer, BufferBuilder.DrawState drawState) {
|
||||
int vertexCount = drawState.vertexCount();
|
||||
int stride = drawState.format().getVertexSize();
|
||||
|
||||
template = new BlockVertexList(vertexBuffer, vertexCount, stride);
|
||||
shadedPredicate = index -> true;
|
||||
|
||||
transforms.pushPose();
|
||||
}
|
||||
|
||||
public void renderInto(PoseStack input, VertexConsumer builder) {
|
||||
if (isEmpty())
|
||||
return;
|
||||
|
||||
Matrix4f modelMat = new Matrix4f(input.last()
|
||||
.pose());
|
||||
Matrix4f localTransforms = transforms.last()
|
||||
.pose();
|
||||
modelMat.mul(localTransforms);
|
||||
|
||||
Matrix3f normalMat;
|
||||
if (fullNormalTransform) {
|
||||
normalMat = new Matrix3f(input.last()
|
||||
.normal());
|
||||
Matrix3f localNormalTransforms = transforms.last()
|
||||
.normal();
|
||||
normalMat.mul(localNormalTransforms);
|
||||
} else {
|
||||
normalMat = new Matrix3f(transforms.last()
|
||||
.normal());
|
||||
}
|
||||
|
||||
if (useWorldLight) {
|
||||
WORLD_LIGHT_CACHE.clear();
|
||||
}
|
||||
|
||||
final Vector4f pos = new Vector4f();
|
||||
final Vector3f normal = new Vector3f();
|
||||
final Vector4f lightPos = new Vector4f();
|
||||
|
||||
DiffuseLightCalculator diffuseCalculator = ForcedDiffuseState.getForcedCalculator();
|
||||
final boolean disableDiffuseMult =
|
||||
this.disableDiffuseMult || (ShadersModHandler.isShaderPackInUse() && diffuseCalculator == null);
|
||||
if (diffuseCalculator == null) {
|
||||
diffuseCalculator = this.diffuseCalculator;
|
||||
if (diffuseCalculator == null) {
|
||||
diffuseCalculator = DiffuseLightCalculator.forCurrentLevel();
|
||||
}
|
||||
}
|
||||
|
||||
final int vertexCount = template.getVertexCount();
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float x = template.getX(i);
|
||||
float y = template.getY(i);
|
||||
float z = template.getZ(i);
|
||||
|
||||
pos.set(x, y, z, 1F);
|
||||
pos.mul(modelMat);
|
||||
builder.vertex(pos.x(), pos.y(), pos.z());
|
||||
|
||||
float normalX = template.getNX(i);
|
||||
float normalY = template.getNY(i);
|
||||
float normalZ = template.getNZ(i);
|
||||
|
||||
normal.set(normalX, normalY, normalZ);
|
||||
normal.mul(normalMat);
|
||||
float nx = normal.x();
|
||||
float ny = normal.y();
|
||||
float nz = normal.z();
|
||||
|
||||
byte r, g, b, a;
|
||||
if (shouldColor) {
|
||||
r = (byte) this.r;
|
||||
g = (byte) this.g;
|
||||
b = (byte) this.b;
|
||||
a = (byte) this.a;
|
||||
} else {
|
||||
r = template.getR(i);
|
||||
g = template.getG(i);
|
||||
b = template.getB(i);
|
||||
a = template.getA(i);
|
||||
}
|
||||
if (disableDiffuseMult) {
|
||||
builder.color(r, g, b, a);
|
||||
} else {
|
||||
float instanceDiffuse = diffuseCalculator.getDiffuse(nx, ny, nz, shadedPredicate.test(i));
|
||||
int colorR = transformColor(r, instanceDiffuse);
|
||||
int colorG = transformColor(g, instanceDiffuse);
|
||||
int colorB = transformColor(b, instanceDiffuse);
|
||||
builder.color(colorR, colorG, colorB, a);
|
||||
}
|
||||
|
||||
float u = template.getU(i);
|
||||
float v = template.getV(i);
|
||||
if (spriteShiftFunc != null) {
|
||||
spriteShiftFunc.shift(builder, u, v);
|
||||
} else {
|
||||
builder.uv(u, v);
|
||||
}
|
||||
|
||||
if (hasOverlay) {
|
||||
builder.overlayCoords(overlay);
|
||||
}
|
||||
|
||||
int light;
|
||||
if (useWorldLight) {
|
||||
lightPos.set(((x - .5f) * 15 / 16f) + .5f, (y - .5f) * 15 / 16f + .5f, (z - .5f) * 15 / 16f + .5f, 1f);
|
||||
lightPos.mul(localTransforms);
|
||||
if (lightTransform != null) {
|
||||
lightPos.mul(lightTransform);
|
||||
}
|
||||
|
||||
light = getLight(Minecraft.getInstance().level, lightPos);
|
||||
if (hasCustomLight) {
|
||||
light = maxLight(light, packedLightCoords);
|
||||
}
|
||||
} else if (hasCustomLight) {
|
||||
light = packedLightCoords;
|
||||
} else {
|
||||
light = template.getLight(i);
|
||||
}
|
||||
|
||||
if (hybridLight) {
|
||||
builder.uv2(maxLight(light, template.getLight(i)));
|
||||
} else {
|
||||
builder.uv2(light);
|
||||
}
|
||||
|
||||
builder.normal(nx, ny, nz);
|
||||
|
||||
builder.endVertex();
|
||||
}
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public SuperByteBuffer reset() {
|
||||
while (!transforms.clear())
|
||||
transforms.popPose();
|
||||
transforms.pushPose();
|
||||
|
||||
shouldColor = false;
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
a = 0;
|
||||
disableDiffuseMult = false;
|
||||
diffuseCalculator = null;
|
||||
spriteShiftFunc = null;
|
||||
hasOverlay = false;
|
||||
overlay = OverlayTexture.NO_OVERLAY;
|
||||
useWorldLight = false;
|
||||
lightTransform = null;
|
||||
hasCustomLight = false;
|
||||
packedLightCoords = 0;
|
||||
hybridLight = false;
|
||||
fullNormalTransform = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return template.isEmpty();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
template.delete();
|
||||
}
|
||||
|
||||
public PoseStack getTransforms() {
|
||||
return transforms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperByteBuffer translate(double x, double y, double z) {
|
||||
transforms.translate(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperByteBuffer multiply(Quaternionf quaternion) {
|
||||
transforms.mulPose(quaternion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperByteBuffer scale(float factorX, float factorY, float factorZ) {
|
||||
transforms.scale(factorX, factorY, factorZ);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperByteBuffer pushPose() {
|
||||
transforms.pushPose();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperByteBuffer popPose() {
|
||||
transforms.popPose();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperByteBuffer mulPose(Matrix4f pose) {
|
||||
transforms.last()
|
||||
.pose()
|
||||
.mul(pose);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperByteBuffer mulNormal(Matrix3f normal) {
|
||||
transforms.last()
|
||||
.normal()
|
||||
.mul(normal);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer transform(PoseStack stack) {
|
||||
transforms.last()
|
||||
.pose()
|
||||
.mul(stack.last()
|
||||
.pose());
|
||||
transforms.last()
|
||||
.normal()
|
||||
.mul(stack.last()
|
||||
.normal());
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer rotateCentered(Direction axis, float radians) {
|
||||
translate(.5f, .5f, .5f).rotate(axis, radians)
|
||||
.translate(-.5f, -.5f, -.5f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer rotateCentered(Quaternionf q) {
|
||||
translate(.5f, .5f, .5f).multiply(q)
|
||||
.translate(-.5f, -.5f, -.5f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer color(int r, int g, int b, int a) {
|
||||
shouldColor = true;
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer color(int color) {
|
||||
shouldColor = true;
|
||||
r = ((color >> 16) & 0xFF);
|
||||
g = ((color >> 8) & 0xFF);
|
||||
b = (color & 0xFF);
|
||||
a = 255;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer color(Color c) {
|
||||
return color(c.getRGB());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents vertex colors from being multiplied by the diffuse value calculated
|
||||
* from the final transformed normal vector. Useful for entity rendering, when
|
||||
* diffuse is applied automatically later.
|
||||
*/
|
||||
public SuperByteBuffer disableDiffuse() {
|
||||
disableDiffuseMult = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer diffuseCalculator(DiffuseLightCalculator diffuseCalculator) {
|
||||
this.diffuseCalculator = diffuseCalculator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer shiftUV(SpriteShiftEntry entry) {
|
||||
this.spriteShiftFunc = (builder, u, v) -> {
|
||||
builder.uv(entry.getTargetU(u), entry.getTargetV(v));
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollV) {
|
||||
return this.shiftUVScrolling(entry, 0, scrollV);
|
||||
}
|
||||
|
||||
public SuperByteBuffer shiftUVScrolling(SpriteShiftEntry entry, float scrollU, float scrollV) {
|
||||
this.spriteShiftFunc = (builder, u, v) -> {
|
||||
float targetU = u - entry.getOriginal()
|
||||
.getU0() + entry.getTarget()
|
||||
.getU0()
|
||||
+ scrollU;
|
||||
float targetV = v - entry.getOriginal()
|
||||
.getV0() + entry.getTarget()
|
||||
.getV0()
|
||||
+ scrollV;
|
||||
builder.uv(targetU, targetV);
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer shiftUVtoSheet(SpriteShiftEntry entry, float uTarget, float vTarget, int sheetSize) {
|
||||
this.spriteShiftFunc = (builder, u, v) -> {
|
||||
float targetU = entry.getTarget()
|
||||
.getU((SpriteShiftEntry.getUnInterpolatedU(entry.getOriginal(), u) / sheetSize) + uTarget * 16);
|
||||
float targetV = entry.getTarget()
|
||||
.getV((SpriteShiftEntry.getUnInterpolatedV(entry.getOriginal(), v) / sheetSize) + vTarget * 16);
|
||||
builder.uv(targetU, targetV);
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer overlay() {
|
||||
hasOverlay = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer overlay(int overlay) {
|
||||
hasOverlay = true;
|
||||
this.overlay = overlay;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer light() {
|
||||
useWorldLight = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer light(Matrix4f lightTransform) {
|
||||
useWorldLight = true;
|
||||
this.lightTransform = lightTransform;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer light(int packedLightCoords) {
|
||||
hasCustomLight = true;
|
||||
this.packedLightCoords = packedLightCoords;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer light(Matrix4f lightTransform, int packedLightCoords) {
|
||||
light(lightTransform);
|
||||
light(packedLightCoords);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses max light from calculated light (world light or custom light) and vertex
|
||||
* light for the final light value. Ineffective if any other light method was
|
||||
* not called.
|
||||
*/
|
||||
public SuperByteBuffer hybridLight() {
|
||||
hybridLight = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms normals not only by the local matrix stack, but also by the passed
|
||||
* matrix stack.
|
||||
*/
|
||||
public SuperByteBuffer fullNormalTransform() {
|
||||
fullNormalTransform = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SuperByteBuffer forEntityRender() {
|
||||
disableDiffuse();
|
||||
overlay();
|
||||
fullNormalTransform();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static int transformColor(byte component, float scale) {
|
||||
return Mth.clamp((int) (Byte.toUnsignedInt(component) * scale), 0, 255);
|
||||
}
|
||||
|
||||
public static int transformColor(int component, float scale) {
|
||||
return Mth.clamp((int) (component * scale), 0, 255);
|
||||
}
|
||||
|
||||
public static int maxLight(int packedLight1, int packedLight2) {
|
||||
int blockLight1 = LightTexture.block(packedLight1);
|
||||
int skyLight1 = LightTexture.sky(packedLight1);
|
||||
int blockLight2 = LightTexture.block(packedLight2);
|
||||
int skyLight2 = LightTexture.sky(packedLight2);
|
||||
return LightTexture.pack(Math.max(blockLight1, blockLight2), Math.max(skyLight1, skyLight2));
|
||||
}
|
||||
|
||||
private static int getLight(Level world, Vector4f lightPos) {
|
||||
BlockPos pos = BlockPos.containing(lightPos.x(), lightPos.y(), lightPos.z());
|
||||
return WORLD_LIGHT_CACHE.computeIfAbsent(pos.asLong(), $ -> LevelRenderer.getLightColor(world, pos));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SpriteShiftFunc {
|
||||
void shift(VertexConsumer builder, float u, float v);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface VertexLighter {
|
||||
int getPackedLight(float x, float y, float z);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
public class SuperByteBufferCache {
|
||||
|
||||
protected final Map<Compartment<?>, Cache<Object, SuperByteBuffer>> caches = new HashMap<>();
|
||||
|
||||
public synchronized void registerCompartment(Compartment<?> compartment) {
|
||||
caches.put(compartment, CacheBuilder.newBuilder()
|
||||
.<Object, SuperByteBuffer>removalListener(n -> n.getValue().delete())
|
||||
.build());
|
||||
}
|
||||
|
||||
public synchronized void registerCompartment(Compartment<?> compartment, long ticksUntilExpired) {
|
||||
caches.put(compartment, CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(ticksUntilExpired * 50, TimeUnit.MILLISECONDS)
|
||||
.<Object, SuperByteBuffer>removalListener(n -> n.getValue().delete())
|
||||
.build());
|
||||
}
|
||||
|
||||
public <T> SuperByteBuffer get(Compartment<T> compartment, T key, Callable<SuperByteBuffer> callable) {
|
||||
Cache<Object, SuperByteBuffer> cache = caches.get(compartment);
|
||||
if (cache != null) {
|
||||
try {
|
||||
return cache.get(key, callable);
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> void invalidate(Compartment<T> compartment, T key) {
|
||||
caches.get(compartment).invalidate(key);
|
||||
}
|
||||
|
||||
public <T> void invalidate(Compartment<?> compartment) {
|
||||
caches.get(compartment).invalidateAll();
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
caches.forEach((compartment, cache) -> cache.invalidateAll());
|
||||
}
|
||||
|
||||
public static class Compartment<T> {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import java.util.SortedMap;
|
||||
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.renderer.SectionBufferBuilderPack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
|
||||
public class SuperRenderTypeBuffer implements MultiBufferSource {
|
||||
|
||||
private static final SuperRenderTypeBuffer INSTANCE = new SuperRenderTypeBuffer();
|
||||
|
||||
public static SuperRenderTypeBuffer getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private SuperRenderTypeBufferPhase earlyBuffer;
|
||||
private SuperRenderTypeBufferPhase defaultBuffer;
|
||||
private SuperRenderTypeBufferPhase lateBuffer;
|
||||
|
||||
public SuperRenderTypeBuffer() {
|
||||
earlyBuffer = new SuperRenderTypeBufferPhase();
|
||||
defaultBuffer = new SuperRenderTypeBufferPhase();
|
||||
lateBuffer = new SuperRenderTypeBufferPhase();
|
||||
}
|
||||
|
||||
public VertexConsumer getEarlyBuffer(RenderType type) {
|
||||
return earlyBuffer.bufferSource.getBuffer(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer getBuffer(RenderType type) {
|
||||
return defaultBuffer.bufferSource.getBuffer(type);
|
||||
}
|
||||
|
||||
public VertexConsumer getLateBuffer(RenderType type) {
|
||||
return lateBuffer.bufferSource.getBuffer(type);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
earlyBuffer.bufferSource.endBatch();
|
||||
defaultBuffer.bufferSource.endBatch();
|
||||
lateBuffer.bufferSource.endBatch();
|
||||
}
|
||||
|
||||
public void draw(RenderType type) {
|
||||
earlyBuffer.bufferSource.endBatch(type);
|
||||
defaultBuffer.bufferSource.endBatch(type);
|
||||
lateBuffer.bufferSource.endBatch(type);
|
||||
}
|
||||
|
||||
private static class SuperRenderTypeBufferPhase {
|
||||
|
||||
// Visible clones from RenderBuffers
|
||||
private final SectionBufferBuilderPack fixedBufferPack = new SectionBufferBuilderPack();
|
||||
private final SortedMap<RenderType, BufferBuilder> fixedBuffers = Util.make(new Object2ObjectLinkedOpenHashMap<>(), map -> {
|
||||
map.put(Sheets.solidBlockSheet(), this.fixedBufferPack.builder(RenderType.solid()));
|
||||
map.put(Sheets.cutoutBlockSheet(), this.fixedBufferPack.builder(RenderType.cutout()));
|
||||
map.put(Sheets.bannerSheet(), this.fixedBufferPack.builder(RenderType.cutoutMipped()));
|
||||
map.put(Sheets.translucentCullBlockSheet(), this.fixedBufferPack.builder(RenderType.translucent()));
|
||||
put(map, Sheets.shieldSheet());
|
||||
put(map, Sheets.bedSheet());
|
||||
put(map, Sheets.shulkerBoxSheet());
|
||||
put(map, Sheets.signSheet());
|
||||
put(map, Sheets.hangingSignSheet());
|
||||
map.put(Sheets.chestSheet(), new BufferBuilder(786432));
|
||||
put(map, RenderType.armorGlint());
|
||||
put(map, RenderType.armorEntityGlint());
|
||||
put(map, RenderType.glint());
|
||||
put(map, RenderType.glintDirect());
|
||||
put(map, RenderType.glintTranslucent());
|
||||
put(map, RenderType.entityGlint());
|
||||
put(map, RenderType.entityGlintDirect());
|
||||
put(map, RenderType.waterMask());
|
||||
ModelBakery.DESTROY_TYPES.forEach(p_173062_ -> put(map, p_173062_));
|
||||
});
|
||||
private final BufferSource bufferSource = MultiBufferSource.immediateWithBuffers(fixedBuffers, new BufferBuilder(256));
|
||||
|
||||
private static void put(Object2ObjectLinkedOpenHashMap<RenderType, BufferBuilder> map, RenderType type) {
|
||||
map.put(type, new BufferBuilder(type.bufferSize()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.render;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
||||
import com.jozufozu.flywheel.config.BackendType;
|
||||
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.AnimationTickHolder;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.RegisteredObjects;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class TileEntityRenderHelper {
|
||||
|
||||
public static void renderTileEntities(Level world, Iterable<BlockEntity> customRenderTEs, PoseStack ms,
|
||||
MultiBufferSource buffer) {
|
||||
renderTileEntities(world, null, customRenderTEs, ms, null, buffer);
|
||||
}
|
||||
|
||||
public static void renderTileEntities(Level world, Iterable<BlockEntity> customRenderTEs, PoseStack ms,
|
||||
MultiBufferSource buffer, float pt) {
|
||||
renderTileEntities(world, null, customRenderTEs, ms, null, buffer, pt);
|
||||
}
|
||||
|
||||
public static void renderTileEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
||||
Iterable<BlockEntity> customRenderTEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer) {
|
||||
renderTileEntities(world, renderWorld, customRenderTEs, ms, lightTransform, buffer,
|
||||
AnimationTickHolder.getPartialTicks());
|
||||
}
|
||||
|
||||
public static void renderTileEntities(Level world, @Nullable VirtualRenderWorld renderWorld,
|
||||
Iterable<BlockEntity> customRenderTEs, PoseStack ms, @Nullable Matrix4f lightTransform, MultiBufferSource buffer,
|
||||
float pt) {
|
||||
Iterator<BlockEntity> iterator = customRenderTEs.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
BlockEntity tileEntity = iterator.next();
|
||||
if (Backend.getBackendType() == BackendType.INSTANCING && Backend.isFlywheelWorld(renderWorld) && InstancedRenderRegistry.shouldSkipRender(tileEntity))
|
||||
continue;
|
||||
|
||||
BlockEntityRenderer<BlockEntity> renderer = Minecraft.getInstance().getBlockEntityRenderDispatcher().getRenderer(tileEntity);
|
||||
if (renderer == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos pos = tileEntity.getBlockPos();
|
||||
ms.pushPose();
|
||||
TransformStack.cast(ms)
|
||||
.translate(pos);
|
||||
|
||||
try {
|
||||
int worldLight = getCombinedLight(world, getLightPos(lightTransform, pos), renderWorld, pos);
|
||||
|
||||
if (renderWorld != null) {
|
||||
// Swap the real world for the render world so that the renderer gets contraption-local information
|
||||
tileEntity.setLevel(renderWorld);
|
||||
renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
||||
tileEntity.setLevel(world);
|
||||
} else {
|
||||
renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
iterator.remove();
|
||||
|
||||
String message = "BlockEntity " + RegisteredObjects.getKeyOrThrow(tileEntity.getType())
|
||||
.toString() + " could not be rendered virtually.";
|
||||
// if (AllConfigs.CLIENT.explainRenderErrors.get())
|
||||
Create.LOGGER.error(message, e);
|
||||
// else
|
||||
// Create.LOGGER.error(message);
|
||||
}
|
||||
|
||||
ms.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockPos getLightPos(@Nullable Matrix4f lightTransform, BlockPos contraptionPos) {
|
||||
if (lightTransform != null) {
|
||||
Vector4f lightVec = new Vector4f(contraptionPos.getX() + .5f, contraptionPos.getY() + .5f, contraptionPos.getZ() + .5f, 1);
|
||||
lightVec.mul(lightTransform);
|
||||
return BlockPos.containing(lightVec.x(), lightVec.y(), lightVec.z());
|
||||
} else {
|
||||
return contraptionPos;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getCombinedLight(Level world, BlockPos worldPos, @Nullable VirtualRenderWorld renderWorld,
|
||||
BlockPos renderWorldPos) {
|
||||
int worldLight = LevelRenderer.getLightColor(world, worldPos);
|
||||
|
||||
if (renderWorld != null) {
|
||||
int renderWorldLight = LevelRenderer.getLightColor(renderWorld, renderWorldPos);
|
||||
return SuperByteBuffer.maxLight(worldLight, renderWorldLight);
|
||||
}
|
||||
|
||||
return worldLight;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Direction.Axis;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class AngleHelper {
|
||||
|
||||
public static float horizontalAngle(Direction facing) {
|
||||
if (facing.getAxis().isVertical())
|
||||
return 0;
|
||||
float angle = facing.toYRot();
|
||||
if (facing.getAxis() == Axis.X)
|
||||
angle = -angle;
|
||||
return angle;
|
||||
}
|
||||
|
||||
public static float verticalAngle(Direction facing) {
|
||||
return facing == Direction.UP ? -90 : facing == Direction.DOWN ? 90 : 0;
|
||||
}
|
||||
|
||||
public static float rad(double angle) {
|
||||
if (angle == 0)
|
||||
return 0;
|
||||
return (float) (angle / 180 * Math.PI);
|
||||
}
|
||||
|
||||
public static float deg(double angle) {
|
||||
if (angle == 0)
|
||||
return 0;
|
||||
return (float) (angle * 180 / Math.PI);
|
||||
}
|
||||
|
||||
public static float angleLerp(double pct, double current, double target) {
|
||||
return (float) (current + getShortestAngleDiff(current, target) * pct);
|
||||
}
|
||||
|
||||
public static float getShortestAngleDiff(double current, double target) {
|
||||
current = current % 360;
|
||||
target = target % 360;
|
||||
return (float) (((((target - current) % 360) + 540) % 360) - 180);
|
||||
}
|
||||
|
||||
public static float getShortestAngleDiff(double current, double target, float hint) {
|
||||
float diff = getShortestAngleDiff(current, target);
|
||||
if (Mth.equal(Math.abs(diff), 180) && Math.signum(diff) != Math.signum(hint)) {
|
||||
return diff + 360*Math.signum(hint);
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.worldWrappers.WrappedClientWorld;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
|
||||
public class AnimationTickHolder {
|
||||
|
||||
private static int ticks;
|
||||
private static int pausedTicks;
|
||||
|
||||
public static void reset() {
|
||||
ticks = 0;
|
||||
pausedTicks = 0;
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
if (!Minecraft.getInstance()
|
||||
.isPaused()) {
|
||||
ticks = (ticks + 1) % 1_728_000; // wrap around every 24 hours so we maintain enough floating point precision
|
||||
} else {
|
||||
pausedTicks = (pausedTicks + 1) % 1_728_000;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getTicks() {
|
||||
return getTicks(false);
|
||||
}
|
||||
|
||||
public static int getTicks(boolean includePaused) {
|
||||
return includePaused ? ticks + pausedTicks : ticks;
|
||||
}
|
||||
|
||||
public static float getRenderTime() {
|
||||
return getTicks() + getPartialTicks();
|
||||
}
|
||||
|
||||
public static float getPartialTicks() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
return (mc.isPaused() ? mc.pausePartialTick : mc.getFrameTime());
|
||||
}
|
||||
|
||||
public static int getTicks(LevelAccessor world) {
|
||||
if (world instanceof WrappedClientWorld)
|
||||
return getTicks(((WrappedClientWorld) world).getWrappedWorld());
|
||||
return getTicks();
|
||||
}
|
||||
|
||||
public static float getRenderTime(LevelAccessor world) {
|
||||
return getTicks(world) + getPartialTicks(world);
|
||||
}
|
||||
|
||||
public static float getPartialTicks(LevelAccessor world) {
|
||||
return getPartialTicks();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
|
||||
public class BBHelper {
|
||||
|
||||
public static BoundingBox encapsulate(BoundingBox bb, BlockPos pos) {
|
||||
return new BoundingBox(Math.min(bb.minX(), pos.getX()), Math.min(bb.minY(), pos.getY()),
|
||||
Math.min(bb.minZ(), pos.getZ()), Math.max(bb.maxX(), pos.getX()), Math.max(bb.maxY(), pos.getY()),
|
||||
Math.max(bb.maxZ(), pos.getZ()));
|
||||
}
|
||||
|
||||
public static BoundingBox encapsulate(BoundingBox bb, BoundingBox bb2) {
|
||||
return new BoundingBox(Math.min(bb.minX(), bb2.minX()), Math.min(bb.minY(), bb2.minY()),
|
||||
Math.min(bb.minZ(), bb2.minZ()), Math.max(bb.maxX(), bb2.maxX()), Math.max(bb.maxY(), bb2.maxY()),
|
||||
Math.max(bb.maxZ(), bb2.maxZ()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
|
||||
public class BlockFace extends Pair<BlockPos, Direction> {
|
||||
|
||||
public BlockFace(BlockPos first, Direction second) {
|
||||
super(first, second);
|
||||
}
|
||||
|
||||
public boolean isEquivalent(BlockFace other) {
|
||||
if (equals(other))
|
||||
return true;
|
||||
return getConnectedPos().equals(other.getPos()) && getPos().equals(other.getConnectedPos());
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return getFirst();
|
||||
}
|
||||
|
||||
public Direction getFace() {
|
||||
return getSecond();
|
||||
}
|
||||
|
||||
public Direction getOppositeFace() {
|
||||
return getSecond().getOpposite();
|
||||
}
|
||||
|
||||
public BlockFace getOpposite() {
|
||||
return new BlockFace(getConnectedPos(), getOppositeFace());
|
||||
}
|
||||
|
||||
public BlockPos getConnectedPos() {
|
||||
return getPos().relative(getFace());
|
||||
}
|
||||
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag compoundNBT = new CompoundTag();
|
||||
compoundNBT.put("Pos", NbtUtils.writeBlockPos(getPos()));
|
||||
NBTHelper.writeEnum(compoundNBT, "Face", getFace());
|
||||
return compoundNBT;
|
||||
}
|
||||
|
||||
public static BlockFace fromNBT(CompoundTag compound) {
|
||||
return new BlockFace(NbtUtils.readBlockPos(compound.getCompound("Pos")),
|
||||
NBTHelper.readEnum(compound, "Face", Direction.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.createmod.catnip.nbt.NBTProcessors;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
@@ -16,6 +19,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
@@ -29,19 +33,41 @@ import net.minecraft.world.level.block.SlimeBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.block.state.properties.SlabType;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.neoforged.neoforge.common.IPlantable;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.common.SpecialPlantable;
|
||||
import net.neoforged.neoforge.event.level.BlockDropsEvent;
|
||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BlockHelper {
|
||||
private static final List<IntegerProperty> COUNT_STATES = List.of(
|
||||
BlockStateProperties.EGGS,
|
||||
BlockStateProperties.PICKLES,
|
||||
BlockStateProperties.CANDLES
|
||||
);
|
||||
|
||||
private static final List<Block> VINELIKE_BLOCKS = List.of(
|
||||
Blocks.VINE, Blocks.GLOW_LICHEN
|
||||
);
|
||||
|
||||
private static final List<BooleanProperty> VINELIKE_STATES = List.of(
|
||||
BlockStateProperties.UP,
|
||||
BlockStateProperties.NORTH,
|
||||
BlockStateProperties.EAST,
|
||||
BlockStateProperties.SOUTH,
|
||||
BlockStateProperties.WEST,
|
||||
BlockStateProperties.DOWN
|
||||
);
|
||||
|
||||
public static BlockState setZeroAge(BlockState blockState) {
|
||||
if (blockState.hasProperty(BlockStateProperties.AGE_1))
|
||||
@@ -78,44 +104,54 @@ public class BlockHelper {
|
||||
Item required = getRequiredItem(block).getItem();
|
||||
|
||||
boolean needsTwo = block.hasProperty(BlockStateProperties.SLAB_TYPE)
|
||||
&& block.getValue(BlockStateProperties.SLAB_TYPE) == SlabType.DOUBLE;
|
||||
&& block.getValue(BlockStateProperties.SLAB_TYPE) == SlabType.DOUBLE;
|
||||
|
||||
if (needsTwo)
|
||||
amount *= 2;
|
||||
|
||||
if (block.hasProperty(BlockStateProperties.EGGS))
|
||||
amount *= block.getValue(BlockStateProperties.EGGS);
|
||||
for (IntegerProperty property : COUNT_STATES)
|
||||
if (block.hasProperty(property))
|
||||
amount *= block.getValue(property);
|
||||
|
||||
if (block.hasProperty(BlockStateProperties.PICKLES))
|
||||
amount *= block.getValue(BlockStateProperties.PICKLES);
|
||||
if (VINELIKE_BLOCKS.contains(block.getBlock())) {
|
||||
int vineCount = 0;
|
||||
|
||||
for (BooleanProperty vineState : VINELIKE_STATES) {
|
||||
if (block.hasProperty(vineState) && block.getValue(vineState)) {
|
||||
vineCount++;
|
||||
}
|
||||
}
|
||||
|
||||
amount += vineCount - 1;
|
||||
}
|
||||
|
||||
{
|
||||
// Try held Item first
|
||||
int preferredSlot = player.getInventory().selected;
|
||||
ItemStack itemstack = player.getInventory()
|
||||
.getItem(preferredSlot);
|
||||
.getItem(preferredSlot);
|
||||
int count = itemstack.getCount();
|
||||
if (itemstack.getItem() == required && count > 0) {
|
||||
int taken = Math.min(count, amount - amountFound);
|
||||
player.getInventory()
|
||||
.setItem(preferredSlot, new ItemStack(itemstack.getItem(), count - taken));
|
||||
.setItem(preferredSlot, new ItemStack(itemstack.getItem(), count - taken));
|
||||
amountFound += taken;
|
||||
}
|
||||
}
|
||||
|
||||
// Search inventory
|
||||
for (int i = 0; i < player.getInventory()
|
||||
.getContainerSize(); ++i) {
|
||||
.getContainerSize(); ++i) {
|
||||
if (amountFound == amount)
|
||||
break;
|
||||
|
||||
ItemStack itemstack = player.getInventory()
|
||||
.getItem(i);
|
||||
.getItem(i);
|
||||
int count = itemstack.getCount();
|
||||
if (itemstack.getItem() == required && count > 0) {
|
||||
int taken = Math.min(count, amount - amountFound);
|
||||
player.getInventory()
|
||||
.setItem(i, new ItemStack(itemstack.getItem(), count - taken));
|
||||
.setItem(i, new ItemStack(itemstack.getItem(), count - taken));
|
||||
amountFound += taken;
|
||||
}
|
||||
}
|
||||
@@ -124,7 +160,7 @@ public class BlockHelper {
|
||||
// Give back 1 if uneven amount was removed
|
||||
if (amountFound % 2 != 0)
|
||||
player.getInventory()
|
||||
.add(new ItemStack(required));
|
||||
.add(new ItemStack(required));
|
||||
amountFound /= 2;
|
||||
}
|
||||
|
||||
@@ -144,18 +180,18 @@ public class BlockHelper {
|
||||
}
|
||||
|
||||
public static void destroyBlock(Level world, BlockPos pos, float effectChance,
|
||||
Consumer<ItemStack> droppedItemCallback) {
|
||||
Consumer<ItemStack> droppedItemCallback) {
|
||||
destroyBlockAs(world, pos, null, ItemStack.EMPTY, effectChance, droppedItemCallback);
|
||||
}
|
||||
|
||||
public static boolean destroyBlockAs(Level world, BlockPos pos, @Nullable Player player, ItemStack usedTool,
|
||||
float effectChance, Consumer<ItemStack> droppedItemCallback) {
|
||||
float effectChance, Consumer<ItemStack> droppedItemCallback) {
|
||||
FluidState fluidState = world.getFluidState(pos);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
|
||||
if (world.random.nextFloat() < effectChance)
|
||||
world.levelEvent(2001, pos, Block.getId(state));
|
||||
BlockEntity tileentity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
|
||||
BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
|
||||
|
||||
if (player != null) {
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player);
|
||||
@@ -163,31 +199,37 @@ public class BlockHelper {
|
||||
if (event.isCanceled())
|
||||
return false;
|
||||
|
||||
if (event.getExpToDrop() > 0 && world instanceof ServerLevel)
|
||||
state.getBlock()
|
||||
.popExperience((ServerLevel) world, pos, event.getExpToDrop());
|
||||
|
||||
usedTool.mineBlock(world, state, pos, player);
|
||||
player.awardStat(Stats.BLOCK_MINED.get(state.getBlock()));
|
||||
}
|
||||
|
||||
if (world instanceof ServerLevel && world.getGameRules()
|
||||
.getBoolean(GameRules.RULE_DOBLOCKDROPS) && !world.restoringBlockSnapshots
|
||||
&& (player == null || !player.isCreative())) {
|
||||
for (ItemStack itemStack : Block.getDrops(state, (ServerLevel) world, pos, tileentity, player, usedTool))
|
||||
if (world instanceof ServerLevel serverLevel && world.getGameRules()
|
||||
.getBoolean(GameRules.RULE_DOBLOCKDROPS) && !world.restoringBlockSnapshots
|
||||
&& (player == null || !player.isCreative())) {
|
||||
List<ItemStack> drops = Block.getDrops(state, serverLevel, pos, blockEntity, player, usedTool);
|
||||
if (player != null) {
|
||||
BlockDropsEvent event = new BlockDropsEvent(serverLevel, pos, state, blockEntity, List.of(), player, usedTool);
|
||||
NeoForge.EVENT_BUS.post(event);
|
||||
if (!event.isCanceled()) {
|
||||
if ( event.getDroppedExperience() > 0)
|
||||
state.getBlock().popExperience(serverLevel, pos, event.getDroppedExperience());
|
||||
}
|
||||
}
|
||||
for (ItemStack itemStack : drops)
|
||||
droppedItemCallback.accept(itemStack);
|
||||
|
||||
// Simulating IceBlock#playerDestroy. Not calling method directly as it would drop item
|
||||
// entities as a side-effect
|
||||
if (state.getBlock() instanceof IceBlock && usedTool.getEnchantmentLevel(Enchantments.SILK_TOUCH) == 0) {
|
||||
Registry<Enchantment> enchantmentRegistry = world.registryAccess().registryOrThrow(Registries.ENCHANTMENT);
|
||||
if (state.getBlock() instanceof IceBlock && usedTool.getEnchantmentLevel(enchantmentRegistry.getHolderOrThrow(Enchantments.SILK_TOUCH)) == 0) {
|
||||
if (world.dimensionType()
|
||||
.ultraWarm())
|
||||
.ultraWarm())
|
||||
return false;
|
||||
|
||||
BlockState belowState = world.getBlockState(pos.below());
|
||||
if (belowState.blocksMotion() || belowState.liquid())
|
||||
BlockState blockstate = world.getBlockState(pos.below());
|
||||
if (blockstate.blocksMotion() || blockstate.liquid())
|
||||
world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState());
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY, true);
|
||||
@@ -199,13 +241,13 @@ public class BlockHelper {
|
||||
|
||||
public static boolean isSolidWall(BlockGetter reader, BlockPos fromPos, Direction toDirection) {
|
||||
return hasBlockSolidSide(reader.getBlockState(fromPos.relative(toDirection)), reader,
|
||||
fromPos.relative(toDirection), toDirection.getOpposite());
|
||||
fromPos.relative(toDirection), toDirection.getOpposite());
|
||||
}
|
||||
|
||||
public static boolean noCollisionInSpace(BlockGetter reader, BlockPos pos) {
|
||||
return reader.getBlockState(pos)
|
||||
.getCollisionShape(reader, pos)
|
||||
.isEmpty();
|
||||
.getCollisionShape(reader, pos)
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
private static void placeRailWithoutUpdate(Level world, BlockState state, BlockPos target) {
|
||||
@@ -218,18 +260,33 @@ public class BlockHelper {
|
||||
chunk.getSections()[idx] = chunksection;
|
||||
}
|
||||
BlockState old = chunksection.setBlockState(SectionPos.sectionRelative(target.getX()),
|
||||
SectionPos.sectionRelative(target.getY()), SectionPos.sectionRelative(target.getZ()), state);
|
||||
SectionPos.sectionRelative(target.getY()), SectionPos.sectionRelative(target.getZ()), state);
|
||||
chunk.setUnsaved(true);
|
||||
world.markAndNotifyBlock(target, chunk, old, state, 82, 512);
|
||||
|
||||
world.setBlock(target, state, 82);
|
||||
world.neighborChanged(target, world.getBlockState(target.below())
|
||||
.getBlock(), target.below());
|
||||
.getBlock(), target.below());
|
||||
}
|
||||
|
||||
public static boolean placeSchematicBlock(Level world, Player player, BlockState state, BlockPos target, ItemStack stack,
|
||||
@Nullable CompoundTag data) {
|
||||
BlockEntity existingTile = world.getBlockEntity(target);
|
||||
public static CompoundTag prepareBlockEntityData(BlockState blockState, BlockEntity blockEntity) {
|
||||
CompoundTag data = null;
|
||||
if (blockEntity == null)
|
||||
return null;
|
||||
RegistryAccess access = blockEntity.getLevel().registryAccess();
|
||||
if (blockEntity instanceof IPartialSafeNBT safeNbtBE) {
|
||||
data = new CompoundTag();
|
||||
safeNbtBE.writeSafe(data, access);
|
||||
data = NBTProcessors.process(blockState, blockEntity, data, true);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void placeSchematicBlock(Level world, BlockState state, BlockPos target, ItemStack stack,
|
||||
@Nullable CompoundTag data) {
|
||||
BlockEntity existingBlockEntity = world.getBlockEntity(target);
|
||||
boolean alreadyPlaced = false;
|
||||
|
||||
// Piston
|
||||
if (state.hasProperty(BlockStateProperties.EXTENDED))
|
||||
@@ -239,58 +296,69 @@ public class BlockHelper {
|
||||
|
||||
if (state.getBlock() == Blocks.COMPOSTER)
|
||||
state = Blocks.COMPOSTER.defaultBlockState();
|
||||
else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof IPlantable)
|
||||
state = ((IPlantable) state.getBlock()).getPlant(world, target);
|
||||
else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof SpecialPlantable specialPlantable) {
|
||||
alreadyPlaced = true;
|
||||
if (specialPlantable.canPlacePlantAtPosition(stack, world, target, null))
|
||||
specialPlantable.spawnPlantAtPosition(stack, world, target, null);
|
||||
}
|
||||
else if (state.is(BlockTags.CAULDRONS))
|
||||
state = Blocks.CAULDRON.defaultBlockState();
|
||||
|
||||
if (world.dimensionType()
|
||||
.ultraWarm() && state.getFluidState().is(FluidTags.WATER)) {
|
||||
.ultraWarm() && state.getFluidState().is(FluidTags.WATER)) {
|
||||
int i = target.getX();
|
||||
int j = target.getY();
|
||||
int k = target.getZ();
|
||||
world.playSound(null, target, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F,
|
||||
2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
|
||||
2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
|
||||
|
||||
for (int l = 0; l < 8; ++l) {
|
||||
world.addParticle(ParticleTypes.LARGE_SMOKE, i + Math.random(), j + Math.random(), k + Math.random(),
|
||||
0.0D, 0.0D, 0.0D);
|
||||
0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
Block.dropResources(state, world, target);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.getBlock() instanceof BaseRailBlock) {
|
||||
//noinspection StatementWithEmptyBody
|
||||
if (alreadyPlaced) {
|
||||
// pass
|
||||
} else if (state.getBlock() instanceof BaseRailBlock) {
|
||||
placeRailWithoutUpdate(world, state, target);
|
||||
} else {
|
||||
world.setBlock(target, state, 2); //Changed flag from 18 to 3
|
||||
world.setBlock(target, state, 18);
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
// if (existingTile instanceof IMergeableTE mergeable) {
|
||||
// BlockEntity loaded = BlockEntity.loadStatic(target, state, data);
|
||||
// if (existingTile.getType()
|
||||
// .equals(loaded.getType())) {
|
||||
// mergeable.accept(loaded);
|
||||
// return;
|
||||
// if (existingBlockEntity instanceof IMergeableBE mergeable) {
|
||||
// BlockEntity loaded = BlockEntity.loadStatic(target, state, data, world.registryAccess());
|
||||
// if (loaded != null) {
|
||||
// if (existingBlockEntity.getType()
|
||||
// .equals(loaded.getType())) {
|
||||
// mergeable.accept(loaded);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
BlockEntity tile = world.getBlockEntity(target);
|
||||
if (tile != null) {
|
||||
BlockEntity blockEntity = world.getBlockEntity(target);
|
||||
if (blockEntity != null) {
|
||||
data.putInt("x", target.getX());
|
||||
data.putInt("y", target.getY());
|
||||
data.putInt("z", target.getZ());
|
||||
// if (tile instanceof KineticTileEntity)
|
||||
// ((KineticTileEntity) tile).warnOfMovement();
|
||||
tile.load(data);
|
||||
// if (blockEntity instanceof KineticBlockEntity kbe)
|
||||
// kbe.warnOfMovement();
|
||||
// if (blockEntity instanceof IMultiBlockEntityContainer imbe)
|
||||
// if (!imbe.isController())
|
||||
// data.put("Controller", NbtUtils.writeBlockPos(imbe.getController()));
|
||||
blockEntity.loadWithComponents(data, world.registryAccess());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
state.getBlock().setPlacedBy(world, target, state, null, stack);
|
||||
} catch (Exception ignored) {
|
||||
state.getBlock()
|
||||
.setPlacedBy(world, target, state, null, stack);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static double getBounceMultiplier(Block block) {
|
||||
@@ -302,22 +370,9 @@ public class BlockHelper {
|
||||
}
|
||||
|
||||
public static boolean hasBlockSolidSide(BlockState p_220056_0_, BlockGetter p_220056_1_, BlockPos p_220056_2_,
|
||||
Direction p_220056_3_) {
|
||||
Direction p_220056_3_) {
|
||||
return !p_220056_0_.is(BlockTags.LEAVES)
|
||||
&& Block.isFaceFull(p_220056_0_.getCollisionShape(p_220056_1_, p_220056_2_), p_220056_3_);
|
||||
}
|
||||
|
||||
public static boolean extinguishFire(Level world, @Nullable Player p_175719_1_, BlockPos p_175719_2_,
|
||||
Direction p_175719_3_) {
|
||||
p_175719_2_ = p_175719_2_.relative(p_175719_3_);
|
||||
if (world.getBlockState(p_175719_2_)
|
||||
.getBlock() == Blocks.FIRE) {
|
||||
world.levelEvent(p_175719_1_, 1009, p_175719_2_, 0);
|
||||
world.removeBlock(p_175719_2_, false);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
&& Block.isFaceFull(p_220056_0_.getCollisionShape(p_220056_1_, p_220056_2_), p_220056_3_);
|
||||
}
|
||||
|
||||
public static BlockState copyProperties(BlockState fromState, BlockState toState) {
|
||||
@@ -328,7 +383,7 @@ public class BlockHelper {
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> BlockState copyProperty(Property<T> property, BlockState fromState,
|
||||
BlockState toState) {
|
||||
BlockState toState) {
|
||||
if (fromState.hasProperty(property) && toState.hasProperty(property)) {
|
||||
return toState.setValue(property, fromState.getValue(property));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.animation.LerpedFloat;
|
||||
import net.createmod.catnip.animation.LerpedFloat;
|
||||
import net.createmod.catnip.math.AngleHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
|
||||
@@ -1,310 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Color {
|
||||
public final static Color TRANSPARENT_BLACK = new Color(0, 0, 0, 0).setImmutable();
|
||||
public final static Color BLACK = new Color(0, 0, 0).setImmutable();
|
||||
public final static Color WHITE = new Color(255, 255, 255).setImmutable();
|
||||
public final static Color RED = new Color(255, 0, 0).setImmutable();
|
||||
public final static Color GREEN = new Color(0, 255, 0).setImmutable();
|
||||
public final static Color SPRING_GREEN = new Color(0, 255, 187).setImmutable();
|
||||
|
||||
protected boolean mutable = true;
|
||||
protected int value;
|
||||
|
||||
public Color(int r, int g, int b) {
|
||||
this(r, g, b, 0xff);
|
||||
}
|
||||
|
||||
public Color(int r, int g, int b, int a) {
|
||||
value = ((a & 0xff) << 24) |
|
||||
((r & 0xff) << 16) |
|
||||
((g & 0xff) << 8) |
|
||||
((b & 0xff) << 0);
|
||||
}
|
||||
|
||||
public Color(float r, float g, float b, float a) {
|
||||
this(
|
||||
(int) (0.5 + 0xff * Mth.clamp(r, 0, 1)),
|
||||
(int) (0.5 + 0xff * Mth.clamp(g, 0, 1)),
|
||||
(int) (0.5 + 0xff * Mth.clamp(b, 0, 1)),
|
||||
(int) (0.5 + 0xff * Mth.clamp(a, 0, 1))
|
||||
);
|
||||
}
|
||||
|
||||
public Color(int rgba) {
|
||||
value = rgba;
|
||||
}
|
||||
|
||||
public Color(int rgb, boolean hasAlpha) {
|
||||
if (hasAlpha) {
|
||||
value = rgb;
|
||||
} else {
|
||||
value = rgb | 0xff_000000;
|
||||
}
|
||||
}
|
||||
|
||||
public Color copy() {
|
||||
return copy(true);
|
||||
}
|
||||
|
||||
public Color copy(boolean mutable) {
|
||||
if (mutable)
|
||||
return new Color(value);
|
||||
else
|
||||
return new Color(value).setImmutable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this color as immutable. Attempting to mutate this color in the future
|
||||
* will instead cause a copy to be created that can me modified.
|
||||
*/
|
||||
public Color setImmutable() {
|
||||
this.mutable = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the red component in the range 0-255.
|
||||
* @see #getRGB
|
||||
*/
|
||||
public int getRed() {
|
||||
return (getRGB() >> 16) & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the green component in the range 0-255.
|
||||
* @see #getRGB
|
||||
*/
|
||||
public int getGreen() {
|
||||
return (getRGB() >> 8) & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the blue component in the range 0-255.
|
||||
* @see #getRGB
|
||||
*/
|
||||
public int getBlue() {
|
||||
return (getRGB() >> 0) & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the alpha component in the range 0-255.
|
||||
* @see #getRGB
|
||||
*/
|
||||
public int getAlpha() {
|
||||
return (getRGB() >> 24) & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the red component in the range 0-1f.
|
||||
*/
|
||||
public float getRedAsFloat() {
|
||||
return getRed() / 255f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the green component in the range 0-1f.
|
||||
*/
|
||||
public float getGreenAsFloat() {
|
||||
return getGreen() / 255f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the blue component in the range 0-1f.
|
||||
*/
|
||||
public float getBlueAsFloat() {
|
||||
return getBlue() / 255f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the alpha component in the range 0-1f.
|
||||
*/
|
||||
public float getAlphaAsFloat() {
|
||||
return getAlpha() / 255f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RGB value representing this color
|
||||
* (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).
|
||||
* @return the RGB value of the color
|
||||
*/
|
||||
public int getRGB() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Vec3 asVector() {
|
||||
return new Vec3(getRedAsFloat(), getGreenAsFloat(), getBlueAsFloat());
|
||||
}
|
||||
|
||||
public Vector3f asVectorF() {
|
||||
return new Vector3f(getRedAsFloat(), getGreenAsFloat(), getBlueAsFloat());
|
||||
}
|
||||
|
||||
public Color setRed(int r) {
|
||||
return ensureMutable().setRedUnchecked(r);
|
||||
}
|
||||
|
||||
public Color setGreen(int g) {
|
||||
return ensureMutable().setGreenUnchecked(g);
|
||||
}
|
||||
|
||||
public Color setBlue(int b) {
|
||||
return ensureMutable().setBlueUnchecked(b);
|
||||
}
|
||||
|
||||
public Color setAlpha(int a) {
|
||||
return ensureMutable().setAlphaUnchecked(a);
|
||||
}
|
||||
|
||||
public Color setRed(float r) {
|
||||
return ensureMutable().setRedUnchecked((int) (0xff * Mth.clamp(r, 0, 1)));
|
||||
}
|
||||
|
||||
public Color setGreen(float g) {
|
||||
return ensureMutable().setGreenUnchecked((int) (0xff * Mth.clamp(g, 0, 1)));
|
||||
}
|
||||
|
||||
public Color setBlue(float b) {
|
||||
return ensureMutable().setBlueUnchecked((int) (0xff * Mth.clamp(b, 0, 1)));
|
||||
}
|
||||
|
||||
public Color setAlpha(float a) {
|
||||
return ensureMutable().setAlphaUnchecked((int) (0xff * Mth.clamp(a, 0, 1)));
|
||||
}
|
||||
|
||||
public Color scaleAlpha(float factor) {
|
||||
return ensureMutable().setAlphaUnchecked((int) (getAlpha() * Mth.clamp(factor, 0, 1)));
|
||||
}
|
||||
|
||||
public Color mixWith(Color other, float weight) {
|
||||
return ensureMutable()
|
||||
.setRedUnchecked((int) (getRed() + (other.getRed() - getRed()) * weight))
|
||||
.setGreenUnchecked((int) (getGreen() + (other.getGreen() - getGreen()) * weight))
|
||||
.setBlueUnchecked((int) (getBlue() + (other.getBlue() - getBlue()) * weight))
|
||||
.setAlphaUnchecked((int) (getAlpha() + (other.getAlpha() - getAlpha()) * weight));
|
||||
}
|
||||
|
||||
public Color darker() {
|
||||
int a = getAlpha();
|
||||
return ensureMutable().mixWith(BLACK, .25f).setAlphaUnchecked(a);
|
||||
}
|
||||
|
||||
public Color brighter() {
|
||||
int a = getAlpha();
|
||||
return ensureMutable().mixWith(WHITE, .25f).setAlphaUnchecked(a);
|
||||
}
|
||||
|
||||
public Color setValue(int value) {
|
||||
return ensureMutable().setValueUnchecked(value);
|
||||
}
|
||||
|
||||
public Color modifyValue(UnaryOperator<Integer> function) {
|
||||
int newValue = function.apply(value);
|
||||
if (newValue == value)
|
||||
return this;
|
||||
|
||||
return ensureMutable().setValueUnchecked(newValue);
|
||||
}
|
||||
|
||||
// ********* //
|
||||
|
||||
protected Color ensureMutable() {
|
||||
if (this.mutable)
|
||||
return this;
|
||||
|
||||
return new Color(this.value);
|
||||
}
|
||||
|
||||
protected Color setRedUnchecked(int r) {
|
||||
this.value = (this.value & 0xff_00ffff) | ((r & 0xff) << 16);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Color setGreenUnchecked(int g) {
|
||||
this.value = (this.value & 0xff_ff00ff) | ((g & 0xff) << 8);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Color setBlueUnchecked(int b) {
|
||||
this.value = (this.value & 0xff_ffff00) | ((b & 0xff) << 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Color setAlphaUnchecked(int a) {
|
||||
this.value = (this.value & 0x00_ffffff) | ((a & 0xff) << 24);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Color setValueUnchecked(int value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
// ********* //
|
||||
|
||||
public static Color mixColors(@Nonnull Color c1, @Nonnull Color c2, float w) {
|
||||
return new Color(
|
||||
(int) (c1.getRed() + (c2.getRed() - c1.getRed()) * w),
|
||||
(int) (c1.getGreen() + (c2.getGreen() - c1.getGreen()) * w),
|
||||
(int) (c1.getBlue() + (c2.getBlue() - c1.getBlue()) * w),
|
||||
(int) (c1.getAlpha() + (c2.getAlpha() - c1.getAlpha()) * w)
|
||||
);
|
||||
}
|
||||
|
||||
public static Color mixColors(@Nonnull Couple<Color> colors, float w) {
|
||||
return mixColors(colors.getFirst(), colors.getSecond(), w);
|
||||
}
|
||||
|
||||
public static int mixColors(int color1, int color2, float w) {
|
||||
int a1 = (color1 >> 24);
|
||||
int r1 = (color1 >> 16) & 0xFF;
|
||||
int g1 = (color1 >> 8) & 0xFF;
|
||||
int b1 = color1 & 0xFF;
|
||||
int a2 = (color2 >> 24);
|
||||
int r2 = (color2 >> 16) & 0xFF;
|
||||
int g2 = (color2 >> 8) & 0xFF;
|
||||
int b2 = color2 & 0xFF;
|
||||
|
||||
return
|
||||
((int) (a1 + (a2 - a1) * w) << 24) +
|
||||
((int) (r1 + (r2 - r1) * w) << 16) +
|
||||
((int) (g1 + (g2 - g1) * w) << 8) +
|
||||
((int) (b1 + (b2 - b1) * w) << 0);
|
||||
}
|
||||
|
||||
public static Color rainbowColor(int timeStep) {
|
||||
int localTimeStep = Math.abs(timeStep) % 1536;
|
||||
int timeStepInPhase = localTimeStep % 256;
|
||||
int phaseBlue = localTimeStep / 256;
|
||||
int red = colorInPhase(phaseBlue + 4, timeStepInPhase);
|
||||
int green = colorInPhase(phaseBlue + 2, timeStepInPhase);
|
||||
int blue = colorInPhase(phaseBlue, timeStepInPhase);
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
|
||||
private static int colorInPhase(int phase, int progress) {
|
||||
phase = phase % 6;
|
||||
if (phase <= 1)
|
||||
return 0;
|
||||
if (phase == 2)
|
||||
return progress;
|
||||
if (phase <= 4)
|
||||
return 255;
|
||||
else
|
||||
return 255 - progress;
|
||||
}
|
||||
|
||||
public static Color generateFromLong(long l) {
|
||||
return rainbowColor(Hashing.crc32().hashLong(l).asInt())
|
||||
.mixWith(WHITE, 0.5f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.minecraft.client.color.block.BlockColor;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.client.renderer.BiomeColors;
|
||||
import net.minecraft.world.level.GrassColor;
|
||||
import net.minecraft.world.level.block.RedStoneWireBlock;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
|
||||
public class ColorHandlers {
|
||||
|
||||
public static BlockColor getGrassyBlock() {
|
||||
return (state, world, pos, layer) -> pos != null && world != null ? BiomeColors.getAverageGrassColor(world, pos)
|
||||
: GrassColor.get(0.5D, 1.0D);
|
||||
}
|
||||
|
||||
public static ItemColor getGrassyItem() {
|
||||
return (stack, layer) -> GrassColor.get(0.5D, 1.0D);
|
||||
}
|
||||
|
||||
public static BlockColor getRedstonePower() {
|
||||
return (state, world, pos, layer) -> RedStoneWireBlock
|
||||
.getColorForPower(pos != null && world != null ? state.getValue(BlockStateProperties.POWER) : 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Couple<T> extends Pair<T, T> implements Iterable<T> {
|
||||
|
||||
private static final Couple<Boolean> TRUE_AND_FALSE = Couple.create(true, false);
|
||||
|
||||
protected Couple(T first, T second) {
|
||||
super(first, second);
|
||||
}
|
||||
|
||||
public static <T> Couple<T> create(T first, T second) {
|
||||
return new Couple<>(first, second);
|
||||
}
|
||||
|
||||
public static <T> Couple<T> create(Supplier<T> factory) {
|
||||
return new Couple<>(factory.get(), factory.get());
|
||||
}
|
||||
|
||||
public static <T> Couple<T> createWithContext(Function<Boolean, T> factory) {
|
||||
return new Couple<>(factory.apply(true), factory.apply(false));
|
||||
}
|
||||
|
||||
public T get(boolean first) {
|
||||
return first ? getFirst() : getSecond();
|
||||
}
|
||||
|
||||
public void set(boolean first, T value) {
|
||||
if (first)
|
||||
setFirst(value);
|
||||
else
|
||||
setSecond(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Couple<T> copy() {
|
||||
return create(first, second);
|
||||
}
|
||||
|
||||
public <S> Couple<S> map(Function<T, S> function) {
|
||||
return Couple.create(function.apply(first), function.apply(second));
|
||||
}
|
||||
|
||||
public <S> Couple<S> mapWithContext(BiFunction<T, Boolean, S> function) {
|
||||
return Couple.create(function.apply(first, true), function.apply(second, false));
|
||||
}
|
||||
|
||||
public <S, R> Couple<S> mapWithParams(BiFunction<T, R, S> function, Couple<R> values) {
|
||||
return Couple.create(function.apply(first, values.first), function.apply(second, values.second));
|
||||
}
|
||||
|
||||
public <S, R> Couple<S> mapNotNullWithParam(BiFunction<T, R, S> function, R value) {
|
||||
return Couple.create(first != null ? function.apply(first, value) : null,
|
||||
second != null ? function.apply(second, value) : null);
|
||||
}
|
||||
|
||||
public boolean both(Predicate<T> test) {
|
||||
return test.test(getFirst()) && test.test(getSecond());
|
||||
}
|
||||
|
||||
public boolean either(Predicate<T> test) {
|
||||
return test.test(getFirst()) || test.test(getSecond());
|
||||
}
|
||||
|
||||
public void replace(Function<T, T> function) {
|
||||
setFirst(function.apply(getFirst()));
|
||||
setSecond(function.apply(getSecond()));
|
||||
}
|
||||
|
||||
public void replaceWithContext(BiFunction<T, Boolean, T> function) {
|
||||
replaceWithParams(function, TRUE_AND_FALSE);
|
||||
}
|
||||
|
||||
public <S> void replaceWithParams(BiFunction<T, S, T> function, Couple<S> values) {
|
||||
setFirst(function.apply(getFirst(), values.getFirst()));
|
||||
setSecond(function.apply(getSecond(), values.getSecond()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super T> consumer) {
|
||||
consumer.accept(getFirst());
|
||||
consumer.accept(getSecond());
|
||||
}
|
||||
|
||||
public void forEachWithContext(BiConsumer<T, Boolean> consumer) {
|
||||
forEachWithParams(consumer, TRUE_AND_FALSE);
|
||||
}
|
||||
|
||||
public <S> void forEachWithParams(BiConsumer<T, S> function, Couple<S> values) {
|
||||
function.accept(getFirst(), values.getFirst());
|
||||
function.accept(getSecond(), values.getSecond());
|
||||
}
|
||||
|
||||
public Couple<T> swap() {
|
||||
return Couple.create(second, first);
|
||||
}
|
||||
|
||||
public ListTag serializeEach(Function<T, CompoundTag> serializer) {
|
||||
return NBTHelper.writeCompoundList(ImmutableList.of(first, second), serializer);
|
||||
}
|
||||
|
||||
public static <S> Couple<S> deserializeEach(ListTag list, Function<CompoundTag, S> deserializer) {
|
||||
List<S> readCompoundList = NBTHelper.readCompoundList(list, deserializer);
|
||||
return new Couple<>(readCompoundList.get(0), readCompoundList.get(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Couplerator<>(this);
|
||||
}
|
||||
|
||||
public Stream<T> stream() {
|
||||
return Stream.of(first, second);
|
||||
}
|
||||
|
||||
private static class Couplerator<T> implements Iterator<T> {
|
||||
|
||||
int state;
|
||||
private final Couple<T> couple;
|
||||
|
||||
public Couplerator(Couple<T> couple) {
|
||||
this.couple = couple;
|
||||
state = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return state != 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
state++;
|
||||
if (state == 1)
|
||||
return couple.first;
|
||||
if (state == 2)
|
||||
return couple.second;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user