forked from RebelKeithy/Aquaculture
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move MenuType to DeferredRegister as well
- Loading branch information
1 parent
840af9a
commit cabba20
Showing
4 changed files
with
11 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 8 additions & 22 deletions
30
src/main/java/com/teammetallurgy/aquaculture/init/AquaGuis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,26 @@ | ||
package com.teammetallurgy.aquaculture.init; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.teammetallurgy.aquaculture.Aquaculture; | ||
import com.teammetallurgy.aquaculture.inventory.container.TackleBoxContainer; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import net.minecraft.world.inventory.MenuType; | ||
import net.minecraftforge.common.extensions.IForgeContainerType; | ||
import net.minecraftforge.event.RegistryEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.registries.ObjectHolder; | ||
import net.minecraftforge.fmllegacy.RegistryObject; | ||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
@Mod.EventBusSubscriber(modid = Aquaculture.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) | ||
@ObjectHolder(Aquaculture.MOD_ID) | ||
public class AquaGuis { | ||
public static List<MenuType> CONTAINERS = Lists.newArrayList(); | ||
public static final MenuType<TackleBoxContainer> TACKLE_BOX = register(IForgeContainerType.create((windowID, inv, data) -> { | ||
public static final DeferredRegister<MenuType<?>> MENU_DEFERRED = DeferredRegister.create(ForgeRegistries.CONTAINERS, Aquaculture.MOD_ID); | ||
public static final RegistryObject<MenuType<TackleBoxContainer>> TACKLE_BOX = register(() -> IForgeContainerType.create((windowID, inv, data) -> { | ||
BlockPos pos = data.readBlockPos(); | ||
return new TackleBoxContainer(windowID, pos, inv); | ||
}), "tackle_box"); | ||
|
||
private static <T extends AbstractContainerMenu> MenuType<T> register(@Nonnull MenuType<T> container, @Nonnull String name) { | ||
container.setRegistryName(new ResourceLocation(Aquaculture.MOD_ID, name)); | ||
CONTAINERS.add(container); | ||
return container; | ||
} | ||
|
||
@SubscribeEvent | ||
public static void registerContainers(RegistryEvent.Register<MenuType<?>> event) { | ||
for (MenuType container : CONTAINERS) { | ||
event.getRegistry().register(container); | ||
} | ||
private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> register(@Nonnull Supplier<MenuType<T>> initializer, @Nonnull String name) { | ||
return MENU_DEFERRED.register(name, initializer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters