Port to 1.20.4
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -20,7 +20,7 @@ build
|
||||
# other
|
||||
eclipse
|
||||
run
|
||||
logs/*
|
||||
runs
|
||||
run-data
|
||||
|
||||
# Files from Forge MDK
|
||||
forge*changelog.txt
|
||||
repo
|
||||
128
build.gradle
128
build.gradle
@@ -1,25 +1,11 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url = 'https://maven.minecraftforge.net' }
|
||||
mavenCentral()
|
||||
maven { url = 'https://repo.spongepowered.org/repository/maven-public' }
|
||||
maven { url = 'https://maven.parchmentmc.org' }
|
||||
}
|
||||
dependencies {
|
||||
classpath "net.minecraftforge.gradle:ForgeGradle:${forgegradle_version}"
|
||||
classpath "org.spongepowered:mixingradle:${mixingradle_version}"
|
||||
classpath "org.parchmentmc:librarian:${librarian_version}"
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'eclipse'
|
||||
id 'idea'
|
||||
id 'maven-publish'
|
||||
id 'net.neoforged.gradle.userdev' version "${neogradle_version}"
|
||||
id 'com.matthewprenger.cursegradle' version "${cursegradle_version}"
|
||||
}
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: 'org.parchmentmc.librarian.forgegradle'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'org.spongepowered.mixin'
|
||||
|
||||
jarJar.enable()
|
||||
|
||||
@@ -37,57 +23,48 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(17)
|
||||
|
||||
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + ' (' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
|
||||
|
||||
minecraft {
|
||||
mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}"
|
||||
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
|
||||
runs {
|
||||
client {
|
||||
workingDirectory project.file('run')
|
||||
arg '-mixin.config=flywheel.mixins.json'
|
||||
//jvmArgs '-XX:+UnlockCommercialFeatures' // uncomment for profiling
|
||||
property 'forge.logging.console.level', 'info'
|
||||
runs {
|
||||
// applies to all the run configs below
|
||||
configureEach { net.neoforged.gradle.dsl.common.runs.run.Run run ->
|
||||
// Recommended logging data for a userdev environment
|
||||
systemProperty 'forge.logging.markers', 'REGISTRIES'
|
||||
|
||||
mods {
|
||||
effortlessbuilding {
|
||||
source sourceSets.main
|
||||
}
|
||||
// Recommended logging level for the console
|
||||
systemProperty 'forge.logging.console.level', 'debug'
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
flywheel {
|
||||
source project(":Flywheel").sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
//Limit ram usage for the dev environment to 4GB
|
||||
jvmArgument '-Xmx4G'
|
||||
if (run.project.javaToolchains.launcherFor(java.toolchain).map { it.metadata.vendor }.getOrElse("").contains("JetBrains")) {
|
||||
jvmArgument '-XX:+AllowEnhancedClassRedefinition'
|
||||
}
|
||||
|
||||
server {
|
||||
workingDirectory project.file('run/server')
|
||||
property 'forge.logging.console.level', 'info'
|
||||
mods {
|
||||
effortlessbuilding {
|
||||
source sourceSets.main
|
||||
}
|
||||
modSource project.sourceSets.main
|
||||
}
|
||||
|
||||
client {
|
||||
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
|
||||
systemProperty 'neoforge.enabledGameTestNamespaces', "effortlessbuilding"
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
dependencies {
|
||||
runtime project(':Flywheel')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data {
|
||||
workingDirectory project.file('run')
|
||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
args '--mod', 'effortlessbuilding', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources')
|
||||
mods {
|
||||
effortlessbuilding {
|
||||
source sourceSets.main
|
||||
}
|
||||
server {
|
||||
systemProperty 'neoforge.enabledGameTestNamespaces', "effortlessbuilding"
|
||||
programArgument '--nogui'
|
||||
}
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
flywheel {
|
||||
source project(":Flywheel").sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
data {
|
||||
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
|
||||
// workingDirectory project.file('run-data')
|
||||
|
||||
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
|
||||
programArguments.addAll '--mod', "effortlessbuilding", '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,10 +74,13 @@ repositories {
|
||||
name = 'tterrag maven'
|
||||
url = 'https://maven.tterrag.com'
|
||||
}
|
||||
|
||||
maven {
|
||||
url = 'https://www.cursemaven.com'
|
||||
content {
|
||||
exclusiveContent {
|
||||
forRepository {
|
||||
maven {
|
||||
url "https://cursemaven.com"
|
||||
}
|
||||
}
|
||||
filter {
|
||||
includeGroup "curse.maven"
|
||||
}
|
||||
}
|
||||
@@ -119,22 +99,16 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||
implementation "net.neoforged:neoforge:${neo_version}"
|
||||
|
||||
jarJar("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") {
|
||||
jarJar.ranged(it, '[0.6.10,0.7)')
|
||||
version { prefer "0.6.10" }
|
||||
}
|
||||
|
||||
if (flywheelInWorkspace) {
|
||||
implementation project(':Flywheel')
|
||||
} else {
|
||||
implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}")
|
||||
}
|
||||
|
||||
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
||||
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
||||
if (!Boolean.getBoolean('idea.sync.active')) {
|
||||
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
|
||||
implementation "com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,8 +153,7 @@ java {
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
jar.finalizedBy('reobfJar')
|
||||
tasks.jarJar.finalizedBy('reobfJarJar')
|
||||
tasks.build.dependsOn tasks.jarJar
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
@@ -188,8 +161,7 @@ publishing {
|
||||
artifactId = base.archivesName.get()
|
||||
|
||||
from components.java
|
||||
fg.component(it)
|
||||
jarJar.component(it)
|
||||
// fg.component(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,15 @@ org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
mod_version = 3.5
|
||||
artifact_minecraft_version = 1.20.1
|
||||
artifact_minecraft_version = 1.20.4
|
||||
|
||||
minecraft_version = 1.20.1
|
||||
forge_version = 47.1.3
|
||||
minecraft_version = 1.20.4
|
||||
neo_version = 20.4.232
|
||||
neogradle.subsystems.parchment.minecraftVersion = 1.20.4
|
||||
neogradle.subsystems.parchment.mappingsVersion = 2024.02.25
|
||||
|
||||
forgegradle_version = 6.0.7
|
||||
mixingradle_version = 0.7-SNAPSHOT
|
||||
mixin_version = 0.8.5
|
||||
librarian_version = 1.+
|
||||
neogradle_version = 7.0.107
|
||||
cursegradle_version = 1.4.0
|
||||
parchment_version = 2023.09.03
|
||||
|
||||
flywheel_minecraft_version = 1.20.1
|
||||
flywheel_version = 0.6.10-7
|
||||
flywheel_minecraft_version = 1.20.4
|
||||
flywheel_version = 0.6.10
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
7
gradlew
vendored
7
gradlew
vendored
@@ -85,9 +85,6 @@ done
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
@@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
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
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven { url = 'https://maven.minecraftforge.net/' }
|
||||
maven {
|
||||
name = 'Official NeoForge Maven'
|
||||
url = 'https://maven.neoforged.net/releases'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
|
||||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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;
|
||||
|
||||
@@ -8,8 +8,8 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.*;
|
||||
|
||||
public class ClientConfig {
|
||||
|
||||
private static final Builder builder = new Builder();
|
||||
public static final Visuals visuals = new Visuals(builder);
|
||||
public static final ForgeConfigSpec spec = builder.build();
|
||||
public static final ModConfigSpec spec = builder.build();
|
||||
|
||||
public static class Visuals {
|
||||
public final BooleanValue showBlockPreviews;
|
||||
|
||||
@@ -6,18 +6,18 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
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.buildmode.BuildModeEnum;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
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;
|
||||
@@ -134,7 +134,7 @@ public class ClientEvents {
|
||||
|
||||
//Radial menu
|
||||
if (keyBindings[0].isDown()) {
|
||||
if (!CapabilityHandler.isDisabled(player)) {
|
||||
if (!AttachmentHandler.isDisabled(player)) {
|
||||
if (!RadialMenu.instance.isVisible()) {
|
||||
Minecraft.getInstance().setScreen(RadialMenu.instance);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ public class ClientEvents {
|
||||
if (player == null) return;
|
||||
|
||||
//Disabled if max reach is 0, might be set in the config that way.
|
||||
if (CapabilityHandler.isDisabled(player)) {
|
||||
if (AttachmentHandler.isDisabled(player)) {
|
||||
EffortlessBuilding.log(player, "Build modifiers are disabled until your power level has increased. Increase your power level by consuming certain items.");
|
||||
} else {
|
||||
mc.setScreen(new ModifiersScreen());
|
||||
@@ -188,7 +188,7 @@ public class ClientEvents {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onGuiOpen(ScreenEvent event) {
|
||||
public static void onGuiOpen(ScreenEvent.Opening event) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player != null) {
|
||||
EffortlessBuildingClient.BUILDER_CHAIN.cancel();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.*;
|
||||
|
||||
public class CommonConfig {
|
||||
|
||||
@@ -11,7 +11,7 @@ public class CommonConfig {
|
||||
public static final MaxBlocksPlacedAtOnce maxBlocksPlacedAtOnce = new MaxBlocksPlacedAtOnce(builder);
|
||||
public static final MaxBlocksPerAxis maxBlocksPerAxis = new MaxBlocksPerAxis(builder);
|
||||
public static final MaxMirrorRadius maxMirrorRadius = new MaxMirrorRadius(builder);
|
||||
public static final ForgeConfigSpec spec = builder.build();
|
||||
public static final ModConfigSpec spec = builder.build();
|
||||
|
||||
public static class Reach {
|
||||
public final IntValue creative;
|
||||
|
||||
@@ -2,27 +2,22 @@ package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.level.BlockEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||
import nl.requios.effortlessbuilding.capability.PowerLevelCapability;
|
||||
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.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 nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||
import nl.requios.effortlessbuilding.network.ModifierSettingsPacket;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
||||
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
||||
import nl.requios.effortlessbuilding.network.message.PowerLevelPacket;
|
||||
import nl.requios.effortlessbuilding.systems.ServerBuildState;
|
||||
import nl.requios.effortlessbuilding.utilities.PowerLevelCommand;
|
||||
|
||||
@@ -30,7 +25,7 @@ import nl.requios.effortlessbuilding.utilities.PowerLevelCommand;
|
||||
public class CommonEvents {
|
||||
|
||||
//Mod Bus Events
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||
// @EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||
public static class ModBusEvents {
|
||||
|
||||
|
||||
@@ -45,6 +40,7 @@ public class CommonEvents {
|
||||
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;
|
||||
|
||||
EffortlessBuilding.SERVER_BLOCK_PLACER.tick();
|
||||
}
|
||||
@@ -80,9 +76,7 @@ public class CommonEvents {
|
||||
//Don't cancel event if our custom logic is breaking blocks
|
||||
if (EffortlessBuilding.SERVER_BLOCK_PLACER.isPlacingOrBreakingBlocks()) return;
|
||||
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
if (powerLevel == null) return; //Should never be null but just to be sure
|
||||
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (!ServerBuildState.isLikeVanilla(player) && powerLevel.canBreakFar(player)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
@@ -102,19 +96,10 @@ public class CommonEvents {
|
||||
|
||||
ServerBuildState.handleNewPlayer(player);
|
||||
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new ModifierSettingsPacket(player));
|
||||
((ServerPlayer)player).connection.send(new ModifierSettingsPacket(player));
|
||||
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
if (powerLevel == null) return; //Should never be null but just to be sure
|
||||
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerCaps(AttachCapabilitiesEvent<Entity> event) {
|
||||
if (event.getObject() instanceof Player) {
|
||||
event.addCapability(CapabilityHandler.POWER_LEVEL_CAP, new PowerLevelCapability());
|
||||
}
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
((ServerPlayer)player).connection.send(new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -126,11 +111,9 @@ public class CommonEvents {
|
||||
Player clone = event.getEntity();
|
||||
|
||||
// Copy the power level from the original player to the clone
|
||||
original.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).ifPresent(dataOriginal ->
|
||||
clone.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).ifPresent(dataClone -> {
|
||||
dataClone.setPowerLevel(dataOriginal.getPowerLevel());
|
||||
})
|
||||
);
|
||||
if (event.isWasDeath() && event.getOriginal().hasData(EffortlessBuilding.POWER_LEVEL)) {
|
||||
event.getEntity().setData(EffortlessBuilding.POWER_LEVEL, event.getOriginal().getData(EffortlessBuilding.POWER_LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,34 +1,42 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
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.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.network.IContainerFactory;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.DistExecutor;
|
||||
import net.neoforged.fml.ModLoadingContext;
|
||||
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.common.NeoForge;
|
||||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
|
||||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
||||
import net.neoforged.neoforge.network.IContainerFactory;
|
||||
import net.neoforged.neoforge.registries.DeferredItem;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
||||
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||
import nl.requios.effortlessbuilding.compatibility.CompatHelper;
|
||||
import nl.requios.effortlessbuilding.gui.DiamondRandomizerBagContainer;
|
||||
import nl.requios.effortlessbuilding.gui.GoldenRandomizerBagContainer;
|
||||
import nl.requios.effortlessbuilding.gui.RandomizerBagContainer;
|
||||
import nl.requios.effortlessbuilding.item.*;
|
||||
import nl.requios.effortlessbuilding.item.DiamondRandomizerBagItem;
|
||||
import nl.requios.effortlessbuilding.item.GoldenRandomizerBagItem;
|
||||
import nl.requios.effortlessbuilding.item.PowerLevelItem;
|
||||
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
|
||||
import nl.requios.effortlessbuilding.item.ReachUpgrade1Item;
|
||||
import nl.requios.effortlessbuilding.item.ReachUpgrade2Item;
|
||||
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;
|
||||
@@ -40,6 +48,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mod(EffortlessBuilding.MODID)
|
||||
public class EffortlessBuilding {
|
||||
@@ -55,42 +64,48 @@ public class EffortlessBuilding {
|
||||
public static final ItemUsageTracker ITEM_USAGE_TRACKER = new ItemUsageTracker();
|
||||
|
||||
//Registration
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
private static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, EffortlessBuilding.MODID);
|
||||
public static final DeferredRegister<Codec<? extends IGlobalLootModifier>> LOOT_MODIFIERS = DeferredRegister.create(ForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, EffortlessBuilding.MODID);
|
||||
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<AttachmentType<?>> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, EffortlessBuilding.MODID);
|
||||
|
||||
public static final RegistryObject<Item> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
|
||||
public static final RegistryObject<Item> GOLDEN_RANDOMIZER_BAG_ITEM = ITEMS.register("golden_randomizer_bag", GoldenRandomizerBagItem::new);
|
||||
public static final RegistryObject<Item> DIAMOND_RANDOMIZER_BAG_ITEM = ITEMS.register("diamond_randomizer_bag", DiamondRandomizerBagItem::new);
|
||||
public static final RegistryObject<Item> REACH_UPGRADE_1_ITEM = ITEMS.register("reach_upgrade1", ReachUpgrade1Item::new);
|
||||
public static final RegistryObject<Item> REACH_UPGRADE_2_ITEM = ITEMS.register("reach_upgrade2", ReachUpgrade2Item::new);
|
||||
public static final RegistryObject<Item> REACH_UPGRADE_3_ITEM = ITEMS.register("reach_upgrade3", ReachUpgrade3Item::new);
|
||||
public static final RegistryObject<Item> MUSCLES_ITEM = ITEMS.register("muscles", PowerLevelItem::new);
|
||||
public static final RegistryObject<Item> ELASTIC_HAND_ITEM = ITEMS.register("elastic_hand", PowerLevelItem::new);
|
||||
public static final RegistryObject<Item> BUILDING_TECHNIQUES_BOOK_ITEM = ITEMS.register("building_techniques_book", PowerLevelItem::new);
|
||||
public static final DeferredItem<RandomizerBagItem> RANDOMIZER_BAG_ITEM = ITEMS.register("randomizer_bag", RandomizerBagItem::new);
|
||||
public static final DeferredItem<GoldenRandomizerBagItem> GOLDEN_RANDOMIZER_BAG_ITEM = ITEMS.register("golden_randomizer_bag", GoldenRandomizerBagItem::new);
|
||||
public static final DeferredItem<DiamondRandomizerBagItem> DIAMOND_RANDOMIZER_BAG_ITEM = ITEMS.register("diamond_randomizer_bag", DiamondRandomizerBagItem::new);
|
||||
public static final DeferredItem<ReachUpgrade1Item> REACH_UPGRADE_1_ITEM = ITEMS.register("reach_upgrade1", ReachUpgrade1Item::new);
|
||||
public static final DeferredItem<ReachUpgrade2Item> REACH_UPGRADE_2_ITEM = ITEMS.register("reach_upgrade2", ReachUpgrade2Item::new);
|
||||
public static final DeferredItem<ReachUpgrade3Item> REACH_UPGRADE_3_ITEM = ITEMS.register("reach_upgrade3", ReachUpgrade3Item::new);
|
||||
public static final DeferredItem<PowerLevelItem> MUSCLES_ITEM = ITEMS.register("muscles", PowerLevelItem::new);
|
||||
public static final DeferredItem<PowerLevelItem> ELASTIC_HAND_ITEM = ITEMS.register("elastic_hand", PowerLevelItem::new);
|
||||
public static final DeferredItem<PowerLevelItem> BUILDING_TECHNIQUES_BOOK_ITEM = ITEMS.register("building_techniques_book", PowerLevelItem::new);
|
||||
|
||||
public static final RegistryObject<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
|
||||
public static final RegistryObject<MenuType<GoldenRandomizerBagContainer>> GOLDEN_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("golden_randomizer_bag", () -> registerContainer(GoldenRandomizerBagContainer::new));
|
||||
public static final RegistryObject<MenuType<DiamondRandomizerBagContainer>> DIAMOND_RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("diamond_randomizer_bag", () -> registerContainer(DiamondRandomizerBagContainer::new));
|
||||
public static final Supplier<MenuType<RandomizerBagContainer>> RANDOMIZER_BAG_CONTAINER = CONTAINERS.register("randomizer_bag", () -> registerContainer(RandomizerBagContainer::new));
|
||||
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 EffortlessBuilding() {
|
||||
public static final Supplier<AttachmentType<PowerLevel>> POWER_LEVEL = ATTACHMENT_TYPES.register("power_level", () -> AttachmentType.serializable(PowerLevel::new).build());
|
||||
|
||||
public EffortlessBuilding(IEventBus modEventBus) {
|
||||
instance = this;
|
||||
|
||||
ModLoadingContext modLoadingContext = ModLoadingContext.get();
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
IEventBus forgeEventBus = MinecraftForge.EVENT_BUS;
|
||||
IEventBus forgeEventBus = NeoForge.EVENT_BUS;
|
||||
|
||||
modEventBus.addListener(EffortlessBuilding::setup);
|
||||
modEventBus.addListener(EffortlessBuilding::addTabContents);
|
||||
modEventBus.addListener(PacketHandler::setupPackets);
|
||||
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> EffortlessBuildingClient.onConstructorClient(modEventBus, forgeEventBus));
|
||||
if (FMLEnvironment.dist.isClient()) {
|
||||
EffortlessBuildingClient.onConstructorClient(modEventBus, forgeEventBus);
|
||||
}
|
||||
|
||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
CONTAINERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
ITEMS.register(modEventBus);
|
||||
CONTAINERS.register(modEventBus);
|
||||
|
||||
var singleItemLootModifier = SingleItemLootModifier.CODEC; //load this class to register the loot modifier
|
||||
LOOT_MODIFIERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
LOOT_MODIFIERS.register(modEventBus);
|
||||
ATTACHMENT_TYPES.register(modEventBus);
|
||||
|
||||
//Register config
|
||||
modLoadingContext.registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
|
||||
@@ -99,8 +114,6 @@ public class EffortlessBuilding {
|
||||
}
|
||||
|
||||
public static void setup(final FMLCommonSetupEvent event) {
|
||||
PacketHandler.register();
|
||||
|
||||
CompatHelper.setup();
|
||||
}
|
||||
|
||||
@@ -111,7 +124,7 @@ public class EffortlessBuilding {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends AbstractContainerMenu> MenuType<T> registerContainer(IContainerFactory<T> fact){
|
||||
public static <T extends AbstractContainerMenu> MenuType<T> registerContainer(IContainerFactory<T> fact) {
|
||||
MenuType<T> type = new MenuType<T>(fact, FeatureFlags.REGISTRY.allFlags());
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BuildModifiers;
|
||||
import nl.requios.effortlessbuilding.gui.DiamondRandomizerBagScreen;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package nl.requios.effortlessbuilding;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraftforge.common.ForgeConfigSpec.*;
|
||||
import static net.neoforged.neoforge.common.ModConfigSpec.*;
|
||||
|
||||
public class ServerConfig {
|
||||
private static final Builder builder = new Builder();
|
||||
public static final ServerConfig.Validation validation = new ServerConfig.Validation(builder);
|
||||
public static final ServerConfig.Memory memory = new ServerConfig.Memory(builder);
|
||||
public static final ForgeConfigSpec spec = builder.build();
|
||||
public static final ModConfigSpec spec = builder.build();
|
||||
|
||||
public static class Validation {
|
||||
public final BooleanValue allowInSurvival;
|
||||
|
||||
@@ -1,33 +1,26 @@
|
||||
package nl.requios.effortlessbuilding.capability;
|
||||
package nl.requios.effortlessbuilding.attachment;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import nl.requios.effortlessbuilding.CommonConfig;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.network.PowerLevelPacket;
|
||||
import nl.requios.effortlessbuilding.network.message.PowerLevelPacket;
|
||||
|
||||
public class CapabilityHandler {
|
||||
public class AttachmentHandler {
|
||||
public static final ResourceLocation POWER_LEVEL_CAP = new ResourceLocation(EffortlessBuilding.MODID, "power_level");
|
||||
public static final Capability<IPowerLevel> POWER_LEVEL_CAPABILITY = CapabilityManager.get(new CapabilityToken<>() {
|
||||
});
|
||||
|
||||
public static void syncToClient(Player player) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel == null) return; //Should never be null but just to be sure
|
||||
|
||||
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||
((ServerPlayer)player).connection.send(new PowerLevelPacket(powerLevel.getPowerLevel()));
|
||||
}
|
||||
|
||||
//Helper methods to reduce boilerplate code
|
||||
public static boolean canReplaceBlocks(Player player) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.canReplaceBlocks(player);
|
||||
}
|
||||
@@ -37,7 +30,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.getMaxBlocksPerAxis(player, nextPowerLevel);
|
||||
}
|
||||
@@ -47,7 +40,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.getMaxBlocksPlacedAtOnce(player, nextPowerLevel);
|
||||
}
|
||||
@@ -57,7 +50,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.getMaxMirrorRadius(player, nextPowerLevel);
|
||||
}
|
||||
@@ -67,7 +60,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static int getBuildModeReach(Player player) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.getBuildModeReach(player);
|
||||
}
|
||||
@@ -77,7 +70,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.getPlacementReach(player, nextPowerLevel);
|
||||
}
|
||||
@@ -87,7 +80,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static int getPowerLevel(Player player) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.getPowerLevel();
|
||||
}
|
||||
@@ -97,7 +90,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static int getNextPowerLevel(Player player) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.getNextPowerLevel();
|
||||
}
|
||||
@@ -107,7 +100,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static boolean canIncreasePowerLevel(Player player) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.canIncreasePowerLevel();
|
||||
}
|
||||
@@ -117,7 +110,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static boolean isDisabled(Player player) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.isDisabled(player);
|
||||
}
|
||||
@@ -127,7 +120,7 @@ public class CapabilityHandler {
|
||||
|
||||
public static boolean canBreakFar(Player player) {
|
||||
if (player != null) {
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
return powerLevel.canBreakFar(player);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package nl.requios.effortlessbuilding.attachment;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.neoforged.neoforge.common.util.INBTSerializable;
|
||||
import nl.requios.effortlessbuilding.CommonConfig;
|
||||
|
||||
public class PowerLevel implements INBTSerializable<CompoundTag> {
|
||||
public static final int MAX_POWER_LEVEL = 3; //Common access
|
||||
|
||||
public PowerLevel() {
|
||||
}
|
||||
|
||||
private int powerLevel = 0;
|
||||
|
||||
public int getPowerLevel() {
|
||||
return this.powerLevel;
|
||||
}
|
||||
|
||||
public int getNextPowerLevel() {
|
||||
return Math.min(getPowerLevel() + 1, MAX_POWER_LEVEL);
|
||||
}
|
||||
|
||||
public void setPowerLevel(int powerLevel) {
|
||||
this.powerLevel = powerLevel;
|
||||
}
|
||||
|
||||
public boolean canIncreasePowerLevel() {
|
||||
return getPowerLevel() < MAX_POWER_LEVEL;
|
||||
}
|
||||
|
||||
public void increasePowerLevel() {
|
||||
if (canIncreasePowerLevel()) {
|
||||
setPowerLevel(getPowerLevel() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.reach.creative.get();
|
||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||
case 1 -> CommonConfig.reach.level1.get();
|
||||
case 2 -> CommonConfig.reach.level2.get();
|
||||
case 3 -> CommonConfig.reach.level3.get();
|
||||
default -> CommonConfig.reach.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
//How far away we can detect the second and third click of build modes (distance to player)
|
||||
public int getBuildModeReach(Player player) {
|
||||
//A bit further than placement reach, so you can build lines when looking to the side without having to move.
|
||||
return getPlacementReach(player, false) + 6;
|
||||
}
|
||||
|
||||
public int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.maxBlocksPlacedAtOnce.creative.get();
|
||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||
case 1 -> CommonConfig.maxBlocksPlacedAtOnce.level1.get();
|
||||
case 2 -> CommonConfig.maxBlocksPlacedAtOnce.level2.get();
|
||||
case 3 -> CommonConfig.maxBlocksPlacedAtOnce.level3.get();
|
||||
default -> CommonConfig.maxBlocksPlacedAtOnce.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
public int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.maxBlocksPerAxis.creative.get();
|
||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||
case 1 -> CommonConfig.maxBlocksPerAxis.level1.get();
|
||||
case 2 -> CommonConfig.maxBlocksPerAxis.level2.get();
|
||||
case 3 -> CommonConfig.maxBlocksPerAxis.level3.get();
|
||||
default -> CommonConfig.maxBlocksPerAxis.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
public int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.maxMirrorRadius.creative.get();
|
||||
return switch (getPowerLevel() + (nextPowerLevel ? 1 : 0)) {
|
||||
case 1 -> CommonConfig.maxMirrorRadius.level1.get();
|
||||
case 2 -> CommonConfig.maxMirrorRadius.level2.get();
|
||||
case 3 -> CommonConfig.maxMirrorRadius.level3.get();
|
||||
default -> CommonConfig.maxMirrorRadius.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isDisabled(Player player) {
|
||||
return getMaxBlocksPlacedAtOnce(player, false) <= 0 || getMaxBlocksPerAxis(player, false) <= 0;
|
||||
}
|
||||
|
||||
public boolean canBreakFar(Player player) {
|
||||
return player.getAbilities().instabuild;
|
||||
}
|
||||
|
||||
public boolean canReplaceBlocks(Player player) {
|
||||
return player.getAbilities().instabuild;
|
||||
}
|
||||
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("powerLevel", getPowerLevel());
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
setPowerLevel(nbt.getInt("powerLevel"));
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.network.IsUsingBuildModePacket;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.network.message.IsUsingBuildModePacket;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@@ -30,7 +30,7 @@ public class BuildModes {
|
||||
public void setBuildMode(BuildModeEnum buildMode) {
|
||||
this.buildMode = buildMode;
|
||||
|
||||
PacketHandler.INSTANCE.sendToServer(new IsUsingBuildModePacket(this.buildMode != BuildModeEnum.DISABLED));
|
||||
PacketDistributor.SERVER.noArg().send(new IsUsingBuildModePacket(this.buildMode != BuildModeEnum.DISABLED));
|
||||
|
||||
EffortlessBuilding.log(Minecraft.getInstance().player, I18n.get(buildMode.getNameKey()), true);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package nl.requios.effortlessbuilding.buildmode;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import nl.requios.effortlessbuilding.AllIcons;
|
||||
import nl.requios.effortlessbuilding.ClientEvents;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.network.PerformRedoPacket;
|
||||
import nl.requios.effortlessbuilding.network.PerformUndoPacket;
|
||||
import nl.requios.effortlessbuilding.network.message.PerformRedoPacket;
|
||||
import nl.requios.effortlessbuilding.network.message.PerformUndoPacket;
|
||||
import nl.requios.effortlessbuilding.systems.BuildSettings;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@@ -69,8 +69,8 @@ public class ModeOptions {
|
||||
if (action == null) return;
|
||||
|
||||
switch (action) {
|
||||
case UNDO -> PacketHandler.INSTANCE.sendToServer(new PerformUndoPacket());
|
||||
case REDO -> PacketHandler.INSTANCE.sendToServer(new PerformRedoPacket());
|
||||
case UNDO -> PacketDistributor.SERVER.noArg().send(new PerformUndoPacket());
|
||||
case REDO -> PacketDistributor.SERVER.noArg().send(new PerformRedoPacket());
|
||||
case OPEN_MODIFIER_SETTINGS -> ClientEvents.openModifierSettings();
|
||||
case OPEN_PLAYER_SETTINGS -> ClientEvents.openPlayerSettings();
|
||||
case PREVIOUS_BUILD_MODE -> EffortlessBuildingClient.BUILD_MODES.activatePreviousBuildMode();
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
||||
if (secondPos == null) return;
|
||||
|
||||
//Limit amount of blocks we can place per row
|
||||
int axisLimit = CapabilityHandler.getMaxBlocksPerAxis(player, false);
|
||||
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||
|
||||
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
||||
int y1 = firstPos.getY(), y2 = secondPos.getY();
|
||||
@@ -94,7 +94,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
||||
if (thirdPos == null) return;
|
||||
|
||||
//Limit amount of blocks you can place per row
|
||||
int axisLimit = CapabilityHandler.getMaxBlocksPerAxis(player, false);
|
||||
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||
|
||||
int x1 = firstPos.getX(), x2 = secondPos.getX(), x3 = thirdPos.getX();
|
||||
int y1 = firstPos.getY(), y2 = secondPos.getY(), y3 = thirdPos.getY();
|
||||
@@ -140,7 +140,7 @@ public abstract class ThreeClicksBuildMode extends BaseBuildMode {
|
||||
criteriaList.add(new HeightCriteria(zBound, secondPos, start));
|
||||
|
||||
//Remove invalid criteria
|
||||
int reach = CapabilityHandler.getBuildModeReach(player);
|
||||
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||
|
||||
//If none are valid, return empty list of blocks
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class TwoClicksBuildMode extends BaseBuildMode {
|
||||
if (secondPos == null) return;
|
||||
|
||||
//Limit amount of blocks we can place per row
|
||||
int axisLimit = CapabilityHandler.getMaxBlocksPerAxis(player, false);
|
||||
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||
|
||||
int x1 = firstPos.getX(), x2 = secondPos.getX();
|
||||
int y1 = firstPos.getY(), y2 = secondPos.getY();
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -24,7 +24,7 @@ public class Floor extends TwoClicksBuildMode {
|
||||
criteriaList.add(new Criteria(yBound, start));
|
||||
|
||||
//Remove invalid criteria
|
||||
int reach = CapabilityHandler.getBuildModeReach(player);
|
||||
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||
|
||||
//If none are valid, return empty list of blocks
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -31,7 +31,7 @@ public class Line extends TwoClicksBuildMode {
|
||||
criteriaList.add(new Criteria(zBound, firstPos, start));
|
||||
|
||||
//Remove invalid criteria
|
||||
int reach = CapabilityHandler.getBuildModeReach(player);
|
||||
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||
|
||||
//If none are valid, return empty list of blocks
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.ThreeClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -15,7 +15,7 @@ public class SlopeFloor extends ThreeClicksBuildMode {
|
||||
public static List<BlockPos> getSlopeFloorBlocks(Player player, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {
|
||||
List<BlockPos> list = new ArrayList<>();
|
||||
|
||||
int axisLimit = CapabilityHandler.getMaxBlocksPerAxis(player, false);
|
||||
int axisLimit = AttachmentHandler.getMaxBlocksPerAxis(player, false);
|
||||
|
||||
//Determine whether to use x or z axis to slope up
|
||||
boolean onXAxis = true;
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.buildmode.BuildModes;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.TwoClicksBuildMode;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -28,7 +28,7 @@ public class Wall extends TwoClicksBuildMode {
|
||||
criteriaList.add(new Criteria(zBound, firstPos, start, look));
|
||||
|
||||
//Remove invalid criteria
|
||||
int reach = CapabilityHandler.getBuildModeReach(player);
|
||||
int reach = AttachmentHandler.getBuildModeReach(player);
|
||||
criteriaList.removeIf(criteria -> !criteria.isValid(start, look, reach, player, skipRaytrace));
|
||||
|
||||
//If none are valid, return empty list of blocks
|
||||
|
||||
@@ -3,11 +3,11 @@ package nl.requios.effortlessbuilding.buildmodifier;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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.ModifierSettingsPacket;
|
||||
import nl.requios.effortlessbuilding.network.PacketHandler;
|
||||
import nl.requios.effortlessbuilding.network.message.ModifierSettingsPacket;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -96,7 +96,7 @@ public class BuildModifiers {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
PacketHandler.INSTANCE.sendToServer(new ModifierSettingsPacket(serializeNBT()));
|
||||
PacketDistributor.SERVER.noArg().send(new ModifierSettingsPacket(serializeNBT()));
|
||||
|
||||
//Save locally as well?
|
||||
// var listTag = NBTHelper.writeCompoundList(modifierSettingsList, BaseModifier::serializeNBT);
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Mirror extends BaseModifier {
|
||||
|
||||
@Override
|
||||
public void onPowerLevelChanged(int powerLevel) {
|
||||
radius = CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||
radius = AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||
}
|
||||
|
||||
private void performMirrorX(BlockSet blocks, BlockEntry blockEntry) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockSet;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RadialMirror extends BaseModifier {
|
||||
|
||||
@Override
|
||||
public void onPowerLevelChanged(int powerLevel) {
|
||||
radius = CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||
radius = AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false);
|
||||
}
|
||||
|
||||
public void performRadialMirror(BlockSet blocks, BlockEntry blockEntry) {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.capability;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.capabilities.AutoRegisterCapability;
|
||||
|
||||
@AutoRegisterCapability
|
||||
public interface IPowerLevel {
|
||||
|
||||
int getPowerLevel();
|
||||
|
||||
int getNextPowerLevel();
|
||||
|
||||
void setPowerLevel(int powerLevel);
|
||||
|
||||
boolean canIncreasePowerLevel();
|
||||
|
||||
void increasePowerLevel();
|
||||
|
||||
|
||||
int getPlacementReach(Player player, boolean nextPowerLevel);
|
||||
|
||||
int getBuildModeReach(Player player);
|
||||
|
||||
|
||||
int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel);
|
||||
|
||||
|
||||
int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel);
|
||||
|
||||
|
||||
int getMaxMirrorRadius(Player player, boolean nextPowerLevel);
|
||||
|
||||
boolean isDisabled(Player player);
|
||||
|
||||
boolean canBreakFar(Player player);
|
||||
|
||||
boolean canReplaceBlocks(Player player);
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.capability;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import nl.requios.effortlessbuilding.CommonConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PowerLevelCapability implements IPowerLevel, ICapabilitySerializable<CompoundTag> {
|
||||
public static final int MAX_POWER_LEVEL = 3; //Common access
|
||||
|
||||
private int powerLevel = 0;
|
||||
|
||||
@Override
|
||||
public int getPowerLevel() {
|
||||
return this.powerLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextPowerLevel() {
|
||||
return Math.min(getPowerLevel() + 1, MAX_POWER_LEVEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPowerLevel(int powerLevel) {
|
||||
this.powerLevel = powerLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canIncreasePowerLevel() {
|
||||
return getPowerLevel() < MAX_POWER_LEVEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increasePowerLevel() {
|
||||
if (canIncreasePowerLevel()) {
|
||||
setPowerLevel(getPowerLevel() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlacementReach(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.reach.creative.get();
|
||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||
case 1 -> CommonConfig.reach.level1.get();
|
||||
case 2 -> CommonConfig.reach.level2.get();
|
||||
case 3 -> CommonConfig.reach.level3.get();
|
||||
default -> CommonConfig.reach.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
//How far away we can detect the second and third click of build modes (distance to player)
|
||||
@Override
|
||||
public int getBuildModeReach(Player player) {
|
||||
//A bit further than placement reach, so you can build lines when looking to the side without having to move.
|
||||
return getPlacementReach(player, false) + 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBlocksPlacedAtOnce(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.maxBlocksPlacedAtOnce.creative.get();
|
||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||
case 1 -> CommonConfig.maxBlocksPlacedAtOnce.level1.get();
|
||||
case 2 -> CommonConfig.maxBlocksPlacedAtOnce.level2.get();
|
||||
case 3 -> CommonConfig.maxBlocksPlacedAtOnce.level3.get();
|
||||
default -> CommonConfig.maxBlocksPlacedAtOnce.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBlocksPerAxis(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.maxBlocksPerAxis.creative.get();
|
||||
return switch (nextPowerLevel ? getNextPowerLevel() : getPowerLevel()) {
|
||||
case 1 -> CommonConfig.maxBlocksPerAxis.level1.get();
|
||||
case 2 -> CommonConfig.maxBlocksPerAxis.level2.get();
|
||||
case 3 -> CommonConfig.maxBlocksPerAxis.level3.get();
|
||||
default -> CommonConfig.maxBlocksPerAxis.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMirrorRadius(Player player, boolean nextPowerLevel) {
|
||||
if (player.isCreative()) return CommonConfig.maxMirrorRadius.creative.get();
|
||||
return switch (getPowerLevel() + (nextPowerLevel ? 1 : 0)) {
|
||||
case 1 -> CommonConfig.maxMirrorRadius.level1.get();
|
||||
case 2 -> CommonConfig.maxMirrorRadius.level2.get();
|
||||
case 3 -> CommonConfig.maxMirrorRadius.level3.get();
|
||||
default -> CommonConfig.maxMirrorRadius.level0.get();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled(Player player) {
|
||||
return getMaxBlocksPlacedAtOnce(player, false) <= 0 || getMaxBlocksPerAxis(player, false) <= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakFar(Player player) {
|
||||
return player.getAbilities().instabuild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReplaceBlocks(Player player) {
|
||||
return player.getAbilities().instabuild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
||||
return CapabilityHandler.POWER_LEVEL_CAPABILITY.orEmpty(cap, LazyOptional.of(() -> this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("powerLevel", getPowerLevel());
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
setPowerLevel(nbt.getInt("powerLevel"));
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ 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.minecraftforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import nl.requios.effortlessbuilding.create.foundation.item.ItemHelper;
|
||||
import nl.requios.effortlessbuilding.item.AbstractRandomizerBagItem;
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package nl.requios.effortlessbuilding.create;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(Dist.CLIENT)
|
||||
//@Mod.EventBusSubscriber(Dist.CLIENT)
|
||||
public class CreateClientTest {
|
||||
|
||||
// @SubscribeEvent
|
||||
|
||||
@@ -6,14 +6,14 @@ 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.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderLevelStageEvent;
|
||||
import net.minecraftforge.client.event.ViewportEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
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;
|
||||
@@ -21,7 +21,7 @@ import nl.requios.effortlessbuilding.create.foundation.utility.AnimationTickHold
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.CameraAngleAnimationService;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.worldWrappers.WrappedClientWorld;
|
||||
|
||||
@EventBusSubscriber(Dist.CLIENT)
|
||||
@Mod.EventBusSubscriber(Dist.CLIENT)
|
||||
public class ClientEvents {
|
||||
|
||||
private static final String ITEM_PREFIX = "item." + Create.ID;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package nl.requios.effortlessbuilding.create.events;
|
||||
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
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;
|
||||
|
||||
@EventBusSubscriber
|
||||
@Mod.EventBusSubscriber
|
||||
public class CommonEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -16,7 +16,7 @@ public class CommonEvents {
|
||||
}
|
||||
|
||||
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||
// @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class ModBusEvents {
|
||||
|
||||
// @SubscribeEvent
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation;
|
||||
|
||||
import net.minecraftforge.forgespi.locating.IModFile;
|
||||
import net.minecraftforge.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);
|
||||
}
|
||||
}
|
||||
//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);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -10,8 +10,8 @@ import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.AbstractSimiWidget;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
import nl.requios.effortlessbuilding.gui.buildmodifier.ModifiersScreenList;
|
||||
@@ -114,8 +114,8 @@ public abstract class AbstractSimiScreen extends Screen {
|
||||
prepareFrame();
|
||||
|
||||
renderWindowBackground(graphics, mouseX, mouseY, partialTicks);
|
||||
renderWindow(graphics, mouseX, mouseY, partialTicks);
|
||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||
renderWindow(graphics, mouseX, mouseY, partialTicks);
|
||||
renderWindowForeground(graphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
endFrame();
|
||||
@@ -123,6 +123,11 @@ public abstract class AbstractSimiScreen extends Screen {
|
||||
ms.popPose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||
// super.renderBackground(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
boolean keyPressed = super.keyPressed(keyCode, scanCode, modifiers);
|
||||
@@ -141,7 +146,7 @@ public abstract class AbstractSimiScreen extends Screen {
|
||||
protected void prepareFrame() {}
|
||||
|
||||
protected void renderWindowBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
renderBackground(graphics);
|
||||
this.renderTransparentBackground(graphics); //Manually draw background
|
||||
}
|
||||
|
||||
protected abstract void renderWindow(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks);
|
||||
|
||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding.create.foundation.gui;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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;
|
||||
|
||||
@@ -9,8 +9,8 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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;
|
||||
|
||||
@@ -5,6 +5,8 @@ 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;
|
||||
@@ -18,10 +20,8 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.event.RenderTooltipEvent;
|
||||
import net.minecraftforge.client.extensions.IForgeGuiGraphics;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.neoforged.neoforge.client.ClientHooks;
|
||||
import net.neoforged.neoforge.client.extensions.IGuiGraphicsExtension;
|
||||
|
||||
public class RemovedGuiUtils {
|
||||
@Nonnull
|
||||
@@ -38,7 +38,7 @@ public class RemovedGuiUtils {
|
||||
public static void drawHoveringText(GuiGraphics graphics, List<? extends FormattedText> textLines, int mouseX,
|
||||
int mouseY, int screenWidth, int screenHeight, int maxTextWidth, Font font) {
|
||||
drawHoveringText(graphics, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth,
|
||||
IForgeGuiGraphics.DEFAULT_BACKGROUND_COLOR, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_START, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_END,
|
||||
IGuiGraphicsExtension.DEFAULT_BACKGROUND_COLOR, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_START, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_END,
|
||||
font);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class RemovedGuiUtils {
|
||||
List<? extends FormattedText> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight,
|
||||
int maxTextWidth, Font font) {
|
||||
drawHoveringText(stack, graphics, textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth,
|
||||
IForgeGuiGraphics.DEFAULT_BACKGROUND_COLOR, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_START, IForgeGuiGraphics.DEFAULT_BORDER_COLOR_END,
|
||||
IGuiGraphicsExtension.DEFAULT_BACKGROUND_COLOR, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_START, IGuiGraphicsExtension.DEFAULT_BORDER_COLOR_END,
|
||||
font);
|
||||
}
|
||||
|
||||
@@ -63,11 +63,11 @@ public class RemovedGuiUtils {
|
||||
if (textLines.isEmpty())
|
||||
return;
|
||||
|
||||
List<ClientTooltipComponent> list = ForgeHooksClient.gatherTooltipComponents(stack, textLines,
|
||||
List<ClientTooltipComponent> list = ClientHooks.gatherTooltipComponents(stack, textLines,
|
||||
stack.getTooltipImage(), mouseX, screenWidth, screenHeight, font);
|
||||
RenderTooltipEvent.Pre event =
|
||||
new RenderTooltipEvent.Pre(stack, graphics, mouseX, mouseY, screenWidth, screenHeight, font, list, null);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
if (NeoForge.EVENT_BUS.post(event).isCanceled())
|
||||
return;
|
||||
|
||||
PoseStack pStack = graphics.pose();
|
||||
@@ -152,7 +152,7 @@ public class RemovedGuiUtils {
|
||||
final int zLevel = 400;
|
||||
RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, graphics, tooltipX, tooltipY,
|
||||
font, backgroundColor, borderColorStart, borderColorEnd, list);
|
||||
MinecraftForge.EVENT_BUS.post(colorEvent);
|
||||
NeoForge.EVENT_BUS.post(colorEvent);
|
||||
backgroundColor = colorEvent.getBackgroundStart();
|
||||
borderColorStart = colorEvent.getBorderStart();
|
||||
borderColorEnd = colorEvent.getBorderEnd();
|
||||
|
||||
@@ -13,8 +13,8 @@ import net.minecraft.client.renderer.Rect2i;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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;
|
||||
|
||||
@@ -94,8 +94,6 @@ public abstract class AbstractSimiContainerScreen<T extends AbstractContainerMen
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
partialTicks = minecraft.getFrameTime();
|
||||
|
||||
renderBackground(graphics);
|
||||
|
||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
renderForeground(graphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.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;
|
||||
}
|
||||
|
||||
}
|
||||
//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,8 +7,8 @@ import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
|
||||
public abstract class GhostItemMenu<T> extends MenuBase<T> implements IClearableMenu {
|
||||
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
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.minecraftforge.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;
|
||||
}
|
||||
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.create.foundation.gui.container;
|
||||
public interface IClearableMenu {
|
||||
|
||||
default void sendClearPacket() {
|
||||
// PacketHandler.INSTANCE.sendToServer(new ClearMenuPacket());
|
||||
// PacketDistributor.SERVER.noArg().send(new ClearMenuPacket());
|
||||
}
|
||||
|
||||
public void clearContents();
|
||||
|
||||
@@ -6,8 +6,8 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.IInteractionChecker;
|
||||
|
||||
public abstract class MenuBase<T> extends AbstractContainerMenu {
|
||||
|
||||
@@ -30,7 +30,7 @@ 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.minecraftforge.client.RenderTypeHelper;
|
||||
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;
|
||||
@@ -268,7 +268,7 @@ public class GuiGameElement {
|
||||
ItemRenderer renderer = Minecraft.getInstance().getItemRenderer();
|
||||
BakedModel bakedModel = renderer.getModel(stack, null, null, 0);
|
||||
|
||||
renderer.textureManager.getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
|
||||
Minecraft.getInstance().textureManager.getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
|
||||
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableCull();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.gui.element;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
public interface ScreenElement {
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ package nl.requios.effortlessbuilding.create.foundation.gui.widget;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.TickableGuiEventListener;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
@@ -39,10 +37,10 @@ public abstract class AbstractSimiWidget extends AbstractWidget implements Ticka
|
||||
super(x, y, width, height, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClientTooltipPositioner createTooltipPositioner() {
|
||||
return DefaultTooltipPositioner.INSTANCE;
|
||||
}
|
||||
// @Override
|
||||
// protected ClientTooltipPositioner createTooltipPositioner() {
|
||||
// return DefaultTooltipPositioner.INSTANCE;
|
||||
// }
|
||||
|
||||
public <T extends AbstractSimiWidget> T withCallback(BiConsumer<Integer, Integer> cb) {
|
||||
this.onClick = cb;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.AllGuiTextures;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Indicator extends AbstractSimiWidget {
|
||||
|
||||
@@ -16,7 +17,7 @@ public class Indicator extends AbstractSimiWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks ) {
|
||||
public void renderWidget(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
if (!visible)
|
||||
return;
|
||||
AllGuiTextures toDraw;
|
||||
|
||||
@@ -117,21 +117,21 @@ public class ScrollInput extends AbstractSimiWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||
if (!this.visible || !this.isHovered) return false; //Added
|
||||
|
||||
if (inverted)
|
||||
delta *= -1;
|
||||
scrollX *= -1;
|
||||
|
||||
StepContext context = new StepContext();
|
||||
context.control = AllKeys.ctrlDown();
|
||||
context.shift = AllKeys.shiftDown();
|
||||
context.currentValue = state;
|
||||
context.forward = delta > 0;
|
||||
context.forward = scrollX > 0;
|
||||
|
||||
int priorState = state;
|
||||
boolean shifted = AllKeys.shiftDown();
|
||||
int step = (int) Math.signum(delta) * this.step.apply(context);
|
||||
int step = (int) Math.signum(scrollX) * this.step.apply(context);
|
||||
|
||||
state += step;
|
||||
if (shifted)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.neoforged.neoforge.items.IItemHandlerModifiable;
|
||||
|
||||
public class ItemHandlerWrapper implements IItemHandlerModifiable {
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||
|
||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Pair;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
@@ -8,8 +9,7 @@ import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.item;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.tags.ITagManager;
|
||||
|
||||
public class TagDependentIngredientItem extends Item {
|
||||
|
||||
@@ -15,8 +14,7 @@ public class TagDependentIngredientItem extends Item {
|
||||
}
|
||||
|
||||
public boolean shouldHide() {
|
||||
ITagManager<Item> tagManager = ForgeRegistries.ITEMS.tags();
|
||||
return !tagManager.isKnownTagName(tag) || tagManager.getTag(tag).isEmpty();
|
||||
return BuiltInRegistries.ITEM.getTag(tag).isEmpty() || BuiltInRegistries.ITEM.getTag(tag).get().size() == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package nl.requios.effortlessbuilding.create.foundation.item.render;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraftforge.client.model.BakedModelWrapper;
|
||||
import net.neoforged.neoforge.client.model.BakedModelWrapper;
|
||||
|
||||
public class CustomRenderedItemModel extends BakedModelWrapper<BakedModel> {
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
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;
|
||||
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
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.minecraftforge.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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//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 +1,12 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.networking;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
public abstract class SimplePacketBase {
|
||||
|
||||
public abstract void write(FriendlyByteBuf buffer);
|
||||
|
||||
public abstract boolean handle(Context context);
|
||||
|
||||
}
|
||||
//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);
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.renderer.ChunkBufferBuilderPack;
|
||||
import net.minecraft.client.renderer.SectionBufferBuilderPack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
@@ -59,31 +59,28 @@ public class SuperRenderTypeBuffer implements MultiBufferSource {
|
||||
private static class SuperRenderTypeBufferPhase {
|
||||
|
||||
// Visible clones from RenderBuffers
|
||||
private final ChunkBufferBuilderPack fixedBufferPack = new ChunkBufferBuilderPack();
|
||||
private final SectionBufferBuilderPack fixedBufferPack = new SectionBufferBuilderPack();
|
||||
private final SortedMap<RenderType, BufferBuilder> fixedBuffers = Util.make(new Object2ObjectLinkedOpenHashMap<>(), map -> {
|
||||
map.put(Sheets.solidBlockSheet(), fixedBufferPack.builder(RenderType.solid()));
|
||||
map.put(Sheets.cutoutBlockSheet(), fixedBufferPack.builder(RenderType.cutout()));
|
||||
map.put(Sheets.bannerSheet(), fixedBufferPack.builder(RenderType.cutoutMipped()));
|
||||
map.put(Sheets.translucentCullBlockSheet(), fixedBufferPack.builder(RenderType.translucent()));
|
||||
put(map, Sheets.shieldSheet());
|
||||
put(map, Sheets.bedSheet());
|
||||
put(map, Sheets.shulkerBoxSheet());
|
||||
put(map, Sheets.signSheet());
|
||||
put(map, Sheets.chestSheet());
|
||||
put(map, RenderType.translucentNoCrumbling());
|
||||
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());
|
||||
put(map, RenderTypes.getOutlineSolid());
|
||||
ModelBakery.DESTROY_TYPES.forEach((p_173062_) -> {
|
||||
put(map, p_173062_);
|
||||
});
|
||||
});
|
||||
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) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.neoforged.neoforge.event.EventHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -20,7 +20,7 @@ public abstract class AbstractBlockBreakQueue {
|
||||
BlockHelper.destroyBlockAs(world, pos, playerEntity, toDamage, effectChance,
|
||||
stack -> drop.accept(pos, stack));
|
||||
if (toDamage.isEmpty() && !usedTool.isEmpty())
|
||||
ForgeEventFactory.onPlayerDestroyItem(playerEntity, usedTool, InteractionHand.MAIN_HAND);
|
||||
EventHooks.onPlayerDestroyItem(playerEntity, usedTool, InteractionHand.MAIN_HAND);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ 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.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.level.BlockEvent;
|
||||
import net.neoforged.neoforge.common.IPlantable;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
@@ -159,7 +159,7 @@ public class BlockHelper {
|
||||
|
||||
if (player != null) {
|
||||
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
NeoForge.EVENT_BUS.post(event);
|
||||
if (event.isCanceled())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -1,101 +1,101 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CreateRegistry<K, V> {
|
||||
private static final List<CreateRegistry<?, ?>> ALL = new ArrayList<>();
|
||||
|
||||
protected final IForgeRegistry<K> objectRegistry;
|
||||
protected final Map<ResourceLocation, V> locationMap = new HashMap<>();
|
||||
protected final Map<K, V> objectMap = new IdentityHashMap<>();
|
||||
protected boolean unwrapped = false;
|
||||
|
||||
public CreateRegistry(IForgeRegistry<K> objectRegistry) {
|
||||
this.objectRegistry = objectRegistry;
|
||||
ALL.add(this);
|
||||
}
|
||||
|
||||
public void register(ResourceLocation location, V value) {
|
||||
if (!unwrapped) {
|
||||
locationMap.put(location, value);
|
||||
} else {
|
||||
K object = objectRegistry.getValue(location);
|
||||
if (object != null) {
|
||||
objectMap.put(object, value);
|
||||
} else {
|
||||
Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry after unwrapping!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void register(K object, V value) {
|
||||
if (unwrapped) {
|
||||
objectMap.put(object, value);
|
||||
} else {
|
||||
ResourceLocation location = objectRegistry.getKey(object);
|
||||
if (location != null) {
|
||||
locationMap.put(location, value);
|
||||
} else {
|
||||
Create.LOGGER.warn("Could not get location of object '" + object + "' in CreateRegistry before unwrapping!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public V get(ResourceLocation location) {
|
||||
if (!unwrapped) {
|
||||
return locationMap.get(location);
|
||||
} else {
|
||||
K object = objectRegistry.getValue(location);
|
||||
if (object != null) {
|
||||
return objectMap.get(object);
|
||||
} else {
|
||||
Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry after unwrapping!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public V get(K object) {
|
||||
if (unwrapped) {
|
||||
return objectMap.get(object);
|
||||
} else {
|
||||
ResourceLocation location = objectRegistry.getKey(object);
|
||||
if (location != null) {
|
||||
return locationMap.get(location);
|
||||
} else {
|
||||
Create.LOGGER.warn("Could not get location of object '" + object + "' in CreateRegistry before unwrapping!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUnwrapped() {
|
||||
return unwrapped;
|
||||
}
|
||||
|
||||
protected void unwrap() {
|
||||
for (Map.Entry<ResourceLocation, V> entry : locationMap.entrySet()) {
|
||||
ResourceLocation location = entry.getKey();
|
||||
K object = objectRegistry.getValue(location);
|
||||
if (object != null) {
|
||||
objectMap.put(object, entry.getValue());
|
||||
} else {
|
||||
Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry during unwrapping!");
|
||||
}
|
||||
}
|
||||
unwrapped = true;
|
||||
}
|
||||
|
||||
public static void unwrapAll() {
|
||||
for (CreateRegistry<?, ?> registry : ALL) {
|
||||
registry.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
//package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
//
|
||||
//import net.minecraft.resources.ResourceLocation;
|
||||
//import net.neoforged.neoforge.registries.IForgeRegistry;
|
||||
//import nl.requios.effortlessbuilding.create.Create;
|
||||
//import org.jetbrains.annotations.Nullable;
|
||||
//
|
||||
//import java.util.*;
|
||||
//
|
||||
//public class CreateRegistry<K, V> {
|
||||
// private static final List<CreateRegistry<?, ?>> ALL = new ArrayList<>();
|
||||
//
|
||||
// protected final IForgeRegistry<K> objectRegistry;
|
||||
// protected final Map<ResourceLocation, V> locationMap = new HashMap<>();
|
||||
// protected final Map<K, V> objectMap = new IdentityHashMap<>();
|
||||
// protected boolean unwrapped = false;
|
||||
//
|
||||
// public CreateRegistry(IForgeRegistry<K> objectRegistry) {
|
||||
// this.objectRegistry = objectRegistry;
|
||||
// ALL.add(this);
|
||||
// }
|
||||
//
|
||||
// public void register(ResourceLocation location, V value) {
|
||||
// if (!unwrapped) {
|
||||
// locationMap.put(location, value);
|
||||
// } else {
|
||||
// K object = objectRegistry.getValue(location);
|
||||
// if (object != null) {
|
||||
// objectMap.put(object, value);
|
||||
// } else {
|
||||
// Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry after unwrapping!");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void register(K object, V value) {
|
||||
// if (unwrapped) {
|
||||
// objectMap.put(object, value);
|
||||
// } else {
|
||||
// ResourceLocation location = objectRegistry.getKey(object);
|
||||
// if (location != null) {
|
||||
// locationMap.put(location, value);
|
||||
// } else {
|
||||
// Create.LOGGER.warn("Could not get location of object '" + object + "' in CreateRegistry before unwrapping!");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// public V get(ResourceLocation location) {
|
||||
// if (!unwrapped) {
|
||||
// return locationMap.get(location);
|
||||
// } else {
|
||||
// K object = objectRegistry.getValue(location);
|
||||
// if (object != null) {
|
||||
// return objectMap.get(object);
|
||||
// } else {
|
||||
// Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry after unwrapping!");
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// public V get(K object) {
|
||||
// if (unwrapped) {
|
||||
// return objectMap.get(object);
|
||||
// } else {
|
||||
// ResourceLocation location = objectRegistry.getKey(object);
|
||||
// if (location != null) {
|
||||
// return locationMap.get(location);
|
||||
// } else {
|
||||
// Create.LOGGER.warn("Could not get location of object '" + object + "' in CreateRegistry before unwrapping!");
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public boolean isUnwrapped() {
|
||||
// return unwrapped;
|
||||
// }
|
||||
//
|
||||
// protected void unwrap() {
|
||||
// for (Map.Entry<ResourceLocation, V> entry : locationMap.entrySet()) {
|
||||
// ResourceLocation location = entry.getKey();
|
||||
// K object = objectRegistry.getValue(location);
|
||||
// if (object != null) {
|
||||
// objectMap.put(object, entry.getValue());
|
||||
// } else {
|
||||
// Create.LOGGER.warn("Could not get object for location '" + location + "' in CreateRegistry during unwrapping!");
|
||||
// }
|
||||
// }
|
||||
// unwrapped = true;
|
||||
// }
|
||||
//
|
||||
// public static void unwrapAll() {
|
||||
// for (CreateRegistry<?, ?> registry : ALL) {
|
||||
// registry.unwrap();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.fml.util.thread.EffectiveSide;
|
||||
import nl.requios.effortlessbuilding.create.Create;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.util.thread.EffectiveSide;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
/** Deprecated so simi doensn't forget to remove debug calls **/
|
||||
@OnlyIn(value = Dist.CLIENT)
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.neoforged.neoforge.fluids.FluidStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -57,9 +57,9 @@ public class NBTHelper {
|
||||
listNBT.forEach(inbt -> consumer.accept((CompoundTag) inbt));
|
||||
}
|
||||
|
||||
public static ListTag writeItemList(Iterable<ItemStack> stacks) {
|
||||
return writeCompoundList(stacks, ItemStack::serializeNBT);
|
||||
}
|
||||
// public static ListTag writeItemList(Iterable<ItemStack> stacks) {
|
||||
// return writeCompoundList(stacks, ItemStack::serializeNBT);
|
||||
// }
|
||||
|
||||
public static List<ItemStack> readItemList(ListTag stacks) {
|
||||
return readCompoundList(stacks, ItemStack::of);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.particles.ParticleType;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
@@ -9,14 +11,12 @@ import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class RegisteredObjects {
|
||||
// registry argument for easier porting to 1.19
|
||||
@NotNull
|
||||
public static <V> ResourceLocation getKeyOrThrow(IForgeRegistry<V> registry, V value) {
|
||||
public static <V> ResourceLocation getKeyOrThrow(Registry<V> registry, V value) {
|
||||
ResourceLocation key = registry.getKey(value);
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("Could not get key for value " + value + "!");
|
||||
@@ -26,41 +26,41 @@ public final class RegisteredObjects {
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(Block value) {
|
||||
return getKeyOrThrow(ForgeRegistries.BLOCKS, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.BLOCK, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(Item value) {
|
||||
return getKeyOrThrow(ForgeRegistries.ITEMS, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.ITEM, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(Fluid value) {
|
||||
return getKeyOrThrow(ForgeRegistries.FLUIDS, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.FLUID, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(EntityType<?> value) {
|
||||
return getKeyOrThrow(ForgeRegistries.ENTITY_TYPES, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.ENTITY_TYPE, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(BlockEntityType<?> value) {
|
||||
return getKeyOrThrow(ForgeRegistries.BLOCK_ENTITY_TYPES, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.BLOCK_ENTITY_TYPE, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(Potion value) {
|
||||
return getKeyOrThrow(ForgeRegistries.POTIONS, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.POTION, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(ParticleType<?> value) {
|
||||
return getKeyOrThrow(ForgeRegistries.PARTICLE_TYPES, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.PARTICLE_TYPE, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResourceLocation getKeyOrThrow(RecipeSerializer<?> value) {
|
||||
return getKeyOrThrow(ForgeRegistries.RECIPE_SERIALIZERS, value);
|
||||
return getKeyOrThrow(BuiltInRegistries.RECIPE_SERIALIZER, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package nl.requios.effortlessbuilding.create.foundation.utility;
|
||||
|
||||
import net.minecraftforge.common.util.NonNullSupplier;
|
||||
import net.neoforged.neoforge.common.util.NonNullSupplier;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
import net.neoforged.neoforge.client.model.data.ModelData;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -15,8 +15,8 @@ import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -3,6 +3,7 @@ package nl.requios.effortlessbuilding.create.foundation.utility.worldWrappers;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.TickRateManager;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
@@ -134,6 +135,11 @@ public class WrappedWorld extends Level {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateManager tickRateManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapItemSavedData getMapData(String mapName) {
|
||||
return null;
|
||||
|
||||
@@ -9,9 +9,9 @@ import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.item.DiamondRandomizerBagItem;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -26,7 +26,6 @@ public class DiamondRandomizerBagScreen extends AbstractContainerScreen<DiamondR
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
renderBackground(guiGraphics);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
this.renderTooltip(guiGraphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.item.GoldenRandomizerBagItem;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -26,7 +26,7 @@ public class GoldenRandomizerBagScreen extends AbstractContainerScreen<GoldenRan
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
renderBackground(guiGraphics);
|
||||
// renderBackground(guiGraphics);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
this.renderTooltip(guiGraphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.item.RandomizerBagItem;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -26,7 +26,7 @@ public class RandomizerBagScreen extends AbstractContainerScreen<RandomizerBagCo
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
renderBackground(guiGraphics);
|
||||
// renderBackground(guiGraphics);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
this.renderTooltip(guiGraphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
package nl.requios.effortlessbuilding.gui.buildmode;
|
||||
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.gui.widget.ExtendedButton;
|
||||
import net.minecraftforge.client.gui.widget.ForgeSlider;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.client.gui.widget.ExtendedButton;
|
||||
import net.neoforged.neoforge.client.gui.widget.ExtendedSlider;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -54,7 +49,7 @@ public class PlayerSettingsGui extends Screen {
|
||||
addRenderableOnly(shaderTypeButton);
|
||||
|
||||
yy += 50;
|
||||
ForgeSlider slider = new ForgeSlider(right - 200, yy, 200, 20, Component.empty(), Component.empty(), 0.5, 2.0, 1.0, true);
|
||||
ExtendedSlider slider = new ExtendedSlider(right - 200, yy, 200, 20, Component.empty(), Component.empty(), 0.5, 2.0, 1.0, true);
|
||||
addRenderableOnly(slider);
|
||||
|
||||
closeButton = new ExtendedButton(left + 50, bottom - 20, 180, 20, Component.literal("Done"), (button) -> this.minecraft.player.closeContainer());
|
||||
@@ -68,7 +63,7 @@ public class PlayerSettingsGui extends Screen {
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(guiGraphics);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
int yy = top;
|
||||
guiGraphics.drawString(font, "Shader type", left, yy + 5, 0xFFFFFF, false);
|
||||
@@ -76,8 +71,6 @@ public class PlayerSettingsGui extends Screen {
|
||||
yy += 50;
|
||||
guiGraphics.drawString(font, "Shader speed", left, yy + 5, 0xFFFFFF, false);
|
||||
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
|
||||
if (showShaderList)
|
||||
this.shaderTypeList.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
@@ -118,8 +111,8 @@ public class PlayerSettingsGui extends Screen {
|
||||
class ShaderTypeList extends ObjectSelectionList<PlayerSettingsGui.ShaderTypeList.ShaderTypeEntry> {
|
||||
|
||||
public ShaderTypeList(Minecraft mcIn) {
|
||||
super(mcIn, 180, 140, top + 20, top + 100, 18);
|
||||
this.setLeftPos(right - width);
|
||||
super(mcIn, 180, 140, top + 20, /*top + 100,*/ 18);
|
||||
this.setX(right - width);
|
||||
|
||||
for (int i = 0; i < 40; i++) {
|
||||
|
||||
@@ -151,33 +144,33 @@ public class PlayerSettingsGui extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int pButton) {
|
||||
if (!showShaderList) return false;
|
||||
return super.mouseClicked(p_mouseClicked_1_, p_mouseClicked_3_, p_mouseClicked_5_);
|
||||
return super.mouseClicked(mouseX, mouseY, pButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double p_mouseReleased_1_, double p_mouseReleased_3_, int p_mouseReleased_5_) {
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
if (!showShaderList) return false;
|
||||
return super.mouseReleased(p_mouseReleased_1_, p_mouseReleased_3_, p_mouseReleased_5_);
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double p_mouseDragged_1_, double p_mouseDragged_3_, int p_mouseDragged_5_, double p_mouseDragged_6_, double p_mouseDragged_8_) {
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) {
|
||||
if (!showShaderList) return false;
|
||||
return super.mouseDragged(p_mouseDragged_1_, p_mouseDragged_3_, p_mouseDragged_5_, p_mouseDragged_6_, p_mouseDragged_8_);
|
||||
return super.mouseDragged(mouseX, mouseY, button, dragX, dragY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double p_mouseScrolled_1_, double p_mouseScrolled_3_, double p_mouseScrolled_5_) {
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||
if (!showShaderList) return false;
|
||||
return super.mouseScrolled(p_mouseScrolled_1_, p_mouseScrolled_3_, p_mouseScrolled_5_);
|
||||
return super.mouseScrolled(mouseX, mouseY, scrollX, scrollY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(double p_isMouseOver_1_, double p_isMouseOver_3_) {
|
||||
public boolean isMouseOver(double mouseX, double mouseY) {
|
||||
if (!showShaderList) return false;
|
||||
return super.isMouseOver(p_isMouseOver_1_, p_isMouseOver_3_);
|
||||
return super.isMouseOver(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public boolean isFocused() {
|
||||
@@ -190,90 +183,90 @@ public class PlayerSettingsGui extends Screen {
|
||||
}
|
||||
|
||||
//From AbstractSelectionList, disabled parts
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int p_render_1_, int p_render_2_, float p_render_3_) {
|
||||
this.renderBackground(guiGraphics);
|
||||
int i = this.getScrollbarPosition();
|
||||
int j = i + 6;
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder bufferbuilder = tessellator.getBuilder();
|
||||
// this.minecraft.getTextureManager().bindTexture(AbstractGui.BACKGROUND_LOCATION);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
float f = 32.0F;
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
bufferbuilder.vertex(this.x0, this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
bufferbuilder.vertex(this.x1, this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
bufferbuilder.vertex(this.x1, this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
bufferbuilder.vertex(this.x0, this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
tessellator.end();
|
||||
int k = this.getRowLeft();
|
||||
int l = this.y0 + 4 - (int) this.getScrollAmount();
|
||||
if (this.renderHeader) {
|
||||
this.renderHeader(guiGraphics, k, l);
|
||||
}
|
||||
// @Override //TODO: Check if this is still needed!
|
||||
// public void render(GuiGraphics guiGraphics, int p_render_1_, int p_render_2_, float p_render_3_) {
|
||||
// this.renderBackground(guiGraphics);
|
||||
// int i = this.getScrollbarPosition();
|
||||
// int j = i + 6;
|
||||
// Tesselator tessellator = Tesselator.getInstance();
|
||||
// BufferBuilder bufferbuilder = tessellator.getBuilder();
|
||||
//// this.minecraft.getTextureManager().bindTexture(AbstractGui.BACKGROUND_LOCATION);
|
||||
// RenderSystem.enableBlend();
|
||||
// RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
|
||||
// RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
// float f = 32.0F;
|
||||
// bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
// bufferbuilder.vertex(this.x0, this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
// bufferbuilder.vertex(this.x1, this.y1, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
// bufferbuilder.vertex(this.x1, this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
// bufferbuilder.vertex(this.x0, this.y0, 0.0D).color(20, 20, 20, 180).endVertex();
|
||||
// tessellator.end();
|
||||
// int k = this.getRowLeft();
|
||||
// int l = this.y0 + 4 - (int) this.getScrollAmount();
|
||||
// if (this.renderHeader) {
|
||||
// this.renderHeader(guiGraphics, k, l);
|
||||
// }
|
||||
//
|
||||
// this.renderList(guiGraphics, p_render_1_, p_render_2_, p_render_3_);
|
||||
// RenderSystem.disableDepthTest();
|
||||
//// this.renderHoleBackground(0, this.y0, 255, 255);
|
||||
//// this.renderHoleBackground(this.y1, this.height, 255, 255);
|
||||
// RenderSystem.enableBlend();
|
||||
// RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
|
||||
//// RenderSystem.disableTexture();
|
||||
// RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
//// int i1 = 4;
|
||||
//// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
//// bufferbuilder.pos((double)this.x0, (double)(this.y0 + 4), 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 0).endVertex();
|
||||
//// bufferbuilder.pos((double)this.x1, (double)(this.y0 + 4), 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 0).endVertex();
|
||||
//// bufferbuilder.pos((double)this.x1, (double)this.y0, 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
//// bufferbuilder.pos((double)this.x0, (double)this.y0, 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
//// tessellator.draw();
|
||||
//// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
//// bufferbuilder.pos((double)this.x0, (double)this.y1, 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
//// bufferbuilder.pos((double)this.x1, (double)this.y1, 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
//// bufferbuilder.pos((double)this.x1, (double)(this.y1 - 4), 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 0).endVertex();
|
||||
//// bufferbuilder.pos((double)this.x0, (double)(this.y1 - 4), 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 0).endVertex();
|
||||
//// tessellator.draw();
|
||||
//
|
||||
// //SCROLLBAR
|
||||
// int j1 = this.getMaxScroll();
|
||||
// if (j1 > 0) {
|
||||
// int k1 = (int) ((float) ((this.y1 - this.y0) * (this.y1 - this.y0)) / (float) this.getMaxPosition());
|
||||
// k1 = Mth.clamp(k1, 32, this.y1 - this.y0 - 8);
|
||||
// int l1 = (int) this.getScrollAmount() * (this.y1 - this.y0 - k1) / j1 + this.y0;
|
||||
// if (l1 < this.y0) {
|
||||
// l1 = this.y0;
|
||||
// }
|
||||
//
|
||||
// bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
// bufferbuilder.vertex(i, this.y1, 0.0D).uv(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
// bufferbuilder.vertex(j, this.y1, 0.0D).uv(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
// bufferbuilder.vertex(j, this.y0, 0.0D).uv(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
// bufferbuilder.vertex(i, this.y0, 0.0D).uv(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
// tessellator.end();
|
||||
// bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
// bufferbuilder.vertex(i, l1 + k1, 0.0D).uv(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
|
||||
// bufferbuilder.vertex(j, l1 + k1, 0.0D).uv(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
|
||||
// bufferbuilder.vertex(j, l1, 0.0D).uv(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
|
||||
// bufferbuilder.vertex(i, l1, 0.0D).uv(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
|
||||
// tessellator.end();
|
||||
// bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
// bufferbuilder.vertex(i, l1 + k1 - 1, 0.0D).uv(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
|
||||
// bufferbuilder.vertex(j - 1, l1 + k1 - 1, 0.0D).uv(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
|
||||
// bufferbuilder.vertex(j - 1, l1, 0.0D).uv(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
|
||||
// bufferbuilder.vertex(i, l1, 0.0D).uv(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
|
||||
// tessellator.end();
|
||||
// }
|
||||
//
|
||||
//// this.renderDecorations(p_render_1_, p_render_2_);
|
||||
//// RenderSystem.enableTexture();
|
||||
// RenderSystem.disableBlend();
|
||||
// }
|
||||
|
||||
this.renderList(guiGraphics, p_render_1_, p_render_2_, p_render_3_);
|
||||
RenderSystem.disableDepthTest();
|
||||
// this.renderHoleBackground(0, this.y0, 255, 255);
|
||||
// this.renderHoleBackground(this.y1, this.height, 255, 255);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
|
||||
// RenderSystem.disableTexture();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
// int i1 = 4;
|
||||
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
// bufferbuilder.pos((double)this.x0, (double)(this.y0 + 4), 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 0).endVertex();
|
||||
// bufferbuilder.pos((double)this.x1, (double)(this.y0 + 4), 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 0).endVertex();
|
||||
// bufferbuilder.pos((double)this.x1, (double)this.y0, 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
// bufferbuilder.pos((double)this.x0, (double)this.y0, 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
// tessellator.draw();
|
||||
// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
// bufferbuilder.pos((double)this.x0, (double)this.y1, 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
// bufferbuilder.pos((double)this.x1, (double)this.y1, 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
// bufferbuilder.pos((double)this.x1, (double)(this.y1 - 4), 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 0).endVertex();
|
||||
// bufferbuilder.pos((double)this.x0, (double)(this.y1 - 4), 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 0).endVertex();
|
||||
// tessellator.draw();
|
||||
|
||||
//SCROLLBAR
|
||||
int j1 = this.getMaxScroll();
|
||||
if (j1 > 0) {
|
||||
int k1 = (int) ((float) ((this.y1 - this.y0) * (this.y1 - this.y0)) / (float) this.getMaxPosition());
|
||||
k1 = Mth.clamp(k1, 32, this.y1 - this.y0 - 8);
|
||||
int l1 = (int) this.getScrollAmount() * (this.y1 - this.y0 - k1) / j1 + this.y0;
|
||||
if (l1 < this.y0) {
|
||||
l1 = this.y0;
|
||||
}
|
||||
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
bufferbuilder.vertex(i, this.y1, 0.0D).uv(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
bufferbuilder.vertex(j, this.y1, 0.0D).uv(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
|
||||
bufferbuilder.vertex(j, this.y0, 0.0D).uv(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
bufferbuilder.vertex(i, this.y0, 0.0D).uv(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
|
||||
tessellator.end();
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
bufferbuilder.vertex(i, l1 + k1, 0.0D).uv(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
|
||||
bufferbuilder.vertex(j, l1 + k1, 0.0D).uv(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
|
||||
bufferbuilder.vertex(j, l1, 0.0D).uv(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
|
||||
bufferbuilder.vertex(i, l1, 0.0D).uv(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
|
||||
tessellator.end();
|
||||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
bufferbuilder.vertex(i, l1 + k1 - 1, 0.0D).uv(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
|
||||
bufferbuilder.vertex(j - 1, l1 + k1 - 1, 0.0D).uv(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
|
||||
bufferbuilder.vertex(j - 1, l1, 0.0D).uv(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
|
||||
bufferbuilder.vertex(i, l1, 0.0D).uv(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
|
||||
tessellator.end();
|
||||
}
|
||||
|
||||
// this.renderDecorations(p_render_1_, p_render_2_);
|
||||
// RenderSystem.enableTexture();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public int getMaxScroll() {
|
||||
return Math.max(0, this.getMaxPosition() - (this.y1 - this.y0 - 4));
|
||||
}
|
||||
// public int getMaxScroll() {
|
||||
// return Math.max(0, this.getMaxPosition() - (this.y1 - this.y0 - 4));
|
||||
// }
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ShaderTypeEntry extends ObjectSelectionList.Entry<ShaderTypeEntry> {
|
||||
@@ -285,8 +278,8 @@ public class PlayerSettingsGui extends Screen {
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int itemIndex, int rowTop, int rowLeft, int rowWidth, int rowHeight, int mouseX, int mouseY, boolean hovered, float partialTicks) {
|
||||
if (rowTop + 10 > ShaderTypeList.this.y0 && rowTop + rowHeight - 5 < ShaderTypeList.this.y1)
|
||||
guiGraphics.drawString(font, shaderType.name, ShaderTypeList.this.x0 + 8, rowTop + 4, 0xFFFFFF, false);
|
||||
if (rowTop + 10 > ShaderTypeList.this.getY() && rowTop + rowHeight - 5 < (ShaderTypeList.this.getY() + ShaderTypeList.this.getHeight()))
|
||||
guiGraphics.drawString(font, shaderType.name, ShaderTypeList.this.getX() + 8, rowTop + 4, 0xFFFFFF, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,7 @@ import nl.requios.effortlessbuilding.buildmode.BuildModeEnum;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions.ActionEnum;
|
||||
import nl.requios.effortlessbuilding.buildmode.ModeOptions.OptionEnum;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.create.foundation.item.ItemDescription;
|
||||
import nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Color;
|
||||
@@ -155,7 +155,7 @@ public class RadialMenu extends Screen {
|
||||
|
||||
|
||||
//Add actions
|
||||
boolean canReplace = CapabilityHandler.canReplaceBlocks(minecraft.player);
|
||||
boolean canReplace = AttachmentHandler.canReplaceBlocks(minecraft.player);
|
||||
|
||||
// buttons.add(new MenuButton(ActionEnum.OPEN_PLAYER_SETTINGS, -buttonDistance - 65, -13, Direction.UP));
|
||||
if (canReplace) {
|
||||
@@ -337,7 +337,7 @@ public class RadialMenu extends Screen {
|
||||
guiGraphics.drawString(font, credits, width - font.width(credits) - 4, height - 10, watermarkTextColor);
|
||||
|
||||
//Draw power level info
|
||||
String powerLevelValue = minecraft.player.isCreative() ? "Creative" : String.valueOf(CapabilityHandler.getPowerLevel(minecraft.player));
|
||||
String powerLevelValue = minecraft.player.isCreative() ? "Creative" : String.valueOf(AttachmentHandler.getPowerLevel(minecraft.player));
|
||||
String powerLevelText = I18n.get("key.effortlessbuilding.power_level") + ": " + powerLevelValue;
|
||||
guiGraphics.drawString(font, powerLevelText, width - font.width(powerLevelText) - 4, height - 22, minecraft.player.isCreative() ? watermarkTextColor : ChatFormatting.DARK_PURPLE.getColor());
|
||||
|
||||
@@ -345,19 +345,19 @@ public class RadialMenu extends Screen {
|
||||
if (mouseX >= width - font.width(powerLevelText) - 14 && mouseX <= width && mouseY >= height - 24 && mouseY <= height) {
|
||||
var tooltip = new ArrayList<Component>();
|
||||
tooltip.add(Components.literal(powerLevelText).withStyle(ChatFormatting.DARK_PURPLE));
|
||||
int placementReach = CapabilityHandler.getPlacementReach(minecraft.player, false);
|
||||
int placementReach = AttachmentHandler.getPlacementReach(minecraft.player, false);
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.placement_reach").withStyle(ChatFormatting.GRAY).append(": " + (placementReach == 0 ? "vanilla" : placementReach + " blocks")));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPerAxis(minecraft.player, false)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPlacedAtOnce(minecraft.player, false)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxMirrorRadius(minecraft.player, false) + " blocks"));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + AttachmentHandler.getMaxBlocksPerAxis(minecraft.player, false)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + AttachmentHandler.getMaxBlocksPlacedAtOnce(minecraft.player, false)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + AttachmentHandler.getMaxMirrorRadius(minecraft.player, false) + " blocks"));
|
||||
|
||||
if (CapabilityHandler.canIncreasePowerLevel(minecraft.player) && !minecraft.player.isCreative()) {
|
||||
if (AttachmentHandler.canIncreasePowerLevel(minecraft.player) && !minecraft.player.isCreative()) {
|
||||
tooltip.add(Components.literal(""));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.next_power_level").withStyle(ChatFormatting.DARK_AQUA).append(": " + CapabilityHandler.getNextPowerLevel(minecraft.player)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.placement_reach").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getPlacementReach(minecraft.player, true) + " blocks"));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPerAxis(minecraft.player, true)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxBlocksPlacedAtOnce(minecraft.player, true)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + CapabilityHandler.getMaxMirrorRadius(minecraft.player, true) + " blocks"));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.next_power_level").withStyle(ChatFormatting.DARK_AQUA).append(": " + AttachmentHandler.getNextPowerLevel(minecraft.player)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.placement_reach").withStyle(ChatFormatting.GRAY).append(": " + AttachmentHandler.getPlacementReach(minecraft.player, true) + " blocks"));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_per_axis").withStyle(ChatFormatting.GRAY).append(": " + AttachmentHandler.getMaxBlocksPerAxis(minecraft.player, true)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_blocks_placed_at_once").withStyle(ChatFormatting.GRAY).append(": " + AttachmentHandler.getMaxBlocksPlacedAtOnce(minecraft.player, true)));
|
||||
tooltip.add(Components.translatable("key.effortlessbuilding.max_mirror_radius").withStyle(ChatFormatting.GRAY).append(": " + AttachmentHandler.getMaxMirrorRadius(minecraft.player, true) + " blocks"));
|
||||
tooltip.add(Components.literal(""));
|
||||
tooltip.addAll(TooltipHelper.cutTextComponent(Components.translatable("key.effortlessbuilding.next_power_level_how"), ChatFormatting.GRAY, ChatFormatting.WHITE));
|
||||
}
|
||||
@@ -485,7 +485,7 @@ public class RadialMenu extends Screen {
|
||||
public static void playRadialMenuSound() {
|
||||
final float volume = 0.1f;
|
||||
if (volume >= 0.0001f) {
|
||||
SimpleSoundInstance sound = new SimpleSoundInstance(SoundEvents.UI_BUTTON_CLICK.get(), SoundSource.MASTER, volume,
|
||||
SimpleSoundInstance sound = new SimpleSoundInstance(SoundEvents.UI_BUTTON_CLICK.value(), SoundSource.MASTER, volume,
|
||||
1.0f, RandomSource.create(), Minecraft.getInstance().player.blockPosition());
|
||||
Minecraft.getInstance().getSoundManager().play(sound);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.AllGuiTextures;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
||||
import nl.requios.effortlessbuilding.gui.elements.LabeledScrollInput;
|
||||
import nl.requios.effortlessbuilding.utilities.MathHelper;
|
||||
@@ -59,8 +59,8 @@ public class ArrayEntry extends BaseModifierEntry<Array> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
super.render(guiGraphics, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float partialTicks) {
|
||||
super.render(guiGraphics, index, y, x, width, height, mouseX, mouseY, hovering, partialTicks);
|
||||
|
||||
//draw offset inputs
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -85,7 +85,7 @@ public class ArrayEntry extends BaseModifierEntry<Array> {
|
||||
super.onValueChanged();
|
||||
|
||||
int currentReach = Math.max(-1, getArrayReach());
|
||||
int maxReach = CapabilityHandler.getMaxBlocksPerAxis(Minecraft.getInstance().player, false);
|
||||
int maxReach = AttachmentHandler.getMaxBlocksPerAxis(Minecraft.getInstance().player, false);
|
||||
ChatFormatting reachColor = isCurrentReachValid(currentReach, maxReach) ? ChatFormatting.GRAY : ChatFormatting.RED;
|
||||
var reachText = "" + reachColor + currentReach + ChatFormatting.GRAY + "/" + ChatFormatting.GRAY + maxReach;
|
||||
reachLabel.text = Component.literal(reachText);
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class BaseModifierEntry<T extends BaseModifier> extends Modifier
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float partialTicks) {
|
||||
|
||||
left = x + width / 2 - BACKGROUND_WIDTH / 2;
|
||||
right = x + width / 2 + BACKGROUND_WIDTH / 2;
|
||||
|
||||
@@ -4,13 +4,13 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.AllGuiTextures;
|
||||
import nl.requios.effortlessbuilding.AllIcons;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Mirror;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.IconButton;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
@@ -101,7 +101,7 @@ public class MirrorEntry extends BaseModifierEntry<Mirror> {
|
||||
|
||||
//Radius
|
||||
radiusInput = new LabeledScrollInput(0, 0, 27, 18)
|
||||
.withRange(0, CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false))
|
||||
.withRange(0, AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false))
|
||||
.titled(Minecraft.getInstance().player.isCreative() ?
|
||||
Component.literal("Radius") :
|
||||
Component.literal("Radius. Use Reach Upgrade items to increase maximum."))
|
||||
@@ -135,8 +135,8 @@ public class MirrorEntry extends BaseModifierEntry<Mirror> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
super.render(guiGraphics, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float partialTicks) {
|
||||
super.render(guiGraphics, index, y, x, width, height, mouseX, mouseY, hovering, partialTicks);
|
||||
|
||||
//draw position inputs
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
@@ -3,8 +3,8 @@ package nl.requios.effortlessbuilding.gui.buildmodifier;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.ClientEvents;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.Array;
|
||||
@@ -41,8 +41,8 @@ public class ModifiersScreen extends AbstractSimiScreen {
|
||||
int listL = this.width / 2 - listWidth / 2;
|
||||
int listR = this.width / 2 + listWidth / 2;
|
||||
|
||||
list = new ModifiersScreenList(minecraft, listWidth, height - 80, 45, height - 45, 68);
|
||||
list.setLeftPos(this.width / 2 - list.getWidth() / 2);
|
||||
list = new ModifiersScreenList(minecraft, listWidth, height - 80, 45, 68);
|
||||
list.setX(this.width / 2 - list.getWidth() / 2);
|
||||
|
||||
addRenderableWidget(list);
|
||||
|
||||
|
||||
@@ -21,32 +21,26 @@ import java.util.Objects;
|
||||
//Based on Create's ConfigScreenList
|
||||
public class ModifiersScreenList extends ObjectSelectionList<ModifiersScreenList.Entry> implements TickableGuiEventListener {
|
||||
|
||||
public ModifiersScreenList(Minecraft mc, int width, int height, int y0, int y1, int itemHeight) {
|
||||
super(mc, width, height, y0, y1, itemHeight);
|
||||
public ModifiersScreenList(Minecraft mc, int width, int height, int y1, int itemHeight) {
|
||||
super(mc, width, height, y1, itemHeight);
|
||||
setRenderBackground(false);
|
||||
setRenderTopAndBottom(false);
|
||||
setRenderSelection(false);
|
||||
headerHeight = 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
Color c = new Color(0x60_000000);
|
||||
UIRenderHelper.angledGradient(guiGraphics, 90, x0 + width / 2, y0, width, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(guiGraphics, -90, x0 + width / 2, y1, width, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(guiGraphics, 0, x0, y0 + height / 2, height, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(guiGraphics, 180, x1, y0 + height / 2, height, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(guiGraphics, 90, getX() + width / 2, getY(), width, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(guiGraphics, -90, getX() + width / 2, getY() + getHeight(), width, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(guiGraphics, 0, getX(), getY() + height / 2, height, 5, c, Color.TRANSPARENT_BLACK);
|
||||
UIRenderHelper.angledGradient(guiGraphics, 180, getX() + getWidth(), getY() + height / 2, height, 5, c, Color.TRANSPARENT_BLACK);
|
||||
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderList(GuiGraphics guiGraphics, int p_239229_, int p_239230_, float p_239231_) {
|
||||
Window window = minecraft.getWindow();
|
||||
double d0 = window.getGuiScale();
|
||||
RenderSystem.enableScissor((int) (this.x0 * d0), (int) (window.getHeight() - (this.y1 * d0)), (int) (this.width * d0), (int) (this.height * d0));
|
||||
super.renderList(guiGraphics, p_239229_, p_239230_, p_239231_);
|
||||
RenderSystem.disableScissor();
|
||||
protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super.renderList(guiGraphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
|
||||
public void renderWindowForeground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
@@ -62,7 +56,7 @@ public class ModifiersScreenList extends ObjectSelectionList<ModifiersScreenList
|
||||
for(int i1 = 0; i1 < l; ++i1) {
|
||||
int j1 = this.getRowTop(i1);
|
||||
int k1 = j1 + itemHeight;
|
||||
if (k1 >= this.y0 && j1 <= this.y1) {
|
||||
if (k1 >= this.getY() && j1 <= (this.getY() + this.getHeight())) {
|
||||
renderItemForeground(guiGraphics, pMouseX, pMouseY, pPartialTick, i1, i, j1, j, k);
|
||||
}
|
||||
}
|
||||
@@ -95,10 +89,10 @@ public class ModifiersScreenList extends ObjectSelectionList<ModifiersScreenList
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
|
||||
if (children().stream().anyMatch(e -> e.mouseScrolled(pMouseX, pMouseY, pDelta)))
|
||||
public boolean mouseScrolled(double pMouseX, double pMouseY, double scrollX, double scrollY) {
|
||||
if (children().stream().anyMatch(e -> e.mouseScrolled(pMouseX, pMouseY, scrollX, scrollY)))
|
||||
return true;
|
||||
return super.mouseScrolled(pMouseX, pMouseY, pDelta);
|
||||
return super.mouseScrolled(pMouseX, pMouseY, scrollX, scrollY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,7 +102,7 @@ public class ModifiersScreenList extends ObjectSelectionList<ModifiersScreenList
|
||||
|
||||
@Override
|
||||
protected int getScrollbarPosition() {
|
||||
return x0 + this.width - 6;
|
||||
return getX() + this.width - 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,12 +135,12 @@ public class ModifiersScreenList extends ObjectSelectionList<ModifiersScreenList
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double delta) {
|
||||
return getGuiListeners().stream().anyMatch(l -> l.mouseScrolled(x, y, delta));
|
||||
public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) {
|
||||
return getGuiListeners().stream().anyMatch(l -> l.mouseScrolled(x, y, scrollX, scrollY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float partialTicks) {
|
||||
|
||||
// UIRenderHelper.streak(guiGraphics, 0, x - 10, y + height / 2, height - 6, width, 0xdd_000000);
|
||||
// UIRenderHelper.streak(guiGraphics, 180, x + (int) (width * 1.35f) + 10, y + height / 2, height - 6, width / 8 * 7, 0xdd_000000);
|
||||
@@ -154,7 +148,6 @@ public class ModifiersScreenList extends ObjectSelectionList<ModifiersScreenList
|
||||
}
|
||||
|
||||
public void renderForeground(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
|
||||
for (var listener : listeners) {
|
||||
if (listener instanceof AbstractSimiWidget simiWidget && simiWidget.isHoveredOrFocused()
|
||||
&& simiWidget.visible) {
|
||||
|
||||
@@ -4,13 +4,13 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import nl.requios.effortlessbuilding.AllGuiTextures;
|
||||
import nl.requios.effortlessbuilding.AllIcons;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.BaseModifier;
|
||||
import nl.requios.effortlessbuilding.buildmodifier.RadialMirror;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.IconButton;
|
||||
import nl.requios.effortlessbuilding.create.foundation.gui.widget.ScrollInput;
|
||||
import nl.requios.effortlessbuilding.create.foundation.utility.Components;
|
||||
@@ -107,7 +107,7 @@ public class RadialMirrorEntry extends BaseModifierEntry<RadialMirror> {
|
||||
|
||||
//Radius
|
||||
radiusInput = new LabeledScrollInput(0, 0, 27, 18)
|
||||
.withRange(0, CapabilityHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false))
|
||||
.withRange(0, AttachmentHandler.getMaxMirrorRadius(Minecraft.getInstance().player, false))
|
||||
.titled(Minecraft.getInstance().player.isCreative() ?
|
||||
Component.literal("Radius") :
|
||||
Component.literal("Radius. Use Reach Upgrade items to increase maximum."))
|
||||
@@ -141,8 +141,8 @@ public class RadialMirrorEntry extends BaseModifierEntry<RadialMirror> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) {
|
||||
super.render(guiGraphics, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||
public void render(GuiGraphics guiGraphics, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean hovering, float partialTicks) {
|
||||
super.render(guiGraphics, index, y, x, width, height, mouseX, mouseY, hovering, partialTicks);
|
||||
|
||||
//draw position inputs
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package nl.requios.effortlessbuilding.gui.elements;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.client.gui.ScreenUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@@ -16,6 +14,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class GuiCheckBoxFixed extends Button {
|
||||
private final ResourceLocation DISABLED_BUTTON = new ResourceLocation("textures/gui/sprites/widget/button_disabled");
|
||||
private final int boxWidth;
|
||||
private boolean isChecked;
|
||||
|
||||
@@ -30,10 +29,8 @@ public class GuiCheckBoxFixed extends Button {
|
||||
|
||||
@Override
|
||||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
|
||||
//Is deprecated but still works
|
||||
ScreenUtils.blitWithBorder(guiGraphics, this.getX(), this.getY(), 0, 46, this.boxWidth, this.height, 200, 20, 2, 3, 2, 2, 0);
|
||||
guiGraphics.blitWithBorder(DISABLED_BUTTON, this.getX(), this.getY(), 0, 0, this.boxWidth, this.height, 200, 20, 2, 3, 2, 2);
|
||||
int color = 14737632;
|
||||
|
||||
if (packedFGColor != 0) {
|
||||
|
||||
@@ -5,8 +5,8 @@ import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -9,8 +9,8 @@ import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.text.DecimalFormat;
|
||||
@@ -138,7 +138,7 @@ public class GuiNumberField {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
textField.tick();
|
||||
// textField.tick();
|
||||
}
|
||||
|
||||
public boolean charTyped(char typedChar, int keyCode) {
|
||||
|
||||
@@ -11,9 +11,9 @@ import net.minecraft.client.gui.components.Renderable;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
@@ -38,7 +38,7 @@ public class GuiScrollPane extends SlotGui {
|
||||
this.font = font;
|
||||
this.renderSelection = false;
|
||||
listEntries = new ArrayList<>();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
NeoForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public IScrollEntry getListEntry(int index) {
|
||||
@@ -239,11 +239,11 @@ public class GuiScrollPane extends SlotGui {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int pButton) {
|
||||
for (int i = 0; i < this.getItemCount(); ++i) {
|
||||
double relativeX = getRelativeMouseX(mouseX);
|
||||
double relativeY = getRelativeMouseY(mouseY, i);
|
||||
this.getListEntry(i).mouseReleased(i, (int) mouseX, (int) mouseY, button, (int) relativeX, (int) relativeY);
|
||||
this.getListEntry(i).mouseReleased(i, (int) mouseX, (int) mouseY, pButton, (int) relativeX, (int) relativeY);
|
||||
}
|
||||
|
||||
this.visible = true;
|
||||
|
||||
@@ -13,8 +13,8 @@ import net.minecraft.client.gui.components.events.AbstractContainerEventHandler;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Collections;
|
||||
@@ -114,6 +114,7 @@ public abstract class SlotGui extends AbstractContainerEventHandler implements R
|
||||
this.scrolling = p_updateScrollingState_5_ == 0 && p_updateScrollingState_1_ >= (double) this.getScrollbarPosition() && p_updateScrollingState_1_ < (double) (this.getScrollbarPosition() + 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
|
||||
this.updateScrollingState(p_mouseClicked_1_, p_mouseClicked_3_, p_mouseClicked_5_);
|
||||
if (this.isVisible() && this.isMouseInList(p_mouseClicked_1_, p_mouseClicked_3_)) {
|
||||
@@ -136,21 +137,23 @@ public abstract class SlotGui extends AbstractContainerEventHandler implements R
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mouseReleased(double p_mouseReleased_1_, double p_mouseReleased_3_, int p_mouseReleased_5_) {
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int pButton) {
|
||||
if (this.getFocused() != null) {
|
||||
this.getFocused().mouseReleased(p_mouseReleased_1_, p_mouseReleased_3_, p_mouseReleased_5_);
|
||||
this.getFocused().mouseReleased(mouseX, mouseY, pButton);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseDragged(double p_mouseDragged_1_, double p_mouseDragged_3_, int p_mouseDragged_5_, double p_mouseDragged_6_, double p_mouseDragged_8_) {
|
||||
if (super.mouseDragged(p_mouseDragged_1_, p_mouseDragged_3_, p_mouseDragged_5_, p_mouseDragged_6_, p_mouseDragged_8_)) {
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double pMouseY, int button, double dragX, double dragY) {
|
||||
if (super.mouseDragged(mouseX, pMouseY, button, dragX, dragY)) {
|
||||
return true;
|
||||
} else if (this.isVisible() && p_mouseDragged_5_ == 0 && this.scrolling) {
|
||||
if (p_mouseDragged_3_ < (double) this.y0) {
|
||||
} else if (this.isVisible() && button == 0 && this.scrolling) {
|
||||
if (pMouseY < (double) this.y0) {
|
||||
this.yo = 0.0D;
|
||||
} else if (p_mouseDragged_3_ > (double) this.y1) {
|
||||
} else if (pMouseY > (double) this.y1) {
|
||||
this.yo = this.getMaxScroll();
|
||||
} else {
|
||||
double d0 = this.getMaxScroll();
|
||||
@@ -165,7 +168,7 @@ public abstract class SlotGui extends AbstractContainerEventHandler implements R
|
||||
d1 = 1.0D;
|
||||
}
|
||||
|
||||
this.yo += p_mouseDragged_8_ * d1;
|
||||
this.yo += dragY * d1;
|
||||
this.capYPosition();
|
||||
}
|
||||
|
||||
@@ -175,15 +178,17 @@ public abstract class SlotGui extends AbstractContainerEventHandler implements R
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mouseScrolled(double p_mouseScrolled_1_, double p_mouseScrolled_3_, double p_mouseScrolled_5_) {
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
|
||||
if (!this.isVisible()) {
|
||||
return false;
|
||||
} else {
|
||||
this.yo -= p_mouseScrolled_5_ * (double) this.itemHeight / 2.0D;
|
||||
this.yo -= scrollX * (double) this.itemHeight / 2.0D;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
|
||||
if (!this.isVisible()) {
|
||||
return false;
|
||||
|
||||
@@ -4,9 +4,7 @@ import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
@@ -23,10 +21,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.systems.ServerBuildState;
|
||||
import nl.requios.effortlessbuilding.utilities.BlockEntry;
|
||||
@@ -43,160 +39,161 @@ import java.util.Random;
|
||||
@ParametersAreNonnullByDefault
|
||||
public abstract class AbstractRandomizerBagItem extends Item {
|
||||
|
||||
private static long currentSeed = 1337;
|
||||
private static final Random rand = new Random(currentSeed);
|
||||
private static long currentSeed = 1337;
|
||||
private static final Random rand = new Random(currentSeed);
|
||||
|
||||
public AbstractRandomizerBagItem() {
|
||||
super(new Item.Properties().stacksTo(1));
|
||||
}
|
||||
public AbstractRandomizerBagItem() {
|
||||
super(new Item.Properties().stacksTo(1));
|
||||
}
|
||||
|
||||
public abstract int getInventorySize();
|
||||
public abstract int getInventorySize();
|
||||
|
||||
public abstract MenuProvider getContainerProvider(ItemStack item);
|
||||
public abstract MenuProvider getContainerProvider(ItemStack item);
|
||||
|
||||
/**
|
||||
* Get the inventory of a randomizer bag by checking the capability.
|
||||
*/
|
||||
public IItemHandler getBagInventory(ItemStack bag) {
|
||||
return bag.getCapability(ForgeCapabilities.ITEM_HANDLER, null).orElse(null);
|
||||
}
|
||||
/**
|
||||
* Get the inventory of a randomizer bag by checking the capability.
|
||||
*/
|
||||
@Nullable
|
||||
public IItemHandler getBagInventory(ItemStack bag) {
|
||||
return bag.getCapability(Capabilities.ItemHandler.ITEM, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick a random slot from the bag. Empty slots will never get chosen.
|
||||
*/
|
||||
public ItemStack pickRandomStack(IItemHandler bagInventory) {
|
||||
//Find how many stacks are non-empty, and save them in a list
|
||||
int nonempty = 0;
|
||||
List<ItemStack> nonEmptyStacks = new ArrayList<>();
|
||||
List<Integer> originalSlots = new ArrayList<>(getInventorySize());
|
||||
for (int i = 0; i < bagInventory.getSlots(); i++) {
|
||||
ItemStack stack = bagInventory.getStackInSlot(i);
|
||||
if (!stack.isEmpty()) {
|
||||
nonempty++;
|
||||
nonEmptyStacks.add(stack);
|
||||
originalSlots.add(i);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pick a random slot from the bag. Empty slots will never get chosen.
|
||||
*/
|
||||
public ItemStack pickRandomStack(IItemHandler bagInventory) {
|
||||
//Find how many stacks are non-empty, and save them in a list
|
||||
int nonempty = 0;
|
||||
List<ItemStack> nonEmptyStacks = new ArrayList<>();
|
||||
List<Integer> originalSlots = new ArrayList<>(getInventorySize());
|
||||
for (int i = 0; i < bagInventory.getSlots(); i++) {
|
||||
ItemStack stack = bagInventory.getStackInSlot(i);
|
||||
if (!stack.isEmpty()) {
|
||||
nonempty++;
|
||||
nonEmptyStacks.add(stack);
|
||||
originalSlots.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (nonEmptyStacks.size() != originalSlots.size())
|
||||
throw new Error("NonEmptyStacks and OriginalSlots not same size");
|
||||
if (nonEmptyStacks.size() != originalSlots.size())
|
||||
throw new Error("NonEmptyStacks and OriginalSlots not same size");
|
||||
|
||||
if (nonempty == 0) return ItemStack.EMPTY;
|
||||
if (nonempty == 0) return ItemStack.EMPTY;
|
||||
|
||||
//Pick random slot
|
||||
int randomSlot = rand.nextInt(nonempty);
|
||||
if (randomSlot < 0 || randomSlot > bagInventory.getSlots()) return ItemStack.EMPTY;
|
||||
//Pick random slot
|
||||
int randomSlot = rand.nextInt(nonempty);
|
||||
if (randomSlot < 0 || randomSlot > bagInventory.getSlots()) return ItemStack.EMPTY;
|
||||
|
||||
int originalSlot = originalSlots.get(randomSlot);
|
||||
if (originalSlot < 0 || originalSlot > bagInventory.getSlots()) return ItemStack.EMPTY;
|
||||
int originalSlot = originalSlots.get(randomSlot);
|
||||
if (originalSlot < 0 || originalSlot > bagInventory.getSlots()) return ItemStack.EMPTY;
|
||||
|
||||
return bagInventory.getStackInSlot(originalSlot);
|
||||
}
|
||||
return bagInventory.getStackInSlot(originalSlot);
|
||||
}
|
||||
|
||||
public ItemStack findStack(IItemHandler bagInventory, Item item) {
|
||||
for (int i = 0; i < bagInventory.getSlots(); i++) {
|
||||
ItemStack stack = bagInventory.getStackInSlot(i);
|
||||
if (!stack.isEmpty() && stack.getItem() == item) {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
public ItemStack findStack(IItemHandler bagInventory, Item item) {
|
||||
for (int i = 0; i < bagInventory.getSlots(); i++) {
|
||||
ItemStack stack = bagInventory.getStackInSlot(i);
|
||||
if (!stack.isEmpty() && stack.getItem() == item) {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static void resetRandomness() {
|
||||
rand.setSeed(currentSeed);
|
||||
}
|
||||
public static void resetRandomness() {
|
||||
rand.setSeed(currentSeed);
|
||||
}
|
||||
|
||||
public static void renewRandomness() {
|
||||
currentSeed = Calendar.getInstance().getTimeInMillis();
|
||||
rand.setSeed(currentSeed);
|
||||
}
|
||||
public static void renewRandomness() {
|
||||
currentSeed = Calendar.getInstance().getTimeInMillis();
|
||||
rand.setSeed(currentSeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext ctx) {
|
||||
Player player = ctx.getPlayer();
|
||||
Level world = ctx.getLevel();
|
||||
BlockPos pos = ctx.getClickedPos();
|
||||
Direction facing = ctx.getClickedFace();
|
||||
ItemStack item = ctx.getItemInHand();
|
||||
Vec3 hitVec = ctx.getClickLocation();
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext ctx) {
|
||||
Player player = ctx.getPlayer();
|
||||
Level world = ctx.getLevel();
|
||||
BlockPos pos = ctx.getClickedPos();
|
||||
Direction facing = ctx.getClickedFace();
|
||||
ItemStack item = ctx.getItemInHand();
|
||||
Vec3 hitVec = ctx.getClickLocation();
|
||||
|
||||
if (player == null) return InteractionResult.FAIL;
|
||||
if (player == null) return InteractionResult.FAIL;
|
||||
|
||||
if (ctx.getPlayer() != null && ctx.getPlayer().isShiftKeyDown()) { //ctx.isPlacerSneaking()
|
||||
if (world.isClientSide) return InteractionResult.SUCCESS;
|
||||
//Open inventory
|
||||
NetworkHooks.openScreen((ServerPlayer) player, getContainerProvider(item));
|
||||
} else {
|
||||
if (world.isClientSide) return InteractionResult.SUCCESS;
|
||||
if (ctx.getPlayer() != null && ctx.getPlayer().isShiftKeyDown()) { //ctx.isPlacerSneaking()
|
||||
if (world.isClientSide) return InteractionResult.SUCCESS;
|
||||
//Open inventory
|
||||
player.openMenu(getContainerProvider(item));
|
||||
} else {
|
||||
if (world.isClientSide) return InteractionResult.SUCCESS;
|
||||
|
||||
//---Only place manually if in normal vanilla mode---
|
||||
if (!ServerBuildState.isLikeVanilla(player)) {
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
//---Only place manually if in normal vanilla mode---
|
||||
if (!ServerBuildState.isLikeVanilla(player)) {
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
//Use item
|
||||
//Get bag inventory
|
||||
ItemStack bag = ctx.getItemInHand();
|
||||
IItemHandler bagInventory = getBagInventory(bag);
|
||||
if (bagInventory == null)
|
||||
return InteractionResult.FAIL;
|
||||
//Use item
|
||||
//Get bag inventory
|
||||
ItemStack bag = ctx.getItemInHand();
|
||||
IItemHandler bagInventory = getBagInventory(bag);
|
||||
if (bagInventory == null)
|
||||
return InteractionResult.FAIL;
|
||||
|
||||
ItemStack toPlace = pickRandomStack(bagInventory);
|
||||
if (toPlace.isEmpty()) return InteractionResult.FAIL;
|
||||
ItemStack toPlace = pickRandomStack(bagInventory);
|
||||
if (toPlace.isEmpty()) return InteractionResult.FAIL;
|
||||
|
||||
if (!world.getBlockState(pos).getBlock().canBeReplaced(world.getBlockState(pos), Fluids.EMPTY)) {
|
||||
pos = pos.relative(facing);
|
||||
}
|
||||
if (!world.getBlockState(pos).getBlock().canBeReplaced(world.getBlockState(pos), Fluids.EMPTY)) {
|
||||
pos = pos.relative(facing);
|
||||
}
|
||||
|
||||
BlockPlaceContext blockItemUseContext = new BlockPlaceContext(new UseOnContext(player, ctx.getHand(), new BlockHitResult(hitVec, facing, pos, false)));
|
||||
BlockState blockState = Block.byItem(toPlace.getItem()).getStateForPlacement(blockItemUseContext);
|
||||
BlockPlaceContext blockItemUseContext = new BlockPlaceContext(new UseOnContext(player, ctx.getHand(), new BlockHitResult(hitVec, facing, pos, false)));
|
||||
BlockState blockState = Block.byItem(toPlace.getItem()).getStateForPlacement(blockItemUseContext);
|
||||
|
||||
var blockEntry = new BlockEntry(pos, blockState, toPlace.getItem());
|
||||
var blockSet = new BlockSet(List.of(blockEntry), pos, pos, false);
|
||||
EffortlessBuilding.SERVER_BLOCK_PLACER.applyBlockSet(player, blockSet);
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
var blockEntry = new BlockEntry(pos, blockState, toPlace.getItem());
|
||||
var blockSet = new BlockSet(List.of(blockEntry), pos, pos, false);
|
||||
EffortlessBuilding.SERVER_BLOCK_PLACER.applyBlockSet(player, blockSet);
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
ItemStack bag = player.getItemInHand(hand);
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
ItemStack bag = player.getItemInHand(hand);
|
||||
|
||||
if (player.isShiftKeyDown()) {
|
||||
if (world.isClientSide) return new InteractionResultHolder<>(InteractionResult.SUCCESS, bag);
|
||||
//Open inventory
|
||||
NetworkHooks.openScreen((ServerPlayer) player, getContainerProvider(bag));
|
||||
} else {
|
||||
//Use item
|
||||
//Get bag inventory
|
||||
IItemHandler bagInventory = getBagInventory(bag);
|
||||
if (bagInventory == null)
|
||||
return new InteractionResultHolder<>(InteractionResult.FAIL, bag);
|
||||
if (player.isShiftKeyDown()) {
|
||||
if (world.isClientSide) return new InteractionResultHolder<>(InteractionResult.SUCCESS, bag);
|
||||
//Open inventory
|
||||
player.openMenu(getContainerProvider(bag));
|
||||
} else {
|
||||
//Use item
|
||||
//Get bag inventory
|
||||
IItemHandler bagInventory = getBagInventory(bag);
|
||||
if (bagInventory == null)
|
||||
return new InteractionResultHolder<>(InteractionResult.FAIL, bag);
|
||||
|
||||
ItemStack toUse = pickRandomStack(bagInventory);
|
||||
if (toUse.isEmpty()) return new InteractionResultHolder<>(InteractionResult.FAIL, bag);
|
||||
ItemStack toUse = pickRandomStack(bagInventory);
|
||||
if (toUse.isEmpty()) return new InteractionResultHolder<>(InteractionResult.FAIL, bag);
|
||||
|
||||
return toUse.use(world, player, hand);
|
||||
}
|
||||
return new InteractionResultHolder<>(InteractionResult.PASS, bag);
|
||||
}
|
||||
return toUse.use(world, player, hand);
|
||||
}
|
||||
return new InteractionResultHolder<>(InteractionResult.PASS, bag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseDuration(ItemStack p_77626_1_) {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public int getUseDuration(ItemStack p_77626_1_) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
return new ItemHandlerCapabilityProvider(getInventorySize());
|
||||
}
|
||||
// @Nullable
|
||||
// @Override
|
||||
// public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
// return new ItemHandlerCapabilityProvider(getInventorySize()); TODO: Re-enable itemhandler cap on randomizer bag item!
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag flag) {
|
||||
tooltip.add(Component.literal(ChatFormatting.YELLOW + "*Experimental* Only works in singleplayer"));
|
||||
tooltip.add(Component.literal(ChatFormatting.BLUE + "Rightclick" + ChatFormatting.GRAY + " to place a random block"));
|
||||
tooltip.add(Component.literal(ChatFormatting.BLUE + "Sneak + rightclick" + ChatFormatting.GRAY + " to open inventory"));
|
||||
}
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag flag) {
|
||||
tooltip.add(Component.literal(ChatFormatting.YELLOW + "*Experimental* Only works in singleplayer"));
|
||||
tooltip.add(Component.literal(ChatFormatting.BLUE + "Rightclick" + ChatFormatting.GRAY + " to place a random block"));
|
||||
tooltip.add(Component.literal(ChatFormatting.BLUE + "Sneak + rightclick" + ChatFormatting.GRAY + " to open inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
package nl.requios.effortlessbuilding.item;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemHandlerCapabilityProvider implements ICapabilitySerializable<CompoundTag> {
|
||||
IItemHandler itemHandler;
|
||||
|
||||
public ItemHandlerCapabilityProvider(int size) {
|
||||
itemHandler = new ItemStackHandler(size);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
return ForgeCapabilities.ITEM_HANDLER.orEmpty(cap, LazyOptional.of(() -> itemHandler));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
return ((ItemStackHandler) itemHandler).serializeNBT();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
((ItemStackHandler) itemHandler).deserializeNBT(nbt);
|
||||
}
|
||||
}
|
||||
//package nl.requios.effortlessbuilding.item;
|
||||
//
|
||||
//import net.minecraft.nbt.CompoundTag;
|
||||
//import net.minecraft.core.Direction;
|
||||
//import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
//import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
//import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
//import net.neoforged.neoforge.items.IItemHandler;
|
||||
//import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
//import net.neoforged.neoforge.common.capabilities.ICapabilitySerializable;
|
||||
//
|
||||
//import javax.annotation.Nonnull;
|
||||
//import javax.annotation.Nullable;
|
||||
//
|
||||
//public class ItemHandlerCapabilityProvider implements ICapabilitySerializable<CompoundTag> { TODO: Reimplement the ItemHandler stuff
|
||||
// IItemHandler itemHandler;
|
||||
//
|
||||
// public ItemHandlerCapabilityProvider(int size) {
|
||||
// itemHandler = new ItemStackHandler(size);
|
||||
// }
|
||||
//
|
||||
// @Nonnull
|
||||
// @Override
|
||||
// public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
// return Capabilities.ITEM_HANDLER.orEmpty(cap, LazyOptional.of(() -> itemHandler));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public CompoundTag serializeNBT() {
|
||||
// return ((ItemStackHandler) itemHandler).serializeNBT();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deserializeNBT(CompoundTag nbt) {
|
||||
// ((ItemStackHandler) itemHandler).deserializeNBT(nbt);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -13,8 +13,8 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||
import nl.requios.effortlessbuilding.create.foundation.item.TooltipHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -31,18 +31,19 @@ public class PowerLevelItem extends Item {
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
if (powerLevel.canIncreasePowerLevel()) {
|
||||
if (!world.isClientSide) {
|
||||
powerLevel.increasePowerLevel();
|
||||
player.setData(EffortlessBuilding.POWER_LEVEL, powerLevel);
|
||||
EffortlessBuilding.log(player, "Upgraded power level to " + powerLevel.getPowerLevel());
|
||||
|
||||
stack.shrink(1);
|
||||
|
||||
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||
|
||||
CapabilityHandler.syncToClient(player);
|
||||
AttachmentHandler.syncToClient(player);
|
||||
}
|
||||
|
||||
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import nl.requios.effortlessbuilding.CommonConfig;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -32,19 +32,20 @@ public class ReachUpgrade1Item extends Item {
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
int currentLevel = powerLevel.getPowerLevel();
|
||||
if (currentLevel == 0) {
|
||||
if (!world.isClientSide) {
|
||||
powerLevel.increasePowerLevel();
|
||||
player.setData(EffortlessBuilding.POWER_LEVEL, powerLevel);
|
||||
EffortlessBuilding.log(player, "Upgraded power level to " + powerLevel.getPowerLevel());
|
||||
|
||||
stack.shrink(1);
|
||||
|
||||
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||
|
||||
CapabilityHandler.syncToClient(player);
|
||||
AttachmentHandler.syncToClient(player);
|
||||
}
|
||||
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||
} else if (currentLevel > 0) {
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import nl.requios.effortlessbuilding.CommonConfig;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -33,7 +33,7 @@ public class ReachUpgrade2Item extends Item {
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
int currentLevel = powerLevel.getPowerLevel();
|
||||
if (currentLevel == 1) {
|
||||
@@ -45,7 +45,7 @@ public class ReachUpgrade2Item extends Item {
|
||||
|
||||
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||
|
||||
CapabilityHandler.syncToClient(player);
|
||||
AttachmentHandler.syncToClient(player);
|
||||
}
|
||||
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||
} else if (currentLevel < 1) {
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import nl.requios.effortlessbuilding.CommonConfig;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.capability.CapabilityHandler;
|
||||
import nl.requios.effortlessbuilding.capability.IPowerLevel;
|
||||
import nl.requios.effortlessbuilding.attachment.AttachmentHandler;
|
||||
import nl.requios.effortlessbuilding.attachment.PowerLevel;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -32,19 +32,20 @@ public class ReachUpgrade3Item extends Item {
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
IPowerLevel powerLevel = player.getCapability(CapabilityHandler.POWER_LEVEL_CAPABILITY).orElse(null);
|
||||
PowerLevel powerLevel = player.getData(EffortlessBuilding.POWER_LEVEL);
|
||||
if (powerLevel != null) {
|
||||
int currentLevel = powerLevel.getPowerLevel();
|
||||
if (currentLevel == 2) {
|
||||
if (!world.isClientSide) {
|
||||
powerLevel.increasePowerLevel();
|
||||
player.setData(EffortlessBuilding.POWER_LEVEL, powerLevel);
|
||||
EffortlessBuilding.log(player, "Upgraded power level to " + powerLevel.getPowerLevel());
|
||||
|
||||
stack.shrink(1);
|
||||
|
||||
world.playSound((Player) null, player.blockPosition(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1f, 1f);
|
||||
|
||||
CapabilityHandler.syncToClient(player);
|
||||
AttachmentHandler.syncToClient(player);
|
||||
}
|
||||
return InteractionResultHolder.sidedSuccess(stack, world.isClientSide());
|
||||
} else if (currentLevel < 2) {
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package nl.requios.effortlessbuilding.item;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifier;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
|
||||
import net.neoforged.neoforge.common.loot.LootModifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
//Adds a single item with a chance to any loot tables. Specify loot tables in the JSON file.
|
||||
//Add JSON files to resources/data/effortlessbuilding/loot_modifiers, and list them in resources/data/forge/loot_modifiers/global_loot_modifiers.json
|
||||
//https://forge.gemwire.uk/wiki/Dynamic_Loot_Modification
|
||||
@@ -21,21 +20,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
//https://mcreator.net/wiki/minecraft-vanilla-loot-tables-list#toc-index-1
|
||||
public class SingleItemLootModifier extends LootModifier {
|
||||
|
||||
public static final RegistryObject<Codec<SingleItemLootModifier>> CODEC = EffortlessBuilding.LOOT_MODIFIERS.register("single_item_loot_modifier", () ->
|
||||
RecordCodecBuilder.create(inst -> codecStart(inst).and(
|
||||
inst.group(
|
||||
public static final Supplier<Codec<SingleItemLootModifier>> CODEC = Suppliers.memoize(() ->
|
||||
RecordCodecBuilder.create(instance -> codecStart(instance).and(
|
||||
instance.group(
|
||||
Codec.FLOAT.fieldOf("chance").forGetter(m -> m.chance),
|
||||
ForgeRegistries.ITEMS.getCodec().fieldOf("item").forGetter(m -> m.item)
|
||||
)).apply(inst, SingleItemLootModifier::new)
|
||||
ItemStack.SINGLE_ITEM_CODEC.fieldOf("item").forGetter(m -> m.stack)
|
||||
)).apply(instance, SingleItemLootModifier::new)
|
||||
));
|
||||
|
||||
private final float chance;
|
||||
private final Item item;
|
||||
private final ItemStack stack;
|
||||
|
||||
public SingleItemLootModifier(LootItemCondition[] conditionsIn, float chance, Item item) {
|
||||
public SingleItemLootModifier(LootItemCondition[] conditionsIn, float chance, ItemStack stack) {
|
||||
super(conditionsIn);
|
||||
this.chance = chance;
|
||||
this.item = item;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -47,7 +46,7 @@ public class SingleItemLootModifier extends LootModifier {
|
||||
//
|
||||
//with chance, add an item
|
||||
if (context.getRandom().nextFloat() < chance) {
|
||||
generatedLoot.add(new ItemStack(item, 1));
|
||||
generatedLoot.add(stack.copy());
|
||||
}
|
||||
return generatedLoot;
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.network;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import nl.requios.effortlessbuilding.systems.ServerBuildState;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class IsQuickReplacingPacket {
|
||||
private boolean isQuickReplacing;
|
||||
|
||||
public IsQuickReplacingPacket() {
|
||||
}
|
||||
|
||||
public IsQuickReplacingPacket(boolean isQuickReplacing) {
|
||||
this.isQuickReplacing = isQuickReplacing;
|
||||
}
|
||||
|
||||
public static void encode(IsQuickReplacingPacket message, FriendlyByteBuf buf) {
|
||||
buf.writeBoolean(message.isQuickReplacing);
|
||||
}
|
||||
|
||||
public static IsQuickReplacingPacket decode(FriendlyByteBuf buf) {
|
||||
return new IsQuickReplacingPacket(buf.readBoolean());
|
||||
}
|
||||
|
||||
public static class Handler {
|
||||
public static void handle(IsQuickReplacingPacket message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
ServerBuildState.setIsQuickReplacing(ctx.get().getSender(), message.isQuickReplacing);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.network;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import nl.requios.effortlessbuilding.systems.ServerBuildState;
|
||||
|
||||
public class IsUsingBuildModePacket {
|
||||
private boolean isUsingBuildMode;
|
||||
|
||||
public IsUsingBuildModePacket() {
|
||||
}
|
||||
|
||||
public IsUsingBuildModePacket(boolean isUsingBuildMode) {
|
||||
this.isUsingBuildMode = isUsingBuildMode;
|
||||
}
|
||||
|
||||
public static void encode(IsUsingBuildModePacket message, FriendlyByteBuf buf) {
|
||||
buf.writeBoolean(message.isUsingBuildMode);
|
||||
}
|
||||
|
||||
public static IsUsingBuildModePacket decode(FriendlyByteBuf buf) {
|
||||
return new IsUsingBuildModePacket(buf.readBoolean());
|
||||
}
|
||||
|
||||
public static class Handler {
|
||||
public static void handle(IsUsingBuildModePacket message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
ServerBuildState.setIsUsingBuildMode(ctx.get().getSender(), message.isUsingBuildMode);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package nl.requios.effortlessbuilding.network;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuilding;
|
||||
import nl.requios.effortlessbuilding.EffortlessBuildingClient;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Sync build modifiers between server and client, for saving and loading.
|
||||
*/
|
||||
public class ModifierSettingsPacket {
|
||||
|
||||
private static final String DATA_KEY = EffortlessBuilding.MODID + ":buildModifiers";
|
||||
private CompoundTag modifiersTag;
|
||||
|
||||
public ModifierSettingsPacket() {
|
||||
}
|
||||
|
||||
public ModifierSettingsPacket(CompoundTag modifiersTag) {
|
||||
this.modifiersTag = modifiersTag;
|
||||
}
|
||||
|
||||
//Only on server
|
||||
public ModifierSettingsPacket(Player player) {
|
||||
this.modifiersTag = player.getPersistentData().getCompound(DATA_KEY);
|
||||
}
|
||||
|
||||
public static void encode(ModifierSettingsPacket message, FriendlyByteBuf buf) {
|
||||
buf.writeNbt(message.modifiersTag);
|
||||
}
|
||||
|
||||
public static ModifierSettingsPacket decode(FriendlyByteBuf buf) {
|
||||
return new ModifierSettingsPacket(buf.readNbt());
|
||||
}
|
||||
|
||||
public static class Handler {
|
||||
public static void handle(ModifierSettingsPacket message, Supplier<NetworkEvent.Context> ctx) {
|
||||
if (ctx.get().getDirection().getReceptionSide().isServer()) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
var player = ctx.get().getSender();
|
||||
//To server, save to persistent player data
|
||||
player.getPersistentData().put(DATA_KEY, message.modifiersTag);
|
||||
});
|
||||
} else {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
//To client, load into system
|
||||
EffortlessBuildingClient.BUILD_MODIFIERS.deserializeNBT(message.modifiersTag);
|
||||
});
|
||||
}
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user