diff --git a/build.gradle b/build.gradle index 4e2dbbf..a19800f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,9 @@ plugins { id 'eclipse' id 'idea' + id 'java-library' id 'maven-publish' - id 'net.minecraftforge.gradle' version '[6.0,6.2)' + id 'net.neoforged.gradle.userdev' version '7.0.145' id 'com.github.johnrengelman.shadow' version '8.1.1' } @@ -15,67 +16,35 @@ ext.buildnumber = 0 project.buildnumber = System.getenv('BUILD_NUMBER') version = "${mod_version}" + (buildnumber ? ".${buildnumber}" : ".0-SNAPSHOT") -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) -minecraft { - mappings channel: 'official', version: minecraft_version +runs { + configureEach { + workingDirectory project.file('run') - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + systemProperty 'forge.logging.markers', 'REGISTRIES' + systemProperty 'forge.logging.console.level', 'debug' - runs { - client { - taskName 'ltlib_client' - copyIdeResources = true - - workingDirectory project.file('run') - - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' - - mods { - ltlib { - source sourceSets.main - } - } - } - - server { - taskName 'ltlib_server' - copyIdeResources = true - - workingDirectory project.file('run') - - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' - - mods { - ltlib { - source sourceSets.main - } - } - } - - data { - taskName 'ltlib_data' - copyIdeResources = true - - workingDirectory project.file('run') - - environment 'target', 'fmluserdevdata' + modSource project.sourceSets.main + } - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' + client { + programArguments.addAll '--username', 'Dev###' + } - mods { - ltlib { - source sourceSets.main - } - } + server { + programArgument '--nogui' + } - args '--mod', 'ltlib', '--all', '--output', '"' + rootProject.file('src/generated/resources/') + '"', - '--existing', '"' + sourceSets.main.resources.srcDirs[0] + '"' + data { + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() + } +} - } +subsystems { + parchment { + minecraftVersion = minecraft_version + mappingsVersion = parchment_version } } @@ -88,7 +57,7 @@ repositories { } dependencies { - minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" + implementation "net.neoforged:neoforge:${neo_version}" shadow ('io.netty:netty-codec-http:4.1.82.Final') { transitive = false @@ -133,10 +102,6 @@ shadowJar { } } -reobf { - shadowJar {} -} - publishing { publications { mavenJava(MavenPublication) { diff --git a/gradle.properties b/gradle.properties index e367755..1a4d795 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,9 @@ +mod_id=ltlib mod_version=1.3 release_type=release -minecraft_version=1.20.1 -forge_version=47.0.19 +minecraft_version=1.21 +neo_version=21.0.58-beta +parchment_version=2024.06.23 # Sets default memory used for gradle commands. Can be overridden by user or command line properties. # This is required to provide enough memory for the Minecraft decompilation process. diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cb..e644113 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..b82aa23 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ 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.7-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index 65dcd68..1aa94a4 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 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"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..7101f8e 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,92 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index 162d9da..4b19003 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,7 @@ pluginManagement { repositories { gradlePluginPortal() - maven { url = 'https://maven.minecraftforge.net/' } + maven { url = 'https://maven.neoforged.net/releases' } mavenCentral() } } diff --git a/src/main/java/com/lovetropics/lib/codec/MoreCodecs.java b/src/main/java/com/lovetropics/lib/codec/MoreCodecs.java index daa1827..6cb928b 100644 --- a/src/main/java/com/lovetropics/lib/codec/MoreCodecs.java +++ b/src/main/java/com/lovetropics/lib/codec/MoreCodecs.java @@ -1,22 +1,22 @@ package com.lovetropics.lib.codec; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.gson.JsonSyntaxException; import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Pair; -import com.mojang.datafixers.util.Unit; -import com.mojang.serialization.*; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.*; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2FloatMap; +import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.SharedConstants; -import net.minecraft.advancements.critereon.BlockPredicate; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.util.ExtraCodecs; import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.level.block.Block; @@ -27,10 +27,15 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.function.IntFunction; -import java.util.stream.Stream; public final class MoreCodecs { public static final Codec ITEM_STACK = Codec.either(ItemStack.CODEC, BuiltInRegistries.ITEM.byNameCodec()) @@ -42,16 +47,6 @@ public final class MoreCodecs { public static final Codec BLOCK_STATE_PROVIDER = Codec.either(BlockStateProvider.CODEC, BLOCK_STATE) .xmap(either -> either.map(Function.identity(), BlockStateProvider::simple), Either::left); - public static final Codec EQUIPMENT_SLOT = stringVariants(EquipmentSlot.values(), EquipmentSlot::getName); - - public static final Codec BLOCK_PREDICATE = ExtraCodecs.JSON.comapFlatMap(json -> { - try { - return DataResult.success(BlockPredicate.fromJson(json)); - } catch (JsonSyntaxException e) { - return DataResult.error(e::getMessage); - } - }, BlockPredicate::serializeToJson); - public static final Codec AABB = RecordCodecBuilder.create(i -> i.group( Vec3.CODEC.fieldOf("start").forGetter(aabb -> new Vec3(aabb.minX, aabb.minY, aabb.minZ)), Vec3.CODEC.fieldOf("end").forGetter(aabb -> new Vec3(aabb.maxX, aabb.maxY, aabb.maxZ)) @@ -60,7 +55,7 @@ public final class MoreCodecs { public static final Codec POTION = BuiltInRegistries.POTION.byNameCodec(); private static final Codec EFFECT_INSTANCE_RECORD = RecordCodecBuilder.create(i -> i.group( - BuiltInRegistries.MOB_EFFECT.byNameCodec().fieldOf("type").forGetter(MobEffectInstance::getEffect), + BuiltInRegistries.MOB_EFFECT.holderByNameCodec().fieldOf("type").forGetter(MobEffectInstance::getEffect), Codec.FLOAT.optionalFieldOf("seconds").forGetter(c -> c.isInfiniteDuration() ? Optional.empty() : Optional.of((float) c.getDuration() / SharedConstants.TICKS_PER_SECOND)), Codec.INT.fieldOf("amplifier").forGetter(MobEffectInstance::getAmplifier), Codec.BOOL.optionalFieldOf("ambient", false).forGetter(MobEffectInstance::isAmbient), @@ -75,14 +70,14 @@ public final class MoreCodecs { .comapFlatMap(either -> either.map(potion -> { List effects = potion.getEffects(); if (effects.size() == 1) { - return DataResult.success(effects.get(0)); + return DataResult.success(effects.getFirst()); } else { return DataResult.error(() -> "Potion must have only 1 effect"); } }, DataResult::success), Either::right); public static MapCodec inputOptionalFieldOf(Codec codec, String name, T fallback) { - return Codec.optionalField(name, codec).xmap( + return Codec.optionalField(name, codec, false).xmap( o -> o.orElse(fallback), Optional::of ); @@ -145,17 +140,6 @@ public static Codec> object2Double(Codec codec) { return Codec.unboundedMap(codec, Codec.DOUBLE).xmap(Object2DoubleOpenHashMap::new, HashMap::new); } - @Deprecated - public static > Codec sorted(Codec codec, Comparator comparator) { - return codec.xmap( - list -> { - list.sort(comparator); - return list; - }, - Function.identity() - ); - } - public static Codec> sortedList(Codec codec, Comparator comparator) { return codec.listOf().xmap( list -> { @@ -167,10 +151,6 @@ public static Codec> sortedList(Codec codec, Comparator Codec> dispatchByMapKey(Codec keyCodec, Function> valueCodec) { - return new DispatchMapCodec<>(keyCodec, valueCodec); - } - public static Codec localDateTime(DateTimeFormatter formatter) { return Codec.STRING.comapFlatMap( string -> { @@ -185,98 +165,9 @@ public static Codec localDateTime(DateTimeFormatter formatter) { } public static Codec tryFirst(Codec first, Codec second) { - return new TryFirstCodec<>(first, second); - } - - record DispatchMapCodec(Codec keyCodec, Function> valueCodec) implements Codec> { - @Override - public DataResult, T>> decode(DynamicOps ops, T input) { - return ops.getMap(input).flatMap(mapInput -> { - ImmutableMap.Builder read = ImmutableMap.builder(); - ImmutableList.Builder> failed = ImmutableList.builder(); - - DataResult result = mapInput.entries().reduce( - DataResult.success(Unit.INSTANCE, Lifecycle.stable()), - (r, pair) -> this.keyCodec.parse(ops, pair.getFirst()).flatMap(key -> { - DataResult> entry = this.valueCodec.apply(key).parse(ops, pair.getSecond()) - .map(value -> Pair.of(key, value)); - entry.error().ifPresent(e -> failed.add(pair)); - - return r.apply2stable((u, p) -> { - read.put(p.getFirst(), p.getSecond()); - return u; - }, entry); - }), - (r1, r2) -> r1.apply2stable((u1, u2) -> u1, r2) - ); - - Map elements = read.build(); - T errors = ops.createMap(failed.build().stream()); - - return result.map(unit -> Pair.of(elements, input)) - .setPartial(Pair.of(elements, input)) - .mapError(e -> e + " missed input: " + errors); - }); - } - - @Override - public DataResult encode(Map input, DynamicOps ops, T prefix) { - RecordBuilder map = ops.mapBuilder(); - for (Map.Entry entry : input.entrySet()) { - K key = entry.getKey(); - V value = entry.getValue(); - map.add(this.keyCodec.encodeStart(ops, key), this.valueCodec.apply(key).encodeStart(ops, value)); - } - return map.build(prefix); - } - } - - record TryFirstCodec(Codec first, Codec second) implements Codec { - @Override - public DataResult> decode(final DynamicOps ops, final R input) { - final DataResult> firstRead = first.decode(ops, input); - if (firstRead.result().isPresent()) { - return firstRead; - } - return second.decode(ops, input); - } - - @Override - public DataResult encode(final T input, final DynamicOps ops, final R prefix) { - return second.encode(input, ops, prefix); - } - } - - public static MapCodec> strictOptionalFieldOf(final Codec codec, final String name) { - return new MapCodec<>() { - @Override - public DataResult> decode(final DynamicOps ops, final MapLike input) { - final T value = input.get(name); - if (value == null) { - return DataResult.success(Optional.empty()); - } - return codec.parse(ops, value).map(Optional::of); - } - - @Override - public RecordBuilder encode(final Optional input, final DynamicOps ops, final RecordBuilder prefix) { - if (input.isPresent()) { - return prefix.add(name, codec.encodeStart(ops, input.get())); - } - return prefix; - } - - @Override - public Stream keys(final DynamicOps ops) { - return Stream.of(ops.createString(name)); - } - }; - } - - public static MapCodec strictOptionalFieldOf(final Codec codec, final String name, final A defaultValue) { - return strictOptionalFieldOf(codec, name).xmap( - value -> value.orElse(defaultValue), - value -> Objects.equals(value, defaultValue) ? Optional.empty() : Optional.of(value) + return Codec.either(first, second).xmap( + either -> either.map(Function.identity(), Function.identity()), + Either::right ); } } diff --git a/src/main/java/com/lovetropics/lib/entity/FireworkPalette.java b/src/main/java/com/lovetropics/lib/entity/FireworkPalette.java index 692470f..0716e8a 100644 --- a/src/main/java/com/lovetropics/lib/entity/FireworkPalette.java +++ b/src/main/java/com/lovetropics/lib/entity/FireworkPalette.java @@ -1,6 +1,8 @@ package com.lovetropics.lib.entity; +import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.core.BlockPos; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.util.RandomSource; @@ -8,10 +10,13 @@ import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.FireworkExplosion; +import net.minecraft.world.item.component.Fireworks; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import javax.annotation.Nonnull; +import java.util.List; public final class FireworkPalette { private static final RandomSource RANDOM = RandomSource.create(); @@ -63,11 +68,6 @@ public int[][] getPalette() { public @Nonnull FireworkRocketEntity create(@Nonnull Level level, @Nonnull BlockPos pos) { ItemStack firework = new ItemStack(Items.FIREWORK_ROCKET); - firework.setTag(new CompoundTag()); - - CompoundTag explosion = new CompoundTag(); - explosion.putBoolean("Flicker", true); - explosion.putBoolean("Trail", true); int[] colors; if (this.palette.length == 0) { @@ -83,18 +83,16 @@ public int[][] getPalette() { } } - explosion.putIntArray("Colors", colors); - byte type = (byte) (RANDOM.nextInt(3) + 1); - type = type == 3 ? 4 : type; - explosion.putByte("Type", type); + int type = RANDOM.nextInt(3) + 1; + + // Skip creeper firework type + if (type == 3) { + type = 4; + } - ListTag explosions = new ListTag(); - explosions.add(explosion); + FireworkExplosion explosion = new FireworkExplosion(FireworkExplosion.Shape.byId(type), IntList.of(colors), IntList.of(), true, true); - CompoundTag fireworkTag = new CompoundTag(); - fireworkTag.put("Explosions", explosions); - fireworkTag.putByte("Flight", (byte) 1); - firework.addTagElement("Fireworks", fireworkTag); + firework.set(DataComponents.FIREWORKS, new Fireworks(1, List.of(explosion))); return new FireworkRocketEntity(level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, firework); }