diff --git a/src/main/java/com/wenxin2/warp_pipes/WarpPipes.java b/src/main/java/com/wenxin2/warp_pipes/WarpPipes.java index b3f64f2..554e0a6 100644 --- a/src/main/java/com/wenxin2/warp_pipes/WarpPipes.java +++ b/src/main/java/com/wenxin2/warp_pipes/WarpPipes.java @@ -7,23 +7,22 @@ import com.wenxin2.warp_pipes.init.ModCreativeTabs; import com.wenxin2.warp_pipes.init.ModRegistry; import com.wenxin2.warp_pipes.init.SoundRegistry; +import net.minecraft.core.registries.Registries; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fluids.FluidType; -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.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.fluids.FluidType; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.NeoForgeRegistries; import org.slf4j.Logger; // The value here should match an entry in the META-INF/mods.toml file @@ -35,38 +34,35 @@ public class WarpPipes // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); // Create a Deferred Register to hold blocks/items which will all be registered under the "warp_pipes" namespace - public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); - public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); - public static final DeferredRegister FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, MODID); - public static final DeferredRegister FLUID_TYPES = DeferredRegister.create(ForgeRegistries.Keys.FLUID_TYPES, MODID); + public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID); + public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID); +// public static final DeferredRegister FLUIDS = DeferredRegister.create(Registries.FLUID, MODID); +// public static final DeferredRegister FLUID_TYPES = DeferredRegister.create(NeoForgeRegistries.FLUID_TYPES, MODID); - public static final DeferredRegister> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, WarpPipes.MODID); - public static final DeferredRegister> MENUS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, WarpPipes.MODID); - public static final DeferredRegister SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, WarpPipes.MODID); + public static final DeferredRegister> BLOCK_ENTITIES = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, WarpPipes.MODID); + public static final DeferredRegister> MENUS = DeferredRegister.create(Registries.MENU, WarpPipes.MODID); + public static final DeferredRegister SOUNDS = DeferredRegister.create(Registries.SOUND_EVENT, WarpPipes.MODID); // Bus for Forge Events - public static final IEventBus FORGE_BUS = MinecraftForge.EVENT_BUS; + public static final IEventBus FORGE_BUS = NeoForge.EVENT_BUS; - public WarpPipes() + public WarpPipes(IEventBus bus, Dist dist) { - IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); - // Register the Deferred Register to the mod event bus so blocks/items get registered - BLOCKS.register(modEventBus); - ITEMS.register(modEventBus); - FLUIDS.register(modEventBus); - FLUID_TYPES.register(modEventBus); - BLOCK_ENTITIES.register(modEventBus); - MENUS.register(modEventBus); - SOUNDS.register(modEventBus); - ModCreativeTabs.TABS.register(modEventBus); + BLOCKS.register(bus); + ITEMS.register(bus); +// FLUIDS.register(bus); +// FLUID_TYPES.register(bus); + BLOCK_ENTITIES.register(bus); + MENUS.register(bus); + SOUNDS.register(bus); + ModCreativeTabs.TABS.register(bus); ModRegistry.init(); SoundRegistry.init(); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - modEventBus.addListener(ClientSetupHandler::registerBlockEntityRenderers); - }); + if (dist.isClient()) + bus.addListener(ClientSetupHandler::registerBlockEntityRenderers); WarpEventHandlers.register(); // PipeBubblesSoundHandler.init(); @@ -74,6 +70,6 @@ public WarpPipes() ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.CONFIG); // Register ourselves for server and other game events we are interested in - MinecraftForge.EVENT_BUS.register(this); + NeoForge.EVENT_BUS.register(this); } } diff --git a/src/main/java/com/wenxin2/warp_pipes/blocks/ClearWarpPipeBlock.java b/src/main/java/com/wenxin2/warp_pipes/blocks/ClearWarpPipeBlock.java index 7c40359..da02d5c 100644 --- a/src/main/java/com/wenxin2/warp_pipes/blocks/ClearWarpPipeBlock.java +++ b/src/main/java/com/wenxin2/warp_pipes/blocks/ClearWarpPipeBlock.java @@ -41,7 +41,7 @@ import net.minecraft.world.phys.shapes.EntityCollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.server.ServerLifecycleHooks; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.jetbrains.annotations.NotNull; public class ClearWarpPipeBlock extends WarpPipeBlock implements EntityBlock, SimpleWaterloggedBlock { diff --git a/src/main/java/com/wenxin2/warp_pipes/init/Config.java b/src/main/java/com/wenxin2/warp_pipes/init/Config.java index 714b9e7..2d0ef23 100644 --- a/src/main/java/com/wenxin2/warp_pipes/init/Config.java +++ b/src/main/java/com/wenxin2/warp_pipes/init/Config.java @@ -4,35 +4,35 @@ import java.util.List; import java.util.function.Predicate; import net.minecraft.world.entity.Entity; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; public class Config { - private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); - public static ForgeConfigSpec CONFIG; + private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder(); + public static ModConfigSpec CONFIG; public static final String CATEGORY_DEBUG = "Debug"; public static final String CATEGORY_CLIENT = "Client"; public static final String CATEGORY_COMMON = "Common"; - public static ForgeConfigSpec.BooleanValue ALLOW_FAST_TRAVEL; - public static ForgeConfigSpec.BooleanValue ALLOW_PIPE_UNWAXING; - public static ForgeConfigSpec.BooleanValue CREATIVE_BUBBLES; - public static ForgeConfigSpec.BooleanValue CREATIVE_CLOSE_PIPES; - public static ForgeConfigSpec.BooleanValue CREATIVE_WATER_SPOUT; - public static ForgeConfigSpec.BooleanValue CREATIVE_WRENCH_PIPE_LINKING; - public static ForgeConfigSpec.BooleanValue DEBUG_PIPE_BUBBLES_SELECTION_BOX; - public static ForgeConfigSpec.BooleanValue DEBUG_WATER_SPOUT_SELECTION_BOX; - public static ForgeConfigSpec.BooleanValue DEBUG_SELECTION_BOX; - public static ForgeConfigSpec.BooleanValue DEBUG_SELECTION_BOX_CREATIVE; - public static ForgeConfigSpec.BooleanValue DISABLE_TEXT; - public static ForgeConfigSpec.BooleanValue TELEPORT_MOBS; - public static ForgeConfigSpec.BooleanValue TELEPORT_NON_MOBS; - public static ForgeConfigSpec.BooleanValue TELEPORT_PLAYERS; - public static ForgeConfigSpec.IntValue WARP_COOLDOWN; - public static ForgeConfigSpec.BooleanValue WARP_COOLDOWN_MESSAGE; - public static ForgeConfigSpec.BooleanValue WARP_COOLDOWN_MESSAGE_TICKS; - public static ForgeConfigSpec.BooleanValue WATER_SPOUTS_BUCKETABLE; + public static ModConfigSpec.BooleanValue ALLOW_FAST_TRAVEL; + public static ModConfigSpec.BooleanValue ALLOW_PIPE_UNWAXING; + public static ModConfigSpec.BooleanValue CREATIVE_BUBBLES; + public static ModConfigSpec.BooleanValue CREATIVE_CLOSE_PIPES; + public static ModConfigSpec.BooleanValue CREATIVE_WATER_SPOUT; + public static ModConfigSpec.BooleanValue CREATIVE_WRENCH_PIPE_LINKING; + public static ModConfigSpec.BooleanValue DEBUG_PIPE_BUBBLES_SELECTION_BOX; + public static ModConfigSpec.BooleanValue DEBUG_WATER_SPOUT_SELECTION_BOX; + public static ModConfigSpec.BooleanValue DEBUG_SELECTION_BOX; + public static ModConfigSpec.BooleanValue DEBUG_SELECTION_BOX_CREATIVE; + public static ModConfigSpec.BooleanValue DISABLE_TEXT; + public static ModConfigSpec.BooleanValue TELEPORT_MOBS; + public static ModConfigSpec.BooleanValue TELEPORT_NON_MOBS; + public static ModConfigSpec.BooleanValue TELEPORT_PLAYERS; + public static ModConfigSpec.IntValue WARP_COOLDOWN; + public static ModConfigSpec.BooleanValue WARP_COOLDOWN_MESSAGE; + public static ModConfigSpec.BooleanValue WARP_COOLDOWN_MESSAGE_TICKS; + public static ModConfigSpec.BooleanValue WATER_SPOUTS_BUCKETABLE; static { diff --git a/src/main/java/com/wenxin2/warp_pipes/init/ModCreativeTabs.java b/src/main/java/com/wenxin2/warp_pipes/init/ModCreativeTabs.java index dee1121..9602e42 100644 --- a/src/main/java/com/wenxin2/warp_pipes/init/ModCreativeTabs.java +++ b/src/main/java/com/wenxin2/warp_pipes/init/ModCreativeTabs.java @@ -1,6 +1,7 @@ package com.wenxin2.warp_pipes.init; import com.wenxin2.warp_pipes.WarpPipes; +import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; @@ -10,16 +11,15 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; -import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; +import net.neoforged.neoforge.registries.DeferredRegister; @Mod.EventBusSubscriber(modid = WarpPipes.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModCreativeTabs { public static final DeferredRegister TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, WarpPipes.MODID); - public static final RegistryObject WARP_PIPES_TAB = TABS.register("warp_pipes_tab", () -> CreativeModeTab.builder() + public static final Registry WARP_PIPES_TAB = TABS.register("warp_pipes_tab", () -> CreativeModeTab.builder() .title(Component.translatable("itemGroup.warp_pipes")) .icon(() -> new ItemStack(ModRegistry.WARP_PIPES.get(DyeColor.GREEN).get())).build()); @@ -30,8 +30,8 @@ public static void addCreative(BuildCreativeModeTabContentsEvent event) { add(event, ModRegistry.CLEAR_WARP_PIPE.get()); - for (RegistryObject pipe : ModRegistry.WARP_PIPES.values()) { - add(event, pipe.get()); + for (Registry pipe : ModRegistry.WARP_PIPES.values()) { + add(event, pipe); } } if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) { @@ -50,7 +50,7 @@ public static void addCreative(BuildCreativeModeTabContentsEvent event) { if (event.getTabKey() == CreativeModeTabs.COLORED_BLOCKS) { add(event, ModRegistry.CLEAR_WARP_PIPE.get()); - for (RegistryObject pipe : ModRegistry.WARP_PIPES.values()) { + for (Registry pipe : ModRegistry.WARP_PIPES.values()) { add(event, pipe.get()); } } @@ -58,7 +58,7 @@ public static void addCreative(BuildCreativeModeTabContentsEvent event) { if (event.getTabKey() == CreativeModeTabs.FUNCTIONAL_BLOCKS) { addAfter(event, Items.RESPAWN_ANCHOR, ModRegistry.CLEAR_WARP_PIPE.get()); - for (RegistryObject pipe : ModRegistry.WARP_PIPES.values()) { + for (Registry pipe : ModRegistry.WARP_PIPES.values()) { addAfter(event, ModRegistry.CLEAR_WARP_PIPE.get(), pipe.get()); } diff --git a/src/main/java/com/wenxin2/warp_pipes/init/ModRegistry.java b/src/main/java/com/wenxin2/warp_pipes/init/ModRegistry.java index 6d5f5bb..38d9013 100644 --- a/src/main/java/com/wenxin2/warp_pipes/init/ModRegistry.java +++ b/src/main/java/com/wenxin2/warp_pipes/init/ModRegistry.java @@ -8,12 +8,16 @@ import com.wenxin2.warp_pipes.blocks.entities.WarpPipeBlockEntity; import com.wenxin2.warp_pipes.inventory.WarpPipeMenu; import com.wenxin2.warp_pipes.items.WrenchItem; +import dev.architectury.registry.registries.RegistrarManager; import java.util.Arrays; import java.util.EnumMap; import java.util.function.Supplier; import java.util.stream.Stream; import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.resources.RegistryOps; import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; @@ -27,20 +31,23 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.PushReaction; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.registries.RegistryObject; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.registries.DeferredBlock; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredItem; +import net.neoforged.neoforge.registries.DeferredRegister; @Mod.EventBusSubscriber(modid = WarpPipes.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModRegistry { - public static final EnumMap> WARP_PIPES = + public static final EnumMap> WARP_PIPES = new EnumMap<>(DyeColor.class); - public static final RegistryObject PIPE_WRENCH; - public static final RegistryObject CLEAR_WARP_PIPE; - public static final RegistryObject PIPE_BUBBLES; - public static final RegistryObject WATER_SPOUT; + public static final DeferredItem PIPE_WRENCH; + public static final DeferredBlock CLEAR_WARP_PIPE; + public static final DeferredBlock PIPE_BUBBLES; + public static final DeferredBlock WATER_SPOUT; - public static final RegistryObject> WARP_PIPE_BLOCK_ENTITY; - public static final RegistryObject> WARP_PIPE_MENU; + public static final DeferredHolder, BlockEntityType> WARP_PIPE_BLOCK_ENTITY; + public static final DeferredHolder, MenuType> WARP_PIPE_MENU; static { @@ -72,29 +79,30 @@ public class ModRegistry { WARP_PIPE_BLOCK_ENTITY = WarpPipes.BLOCK_ENTITIES.register("warp_pipe", () -> BlockEntityType.Builder.of(WarpPipeBlockEntity::new, - Stream.concat(WARP_PIPES.values().stream().map(RegistryObject::get), + Stream.concat(WARP_PIPES.values().stream().map(DeferredBlock::get), Stream.of(CLEAR_WARP_PIPE.get())).toArray(Block[]::new)) .build(null)); WARP_PIPE_MENU = WarpPipes.MENUS.register("warp_pipe", () -> new MenuType<>(WarpPipeMenu::new, FeatureFlags.REGISTRY.allFlags())); } - public static RegistryObject registerBlock(String name, Supplier block) + public static DeferredBlock registerBlock(String name, Supplier block) { - RegistryObject blocks = WarpPipes.BLOCKS.register(name, block); + DeferredBlock blocks = WarpPipes.BLOCKS.register(name, block); WarpPipes.ITEMS.register(name, () -> new BlockItem(blocks.get(), new Item.Properties())); return blocks; } - public static RegistryObject registerNoItemBlock(String name, Supplier block) + public static DeferredBlock registerNoItemBlock(String name, Supplier block) { - RegistryObject blocks = WarpPipes.BLOCKS.register(name, block); + DeferredBlock blocks = WarpPipes.BLOCKS.register(name, block); return blocks; } - public static RegistryObject registerItem(String name, Supplier item) + public static DeferredItem registerItem(String name, Supplier item) { - return WarpPipes.ITEMS.register(name, item); + DeferredItem items = WarpPipes.ITEMS.register(name, item); + return items; } private static boolean always(BlockState state, BlockGetter block, BlockPos pos)