Add forge registry for container types, expose ScreenManager.registerFactory

This commit is contained in:
tterrag 2019-06-09 00:19:17 -04:00
parent 2d32929dc5
commit 892fea3df9
7 changed files with 152 additions and 2 deletions

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/inventory/container/ContainerType.java
+++ b/net/minecraft/inventory/container/ContainerType.java
@@ -5,7 +5,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-public class ContainerType<T extends Container> {
+public class ContainerType<T extends Container> extends net.minecraftforge.registries.ForgeRegistryEntry<ContainerType<?>> {
public static final ContainerType<ChestContainer> field_221507_a = func_221505_a("generic_9x1", ChestContainer::func_216986_a);
public static final ContainerType<ChestContainer> field_221508_b = func_221505_a("generic_9x2", ChestContainer::func_216987_b);
public static final ContainerType<ChestContainer> field_221509_c = func_221505_a("generic_9x3", ChestContainer::func_216988_c);

View file

@ -69,6 +69,15 @@
return DimensionType.OVERWORLD;
});
public static final DefaultedRegistry<PaintingType> field_212620_i = func_222933_a("motive", "kebab", () -> {
@@ -148,7 +152,7 @@
public static final Registry<IJigsawDeserializer> field_218365_F = func_222935_a("structure_pool_element", () -> {
return IJigsawDeserializer.field_214931_e;
});
- public static final Registry<ContainerType<?>> field_218366_G = func_222935_a("menu", () -> {
+ public static final Registry<ContainerType<?>> field_218366_G = forge("menu", ContainerType.class, () -> {
return ContainerType.field_221514_h;
});
public static final Registry<IRecipeType<?>> field_218367_H = func_222935_a("recipe_type", () -> {
@@ -230,6 +234,14 @@
return ((MutableRegistry<T>)p_218343_0_).func_218382_a(p_218343_1_, new ResourceLocation(p_218343_2_), p_218343_3_);
}

View file

@ -22,6 +22,7 @@ package net.minecraftforge.registries;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.util.registry.Bootstrap;
import net.minecraft.item.Item;
import net.minecraft.potion.Effect;
@ -48,8 +49,9 @@ public class ForgeRegistries
public static final IForgeRegistry<SoundEvent> SOUND_EVENTS = RegistryManager.ACTIVE.getRegistry(SoundEvent.class);
public static final IForgeRegistry<Potion> POTION_TYPES = RegistryManager.ACTIVE.getRegistry(Potion.class);
public static final IForgeRegistry<Enchantment> ENCHANTMENTS = RegistryManager.ACTIVE.getRegistry(Enchantment.class);
public static final IForgeRegistry<EntityType<?>> ENTITIES = RegistryManager.ACTIVE.getRegistry(EntityType.class); //Untyped casys needed to fix javac issues.
public static final IForgeRegistry<EntityType<?>> ENTITIES = RegistryManager.ACTIVE.getRegistry(EntityType.class);
public static final IForgeRegistry<TileEntityType<?>> TILE_ENTITIES = RegistryManager.ACTIVE.getRegistry(TileEntityType.class);
public static final IForgeRegistry<ContainerType<?>> CONTAINERS = RegistryManager.ACTIVE.getRegistry(ContainerType.class);
public static final IForgeRegistry<ModDimension> MOD_DIMENSIONS = RegistryManager.ACTIVE.getRegistry(ModDimension.class);
public static final IForgeRegistry<DataSerializerEntry> DATA_SERIALIZERS = RegistryManager.ACTIVE.getRegistry(DataSerializerEntry.class);

View file

@ -26,6 +26,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.Item;
import net.minecraft.item.BlockItem;
import net.minecraft.network.datasync.IDataSerializer;
@ -88,6 +89,7 @@ public class GameData
public static final ResourceLocation ENCHANTMENTS = new ResourceLocation("minecraft:enchantments");
public static final ResourceLocation ENTITIES = new ResourceLocation("minecraft:entities");
public static final ResourceLocation TILEENTITIES = new ResourceLocation("minecraft:tileentities");
public static final ResourceLocation CONTAINERS = new ResourceLocation("minecraft:containers");
public static final ResourceLocation PROFESSIONS = new ResourceLocation("minecraft:villagerprofessions");
public static final ResourceLocation MODDIMENSIONS = new ResourceLocation("forge:moddimensions");
public static final ResourceLocation SERIALIZERS = new ResourceLocation("minecraft:dataserializers");
@ -126,6 +128,7 @@ public class GameData
makeRegistry(ENCHANTMENTS, Enchantment.class ).create();
makeRegistry(ENTITIES, EntityType.class, new ResourceLocation("pig")).create();
makeRegistry(TILEENTITIES, TileEntityType.class).disableSaving().create();
makeRegistry(CONTAINERS, ContainerType.class).disableSaving().create();
makeRegistry(MODDIMENSIONS, ModDimension.class ).disableSaving().create();
makeRegistry(SERIALIZERS, DataSerializerEntry.class, 256 /*vanilla space*/, MAX_VARINT).disableSaving().disableOverrides().addCallback(SerializerCallbacks.INSTANCE).create();
}

View file

@ -47,6 +47,9 @@ public+f net.minecraft.item.crafting.ShapedRecipes field_77576_b #recipeWidth
public+f net.minecraft.item.crafting.ShapedRecipes field_77577_c #recipeHeight
# ShapelessRecipes
public net.minecraft.item.crafting.ShapelessRecipes field_77579_b #recipeItems
# ContainerType
public net.minecraft.inventory.container.ContainerType <init>(Lnet/minecraft/inventory/container/ContainerType$IFactory;)V
public net.minecraft.inventory.container.ContainerType$IFactory
# RepairContainer
public net.minecraft.inventory.container.RepairContainer field_82856_l #RepairContainer/stackSizeToBeUsedInRepair
# BiomeDecorator
@ -189,6 +192,9 @@ public net.minecraft.entity.MobEntity field_70714_bg #tasks
public net.minecraft.entity.MobEntity field_70715_bh #targetTasks
# ContainerMinecartEntity
public net.minecraft.entity.item.ContainerMinecartEntity field_94112_b #dropContentsWhenDead
# ScreenManager
public net.minecraft.client.gui.ScreenManager func_216911_a(Lnet/minecraft/inventory/container/ContainerType;Lnet/minecraft/client/gui/ScreenManager$IScreenFactory;)V # registerFactory
public net.minecraft.client.gui.ScreenManager$IScreenFactory
# Screen
public net.minecraft.client.gui.screen.Screen field_146297_k # minecraft instance - public because gui's outside access it
# Minecraft

View file

@ -0,0 +1,115 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.misc;
import net.minecraft.block.Blocks;
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.util.Hand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.ObjectHolder;
@Mod("containertypetest")
public class ContainerTypeTest
{
@ObjectHolder("containertypetest:container")
public static final ContainerType<TestContainer> TYPE = null;
public class TestContainer extends Container
{
protected TestContainer(int windowId, PlayerInventory inv)
{
super(TYPE, windowId);
}
@Override
public boolean canInteractWith(PlayerEntity playerIn)
{
return true;
}
}
public class TestGui extends ContainerScreen<TestContainer>
{
public TestGui(TestContainer container, PlayerInventory inv, ITextComponent name)
{
super(container, inv, name);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
drawString(this.font, "Hello World!", mouseX, mouseY, -1);
}
}
public ContainerTypeTest()
{
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(ContainerType.class, this::registerContainers);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
MinecraftForge.EVENT_BUS.addListener(this::onRightClick);
}
private void registerContainers(final RegistryEvent.Register<ContainerType<?>> event)
{
event.getRegistry().register(new ContainerType<TestContainer>(TestContainer::new).setRegistryName("container"));
}
private void setup(FMLClientSetupEvent event)
{
ScreenManager.registerFactory(TYPE, TestGui::new);
}
private void onRightClick(PlayerInteractEvent.RightClickBlock event)
{
if (!event.getWorld().isRemote && event.getHand() == Hand.MAIN_HAND)
{
if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.SPONGE)
{
event.getEntityPlayer().openContainer(new INamedContainerProvider()
{
@Override
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_)
{
return TYPE.func_221506_a(p_createMenu_1_, p_createMenu_2_);
}
@Override
public ITextComponent getDisplayName()
{
return new StringTextComponent("Test");
}
});
}
}
}
}

View file

@ -10,3 +10,7 @@ loaderVersion="[2.0,)"
# modId="forgedebugmodelloaderregistry"
# version="1.0"
# displayName="ModelLoaderRegistryTest"
[[mods]]
modId="containertypetest"
version="1.0"
displayName="ContainerTypeTest"