diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index dd80175..bfda8a5 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -14,10 +14,10 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: - java-version: '17' + java-version: '21' distribution: 'adopt' - name: Change wrapper permissions run: chmod +x ./gradlew @@ -30,16 +30,16 @@ jobs: if: endswith(github.ref_name, 'master') && github.ref_protected && github.ref_type == 'branch' runs-on: ubuntu-latest env: - APPVEYOR_BUILD_VERSION: '3.2.2' + APPVEYOR_BUILD_VERSION: '3.2.3' CURSETOKEN: ${{ secrets.CURSETOKEN }} steps: - uses: actions/checkout@v3 with: submodules: true - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: - java-version: '17' + java-version: '21' distribution: 'adopt' - name: Change wrapper permissions run: chmod +x ./gradlew diff --git a/.gitignore b/.gitignore index 12f8644..9746858 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ build # other eclipse run +runs # Files from Forge MDK forge*changelog.txt diff --git a/.gitmodules b/.gitmodules index 83f69b0..5c85762 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "linkableapi"] path = linkableapi url = https://github.com/MrTroble/linkableapi + branch = 1.21-neoforge diff --git a/build.gradle b/build.gradle index 3b105e4..0882b0f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,12 @@ -buildscript { - repositories { - maven { url = 'https://files.minecraftforge.net/maven' } - maven { url "https://plugins.gradle.org/m2/" } - jcenter() - mavenCentral() - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '6.0.+', changing: true - classpath "gradle.plugin.com.matthewprenger:CurseGradle:1.4.0" - } +plugins { + id 'java-library' + id 'eclipse' + id 'maven-publish' + id 'net.neoforged.gradle.userdev' version '7.0.171' + id 'com.matthewprenger.cursegradle' version '1.4.0' } - -apply plugin: 'net.minecraftforge.gradle' -apply plugin: 'eclipse' -apply plugin: 'maven-publish' -apply plugin: "com.matthewprenger.cursegradle" -sourceSets{ +sourceSets { main { java { srcDirs("linkableapi/src/") @@ -34,56 +24,45 @@ curseforge { changelog = file('changelog.md') changelogType = 'markdown' releaseType = 'release' - addGameVersion 'Java 17' + addGameVersion 'Java 21' } } def ver = System.getenv("APPVEYOR_BUILD_VERSION") if(ver == null) - ver = "dev" + ver = "0.0" version = ver group = 'com.troblecodings' -archivesBaseName = 'TC-Redstone-1.20.1' +base.archivesName = 'TC-Redstone-1.21.1' -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) -minecraft { - mappings channel: 'official', version: '1.20.1' +runs { + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + systemProperty 'forge.logging.console.level', 'debug' + modSource project.sourceSets.main + } - runs { - client { - workingDirectory project.file('run') - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - property 'forge.logging.console.level', 'debug' - - mods { - gircredstone { - source sourceSets.main - } - } - } + client { + // configured as client + } - server { - workingDirectory project.file('run') - property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' - property 'forge.logging.console.level', 'debug' - - mods { - gircredstone { - source sourceSets.main - } - } - } + server { + arguments '--nogui' } } repositories { - + maven { + name = 'NeoForged' + url = 'https://maven.neoforged.net/releases' + } } dependencies { - minecraft 'net.minecraftforge:forge:1.20.1-47.2.0' + implementation "net.neoforged:neoforge:${neoforge_version}" } jar { @@ -100,7 +79,6 @@ jar { } } -jar.finalizedBy('reobfJar') publishing { publications { mavenJava(MavenPublication) { diff --git a/changelog.md b/changelog.md index 6072f17..58db2fd 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,17 @@ # Changelog -## [1.20.1 - 3.2.2] +## [1.21 - 3.2.3] +* port 1.21 + +## [1.20.4 - 3.2.3] + +* feat: add item damage +* ref: update linkable api + +## [1.20.4 - 3.2.2] + +* port 1.20.4 * rem: debug output ## [1.20.1-3.2.1] diff --git a/gradle.properties b/gradle.properties index 878bf1f..7beebc4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,6 @@ # 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. org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false \ No newline at end of file +org.gradle.daemon=false + +neoforge_version=21.1.196 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180..c1962a7 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 fae0804..e5b2968 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +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.10-all.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index c53aefa..aeb74cb 100644 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: # * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». # # Important for patching: # @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -143,12 +140,16 @@ fi 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 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,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 @@ -205,6 +210,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +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 diff --git a/linkableapi b/linkableapi index 46583ac..d39140f 160000 --- a/linkableapi +++ b/linkableapi @@ -1 +1 @@ -Subproject commit 46583ac0aa18f98cfd2fb38e18064e3586e54c4b +Subproject commit d39140fa7b95aa8df925c373f89563ad18cd30f9 diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..ec41fdf --- /dev/null +++ b/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven { + name = 'NeoForged' + url = 'https://maven.neoforged.net/releases' + } + } +} + +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' +} diff --git a/src/main/java/com/troblecodings/tcredstone/GIRCRedstoneMain.java b/src/main/java/com/troblecodings/tcredstone/GIRCRedstoneMain.java index 17cd0f4..f6f7e85 100644 --- a/src/main/java/com/troblecodings/tcredstone/GIRCRedstoneMain.java +++ b/src/main/java/com/troblecodings/tcredstone/GIRCRedstoneMain.java @@ -5,13 +5,21 @@ import com.troblecodings.tcredstone.init.GIRCInit; -import net.minecraftforge.fml.common.Mod; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.codec.ByteBufCodecs; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.common.Mod; @Mod(GIRCRedstoneMain.MODID) public class GIRCRedstoneMain { - public GIRCRedstoneMain() { - GIRCInit.init(); + public static final DataComponentType COMPOUND_DATA = + DataComponentType.builder().persistent(CompoundTag.CODEC) + .networkSynchronized(ByteBufCodecs.COMPOUND_TAG).build(); + + public GIRCRedstoneMain(final IEventBus modEventBus) { + GIRCInit.init(modEventBus); } public static final Logger LOGGER = LogManager.getLogger(); diff --git a/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneAcceptor.java b/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneAcceptor.java index 3307587..ff79d39 100644 --- a/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneAcceptor.java +++ b/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneAcceptor.java @@ -25,12 +25,6 @@ public boolean isSignalSource(final BlockState blockState) { @Override public int getSignal(final BlockState blockState, final BlockGetter world, final BlockPos pos, final Direction direction) { - return this.getDirectSignal(blockState, world, pos, direction); - } - - @Override - public int getDirectSignal(final BlockState blockState, final BlockGetter world, - final BlockPos pos, final Direction direction) { return blockState.getValue(POWER) ? 15 : 0; } diff --git a/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneEmitter.java b/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneEmitter.java index 4d69a91..0d6a0b7 100644 --- a/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneEmitter.java +++ b/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneEmitter.java @@ -6,8 +6,9 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; @@ -22,12 +23,13 @@ public BlockRedstoneEmitter(final Properties properties) { } @Override - public InteractionResult use(final BlockState state, final Level world, final BlockPos pos, - final Player player, final InteractionHand hand, final BlockHitResult hit) { + public ItemInteractionResult useItemOn(final ItemStack stack, final BlockState state, + final Level world, final BlockPos pos, final Player player, final InteractionHand hand, + final BlockHitResult hit) { if (world.isClientSide) - return InteractionResult.PASS; + return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION; if (player.getItemInHand(hand).getItem().equals(GIRCInit.RS_LINKER.get())) - return InteractionResult.PASS; + return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION; final BlockEntity entity = world.getBlockEntity(pos); if (entity instanceof TileRedstoneEmitter) { final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity; @@ -44,9 +46,9 @@ public InteractionResult use(final BlockState state, final Level world, final Bl linkedpos.getZ()); } } - return InteractionResult.SUCCESS; + return ItemInteractionResult.SUCCESS; } - return InteractionResult.FAIL; + return ItemInteractionResult.FAIL; } @Override diff --git a/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneMultiEmitter.java b/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneMultiEmitter.java index 88a1923..1513d5f 100644 --- a/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneMultiEmitter.java +++ b/src/main/java/com/troblecodings/tcredstone/block/BlockRedstoneMultiEmitter.java @@ -8,8 +8,9 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -28,12 +29,13 @@ public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) { } @Override - public InteractionResult use(final BlockState state, final Level world, final BlockPos pos, - final Player player, final InteractionHand hand, final BlockHitResult hit) { + public ItemInteractionResult useItemOn(final ItemStack stack, final BlockState state, + final Level world, final BlockPos pos, final Player player, final InteractionHand hand, + final BlockHitResult hit) { if (world.isClientSide) - return InteractionResult.PASS; + return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION; if (player.getItemInHand(hand).getItem().equals(GIRCInit.RS_LINKER.get())) - return InteractionResult.PASS; + return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION; final BlockEntity entity = world.getBlockEntity(pos); if (entity instanceof TileRedstoneMultiEmitter) { final TileRedstoneMultiEmitter emitter = (TileRedstoneMultiEmitter) entity; @@ -50,9 +52,9 @@ public InteractionResult use(final BlockState state, final Level world, final Bl blockpos.getX(), blockpos.getY(), blockpos.getZ())); } } - return InteractionResult.SUCCESS; + return ItemInteractionResult.SUCCESS; } - return InteractionResult.FAIL; + return ItemInteractionResult.FAIL; } @Override diff --git a/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java b/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java index e6b8be8..39e311e 100644 --- a/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java +++ b/src/main/java/com/troblecodings/tcredstone/init/GIRCInit.java @@ -13,6 +13,9 @@ import com.troblecodings.tcredstone.tile.TileRedstoneMultiEmitter; import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; @@ -21,61 +24,59 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.RegisterEvent; public class GIRCInit { - public static final DeferredRegister ITEM_REGISTRY = DeferredRegister - .create(ForgeRegistries.ITEMS, GIRCRedstoneMain.MODID); - public static final DeferredRegister BLOCK_REGISTRY = DeferredRegister - .create(ForgeRegistries.BLOCKS, GIRCRedstoneMain.MODID); - public static final DeferredRegister> TILEENTITY_REGISTRY = DeferredRegister - .create(ForgeRegistries.BLOCK_ENTITY_TYPES, GIRCRedstoneMain.MODID); + public static final DeferredRegister ITEM_REGISTRY = + DeferredRegister.create(Registries.ITEM, GIRCRedstoneMain.MODID); + public static final DeferredRegister BLOCK_REGISTRY = + DeferredRegister.create(Registries.BLOCK, GIRCRedstoneMain.MODID); + public static final DeferredRegister> TILEENTITY_REGISTRY = + DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, GIRCRedstoneMain.MODID); - public static final RegistryObject RS_ACCEPTOR = internalRegisterBlock("acceptor", - () -> new BlockRedstoneAcceptor(BlockBehaviour.Properties.of() //TODO Material.METAL + public static final DeferredHolder RS_ACCEPTOR = internalRegisterBlock("acceptor", + () -> new BlockRedstoneAcceptor(BlockBehaviour.Properties.of() // TODO Material.METAL .strength(1.5f, 6.0f).requiresCorrectToolForDrops())); - public static final RegistryObject RS_EMITTER = internalRegisterBlock("emitter", - () -> new BlockRedstoneEmitter(BlockBehaviour.Properties.of() //TODO Material.METAL + public static final DeferredHolder RS_EMITTER = internalRegisterBlock("emitter", + () -> new BlockRedstoneEmitter(BlockBehaviour.Properties.of() // TODO Material.METAL .strength(1.5f, 6.0f).requiresCorrectToolForDrops())); - public static final RegistryObject RS_MULTI_EMITTER = internalRegisterBlock( - "multiemitter", () -> new BlockRedstoneMultiEmitter(BlockBehaviour.Properties - .of().strength(1.5f, 6.0f).requiresCorrectToolForDrops())); //TODO Material.METAL + public static final DeferredHolder RS_MULTI_EMITTER = internalRegisterBlock( + "multiemitter", () -> new BlockRedstoneMultiEmitter(BlockBehaviour.Properties.of() + .strength(1.5f, 6.0f).requiresCorrectToolForDrops())); // TODO Material.METAL public static boolean acceptAcceptor(final Level level, final BlockPos pos) { return level.getBlockState(pos).getBlock() instanceof BlockRedstoneAcceptor; } - public static final RegistryObject RS_LINKER = ITEM_REGISTRY.register("linker", - () -> new Linkingtool(null, GIRCInit::acceptAcceptor)); - public static final RegistryObject RS_MULTILINKER = ITEM_REGISTRY.register("multilinker", - () -> new MultiLinkingTool(null, GIRCInit::acceptAcceptor)); - public static final RegistryObject REMOTE_ACTIVATOR = ITEM_REGISTRY.register("activator", - () -> new RemoteActivator()); + public static final DeferredHolder RS_LINKER = + ITEM_REGISTRY.register("linker", () -> new Linkingtool(null, GIRCInit::acceptAcceptor)); + public static final DeferredHolder RS_MULTILINKER = ITEM_REGISTRY.register( + "multilinker", () -> new MultiLinkingTool(null, GIRCInit::acceptAcceptor)); + public static final DeferredHolder REMOTE_ACTIVATOR = ITEM_REGISTRY.register( + "activator", () -> new RemoteActivator(null, GIRCInit::acceptAcceptor)); - public static final RegistryObject> EMITER_TILE = TILEENTITY_REGISTRY - .register("emitter", () -> BlockEntityType.Builder + public static final DeferredHolder, BlockEntityType> EMITER_TILE = + TILEENTITY_REGISTRY.register("emitter", () -> BlockEntityType.Builder .of(TileRedstoneEmitter::new, RS_EMITTER.get()).build(null)); - public static final RegistryObject> MULTI_EMITER_TILE = TILEENTITY_REGISTRY - .register("multiemitter", () -> BlockEntityType.Builder + public static final DeferredHolder, BlockEntityType> MULTI_EMITER_TILE = + TILEENTITY_REGISTRY.register("multiemitter", () -> BlockEntityType.Builder .of(TileRedstoneMultiEmitter::new, RS_MULTI_EMITTER.get()).build(null)); - private static final RegistryObject internalRegisterBlock(final String name, + private static final DeferredHolder internalRegisterBlock(final String name, final Supplier sup) { - final RegistryObject registerObject = BLOCK_REGISTRY.register(name, sup); + final DeferredHolder registerObject = BLOCK_REGISTRY.register(name, sup); ITEM_REGISTRY.register(name, () -> new BlockItem(registerObject.get(), new Properties())); return registerObject; } - public static void init() { - final IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); + public static void init(final IEventBus bus) { bus.register(GIRCInit.class); ITEM_REGISTRY.register(bus); BLOCK_REGISTRY.register(bus); @@ -85,8 +86,17 @@ public static void init() { @SubscribeEvent public static void onCreativeTabs(final BuildCreativeModeTabContentsEvent event) { if (event.getTabKey().equals(CreativeModeTabs.REDSTONE_BLOCKS)) { - ITEM_REGISTRY.getEntries().forEach(event::accept); + ITEM_REGISTRY.getEntries().forEach(holder -> event.accept(holder.get())); } } + @SubscribeEvent + public static void registerDataComponents(final RegisterEvent event) { + event.register(BuiltInRegistries.DATA_COMPONENT_TYPE.key(), registry -> { + registry.register( + ResourceLocation.fromNamespaceAndPath(GIRCRedstoneMain.MODID, "compound_data"), + GIRCRedstoneMain.COMPOUND_DATA); + }); + } + } diff --git a/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java b/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java index 7136ca3..43b9a91 100644 --- a/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java +++ b/src/main/java/com/troblecodings/tcredstone/item/RemoteActivator.java @@ -1,7 +1,10 @@ package com.troblecodings.tcredstone.item; +import java.util.Optional; +import java.util.function.BiPredicate; + import com.troblecodings.linkableapi.Linkingtool; -import com.troblecodings.tcredstone.init.GIRCInit; +import com.troblecodings.tcredstone.GIRCRedstoneMain; import com.troblecodings.tcredstone.tile.TileRedstoneEmitter; import net.minecraft.core.BlockPos; @@ -10,25 +13,33 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; public class RemoteActivator extends Linkingtool { - public RemoteActivator() { - super(null, GIRCInit::acceptAcceptor, _u1 -> false); + public RemoteActivator(final CreativeModeTab tab, + final BiPredicate predicate) { + super(tab, predicate, _u -> false); } @Override public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { final ItemStack itemstack = player.getItemInHand(hand); - if (!hand.equals(InteractionHand.MAIN_HAND) || level.isClientSide) - return InteractionResultHolder.pass(itemstack); - final CompoundTag comp = itemstack.getTag(); - final BlockPos linkpos = NbtUtils.readBlockPos(comp); - final boolean state = TileRedstoneEmitter.redstoneUpdate(linkpos, level); - message(player, "ra.state", String.valueOf(state)); + final CompoundTag tag = itemstack.get(GIRCRedstoneMain.COMPOUND_DATA); // TODO + if (tag != null) { + if (!hand.equals(InteractionHand.MAIN_HAND) || level.isClientSide) + return InteractionResultHolder.pass(itemstack); + final CompoundTag comp = getOrCreateForStack(itemstack); + if (comp.contains(LINKINGTOOL_TAG)) { + final Optional linkpos = NbtUtils.readBlockPos(comp, LINKINGTOOL_TAG); + final boolean state = TileRedstoneEmitter.redstoneUpdate(linkpos, level); + message(player, "ra.state", String.valueOf(state)); + return InteractionResultHolder.success(itemstack); + } + } return InteractionResultHolder.success(itemstack); } diff --git a/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneEmitter.java b/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneEmitter.java index 1748716..fa2c864 100644 --- a/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneEmitter.java +++ b/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneEmitter.java @@ -1,10 +1,13 @@ package com.troblecodings.tcredstone.tile; +import java.util.Optional; + import com.troblecodings.linkableapi.ILinkableTile; import com.troblecodings.tcredstone.block.BlockRedstoneAcceptor; import com.troblecodings.tcredstone.init.GIRCInit; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup.Provider; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; @@ -33,30 +36,29 @@ public static CompoundTag writeBlockPosToNBT(final BlockPos pos, final CompoundT public static BlockPos readBlockPosFromNBT(final CompoundTag compound) { if (compound != null && compound.contains(ID_X) && compound.contains(ID_Y) - && compound.contains(ID_Z)) { + && compound.contains(ID_Z)) return new BlockPos(compound.getInt(ID_X), compound.getInt(ID_Y), compound.getInt(ID_Z)); - } return null; } @Override - public void load(final CompoundTag compound) { - super.load(compound); + protected void loadAdditional(final CompoundTag compound, final Provider provider) { + super.loadAdditional(compound, provider); this.linkedpos = readBlockPosFromNBT(compound); } @Override - protected void saveAdditional(final CompoundTag compound) { - super.saveAdditional(compound); + protected void saveAdditional(final CompoundTag compound, final Provider provider) { + super.saveAdditional(compound, provider); writeBlockPosToNBT(linkedpos, compound); } @Override - public boolean link(final BlockPos pos) { + public boolean link(final Optional pos) { if (pos == null) return false; - this.linkedpos = pos; + this.linkedpos = pos.get(); return true; } @@ -87,12 +89,13 @@ public static boolean redstoneUpdate(final boolean enabled, final BlockPos linke return enabled; } - public static boolean redstoneUpdate(final BlockPos linkedpos, final Level level) { - if (linkedpos != null) { - final BlockState state = level.getBlockState(linkedpos); + public static boolean redstoneUpdate(final Optional linkpos, final Level level) { + if (linkpos != null) { + final BlockState state = level.getBlockState(linkpos.get()); if (state.getBlock() instanceof BlockRedstoneAcceptor) { final boolean newState = !state.getValue(BlockRedstoneAcceptor.POWER); - level.setBlock(linkedpos, state.setValue(BlockRedstoneAcceptor.POWER, newState), 3); + level.setBlock(linkpos.get(), state.setValue(BlockRedstoneAcceptor.POWER, newState), + 3); return newState; } } diff --git a/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneMultiEmitter.java b/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneMultiEmitter.java index 0058fc4..3c781e4 100644 --- a/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneMultiEmitter.java +++ b/src/main/java/com/troblecodings/tcredstone/tile/TileRedstoneMultiEmitter.java @@ -2,15 +2,20 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import com.troblecodings.linkableapi.ILinkableTile; +import com.troblecodings.linkableapi.MultiLinkingTool; import com.troblecodings.tcredstone.block.BlockRedstoneAcceptor; import com.troblecodings.tcredstone.init.GIRCInit; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup.Provider; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.IntArrayTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtUtils; +import net.minecraft.nbt.Tag; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -30,7 +35,7 @@ public CompoundTag writeBlockPosToNBT(final List pos, final CompoundTa final ListTag list = new ListTag(); listOfPositions.forEach(blockpos -> { - final CompoundTag item = NbtUtils.writeBlockPos(blockpos); + final Tag item = NbtUtils.writeBlockPos(blockpos); list.add(item); }); compound.put(LINKED_POS_LIST, list); @@ -43,8 +48,8 @@ public List readBlockPosFromNBT(final CompoundTag compound) { if (list != null) { listOfPositions.clear(); list.forEach(pos -> { - final CompoundTag item = (CompoundTag) pos; - listOfPositions.add(NbtUtils.readBlockPos(item)); + listOfPositions.add( + MultiLinkingTool.readBlockPos((IntArrayTag) pos, LINKED_POS_LIST).get()); }); return listOfPositions; } @@ -57,9 +62,9 @@ public boolean hasLink() { } @Override - public boolean link(final BlockPos pos) { - if (pos != null && !listOfPositions.contains(pos)) { - listOfPositions.add(pos); + public boolean link(final Optional pos) { + if (pos != null && !listOfPositions.contains(pos.get())) { + listOfPositions.add(pos.get()); return true; } return false; @@ -78,14 +83,14 @@ public List getLinkedPos() { } @Override - public void load(final CompoundTag compound) { - super.load(compound); + public void loadAdditional(final CompoundTag compound, final Provider provider) { + super.loadAdditional(compound, provider); this.listOfPositions = readBlockPosFromNBT(compound); } @Override - protected void saveAdditional(final CompoundTag compound) { - super.saveAdditional(compound); + protected void saveAdditional(final CompoundTag compound, final Provider provider) { + super.saveAdditional(compound, provider); writeBlockPosToNBT(listOfPositions, compound); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 78% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml index 51b01c9..0abc453 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[46,)" +loaderVersion="[1,)" issueTrackerURL="https://github.com/German-Immersive-Railroading-Community/GIRC-Redstone/issues" license="Apache License Version 2.0" @@ -12,15 +12,15 @@ authors="MrTroble, Jeronimo" description="Works in unloaded Chunks TM." [[dependencies.gircredstone]] - modId="forge" - mandatory=true - versionRange="[46,)" + modId="neoforge" + type="required" + versionRange="[21.1,)" ordering="NONE" side="BOTH" [[dependencies.gircredstone]] modId="minecraft" - mandatory=true - versionRange="[1.20,)" + type="required" + versionRange="[1.21.1,)" ordering="NONE" side="BOTH" diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index d81f1da..d1f934e 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,8 +1,6 @@ { "pack": { - "description": "TC Wireless-Redstone", - "pack_format": 15, - "forge:resource_pack_format": 15, - "forge:data_pack_format": 15 + "description": "TC Redstone", + "pack_format": 34 } }