mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Redesign CreativeTab collection event to be a lot more straight forward. (#9198)
This commit is contained in:
1 parent
4cf5508e04
commit
ec3abdea14
41 files changed
+696
-512
No files matched your search
@@ -19,8 +19,6 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Test mod that demos disabling ambient occlusion on specific faces of "elements" models.
|
||||
*/
|
||||
@@ -50,8 +48,17 @@ public class AmbientOcclusionElementsTest
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
BLOCKS.register(modEventBus);
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.BUILDING_BLOCKS,
|
||||
AO_BLOCK_SHADE_ITEM.get(), AO_BLOCK_NO_SHADE_ITEM.get(), NO_AO_BLOCK_SHADE_ITEM.get(), NO_AO_BLOCK_NO_SHADE_ITEM.get()));
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.BUILDING_BLOCKS)
|
||||
{
|
||||
event.accept(AO_BLOCK_SHADE_ITEM);
|
||||
event.accept(AO_BLOCK_NO_SHADE_ITEM);
|
||||
event.accept(NO_AO_BLOCK_SHADE_ITEM);
|
||||
event.accept(NO_AO_BLOCK_NO_SHADE_ITEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,9 +48,17 @@ public class CustomArmorModelTest
|
||||
{
|
||||
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modBus);
|
||||
modBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
modBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.INGREDIENTS,
|
||||
RED_LEGGINGS.get(), ENDERMAN_CHESTPLATE.get(), ENDERMAN_BOOTS.get()));
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
{
|
||||
event.accept(RED_LEGGINGS);
|
||||
event.accept(ENDERMAN_CHESTPLATE);
|
||||
event.accept(ENDERMAN_BOOTS);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TintedArmorItem extends ArmorItem
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(CustomTooltipTest.ID)
|
||||
public class CustomTooltipTest
|
||||
@@ -65,10 +64,16 @@ public class CustomTooltipTest
|
||||
modEventBus.register(ClientModBusEventHandler.class);
|
||||
}
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.INGREDIENTS, CUSTOM_ITEM.get()));
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(CUSTOM_ITEM);
|
||||
}
|
||||
|
||||
static record CustomTooltip(int color) implements TooltipComponent
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,7 +37,12 @@ public class EmissiveElementsTest
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
BLOCKS.register(modEventBus);
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.BUILDING_BLOCKS, TEST_BLOCK_ITEM.get()));
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.BUILDING_BLOCKS)
|
||||
event.accept(TEST_BLOCK_ITEM);
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,6 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(CompositeModelTest.MODID)
|
||||
public class CompositeModelTest
|
||||
{
|
||||
@@ -87,7 +85,12 @@ public class CompositeModelTest
|
||||
|
||||
BLOCKS.register(modEventBus);
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.INGREDIENTS, composite_item.get()));
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(composite_item);
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,6 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/*
|
||||
* Test mod for the custom transform types feature.
|
||||
* This test mod adds an item that should be held in the main hand, while another item is in the offhand.
|
||||
@@ -129,13 +127,13 @@ public class CustomTransformTypeTest
|
||||
BLOCKS.register(modBus);
|
||||
BLOCK_ENTITY_TYPES.register(modBus);
|
||||
ITEMS.register(modBus);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.INGREDIENTS) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(ITEM_HANGER_ITEM.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(ITEM_HANGER_ITEM);
|
||||
}
|
||||
|
||||
public void gatherData(GatherDataEvent event)
|
||||
|
||||
@@ -15,8 +15,6 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(DynBucketModelTest.MODID)
|
||||
public class DynBucketModelTest
|
||||
{
|
||||
@@ -33,14 +31,16 @@ public class DynBucketModelTest
|
||||
{
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modEventBus);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.INGREDIENTS) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(DRIP_BUCKET.get());
|
||||
output.accept(LAVA_OBSIDIAN.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
{
|
||||
event.accept(DRIP_BUCKET);
|
||||
event.accept(LAVA_OBSIDIAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,12 +88,13 @@ public class MegaModelTest
|
||||
BLOCKS.register(modEventBus);
|
||||
ITEMS.register(modEventBus);
|
||||
BLOCK_ENTITIES.register(modEventBus);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.BUILDING_BLOCKS) {
|
||||
onBuildContents.register((p_259204_, p_259752_, p_260123_) -> p_259752_.accept(TEST_BLOCK_ITEM.get()));
|
||||
}
|
||||
});
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.BUILDING_BLOCKS)
|
||||
event.accept(TEST_BLOCK_ITEM);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
|
||||
@@ -12,17 +12,14 @@ import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.event.CreativeModeTabEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
@Mod(MultiLayerModelTest.MODID)
|
||||
public class MultiLayerModelTest
|
||||
@@ -32,44 +29,34 @@ public class MultiLayerModelTest
|
||||
public static final String VERSION = "0.0";
|
||||
|
||||
private static final String blockName = "test_layer_block";
|
||||
private static final ResourceLocation blockId = new ResourceLocation(MODID, blockName);
|
||||
@ObjectHolder(registryName = "block", value = blockName)
|
||||
public static final Block TEST_BLOCK = null;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class Registration
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
private static final RegistryObject<Block> TEST_BLOCK = BLOCKS.register(blockName, () -> new Block(Block.Properties.of(Material.WOOD).noOcclusion()));
|
||||
private static final RegistryObject<Item> TEST_BLOCK_ITEM = ITEMS.register(blockName, () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties()));
|
||||
|
||||
public MultiLayerModelTest()
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegisterEvent event)
|
||||
{
|
||||
if (!ENABLED || !event.getRegistryKey().equals(ForgeRegistries.Keys.BLOCKS))
|
||||
return;
|
||||
event.register(ForgeRegistries.Keys.BLOCKS, blockId, () -> new Block(Block.Properties.of(Material.WOOD).noOcclusion()));
|
||||
}
|
||||
if (!ENABLED)
|
||||
return;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegisterEvent event)
|
||||
{
|
||||
if (!ENABLED || !event.getRegistryKey().equals(ForgeRegistries.Keys.ITEMS))
|
||||
return;
|
||||
event.register(ForgeRegistries.Keys.ITEMS, blockId, () -> new BlockItem(TEST_BLOCK, new Item.Properties()));
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.INGREDIENTS) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(TEST_BLOCK.asItem());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
BLOCKS.register(modEventBus);
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener(this::clientSetup);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void clientSetup(FMLClientSetupEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
return;
|
||||
ItemBlockRenderTypes.setRenderLayer(TEST_BLOCK, (layer) -> {
|
||||
return layer == RenderType.solid() || layer == RenderType.translucent();
|
||||
});
|
||||
}
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(TEST_BLOCK);
|
||||
}
|
||||
|
||||
private void clientSetup(FMLClientSetupEvent event)
|
||||
{
|
||||
ItemBlockRenderTypes.setRenderLayer(TEST_BLOCK.get(), (layer) -> {
|
||||
return layer == RenderType.solid() || layer == RenderType.translucent();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.debug.client.model;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.ModelBaker;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -48,7 +47,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
@@ -127,20 +126,22 @@ public class NewModelLoaderTest
|
||||
|
||||
modEventBus.addListener(this::modelRegistry);
|
||||
modEventBus.addListener(this::datagen);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.INGREDIENTS) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(obj_item.get());
|
||||
output.accept(custom_transforms.get());
|
||||
output.accept(custom_vanilla_loader.get());
|
||||
output.accept(custom_loader.get());
|
||||
output.accept(item_layers.get());
|
||||
output.accept(separate_perspective.get());
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
{
|
||||
Arrays.asList(
|
||||
obj_item,
|
||||
custom_transforms,
|
||||
custom_vanilla_loader,
|
||||
custom_loader,
|
||||
item_layers,
|
||||
separate_perspective
|
||||
).forEach(event::accept);
|
||||
}
|
||||
}
|
||||
|
||||
public void modelRegistry(ModelEvent.RegisterGeometryLoaders event)
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
package net.minecraftforge.debug.client.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
@@ -56,12 +54,13 @@ public class TRSRTransformerTest {
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> mod.addListener(this::onModelBake));
|
||||
BLOCKS.register(mod);
|
||||
ITEMS.register(mod);
|
||||
mod.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.BUILDING_BLOCKS) {
|
||||
onBuildContents.register((p_259204_, p_259752_, p_260123_) -> p_259752_.accept(TEST_ITEM.get()));
|
||||
}
|
||||
});
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.BUILDING_BLOCKS)
|
||||
event.accept(TEST_ITEM);
|
||||
}
|
||||
|
||||
public void onModelBake(ModelEvent.BakingCompleted e) {
|
||||
|
||||
Reference in new issue
Block a user