mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +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
@@ -33,8 +33,6 @@ import net.minecraft.world.item.Item.Properties;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(CustomElytraTest.MOD_ID)
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = CustomElytraTest.MOD_ID)
|
||||
public class CustomElytraTest
|
||||
@@ -48,13 +46,13 @@ public class CustomElytraTest
|
||||
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modBus);
|
||||
modBus.addListener(this::onClientSetup);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.INGREDIENTS) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(TEST_ELYTRA.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(TEST_ELYTRA);
|
||||
}
|
||||
|
||||
private void onClientSetup(FMLClientSetupEvent event)
|
||||
|
||||
@@ -19,8 +19,6 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(CustomMobBucketTest.MODID)
|
||||
public class CustomMobBucketTest
|
||||
{
|
||||
@@ -41,13 +39,13 @@ public class CustomMobBucketTest
|
||||
{
|
||||
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(COW_BUCKET.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(COW_BUCKET);
|
||||
}
|
||||
}
|
||||
@@ -31,14 +31,15 @@ public class CustomShieldTest
|
||||
|
||||
public CustomShieldTest()
|
||||
{
|
||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.COMBAT) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(CUSTOM_SHIELD_ITEM.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
var modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modBus);
|
||||
modBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.COMBAT)
|
||||
event.accept(CUSTOM_SHIELD_ITEM);
|
||||
}
|
||||
|
||||
private static class CustomShieldItem extends Item
|
||||
|
||||
@@ -17,15 +17,13 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(EnderMaskTest.MODID)
|
||||
public class EnderMaskTest
|
||||
{
|
||||
public static final String MODID = "ender_mask_test";
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
|
||||
public static RegistryObject<Item> ender_mask = ITEMS.register("ender_mask", () ->
|
||||
public static RegistryObject<Item> ENDER_MASK = ITEMS.register("ender_mask", () ->
|
||||
new ArmorItem(ArmorMaterials.LEATHER, EquipmentSlot.HEAD, (new Item.Properties()))
|
||||
{
|
||||
@Override
|
||||
@@ -40,12 +38,12 @@ public class EnderMaskTest
|
||||
{
|
||||
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(ender_mask.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(ENDER_MASK);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@
|
||||
package net.minecraftforge.debug.item;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.client.renderer.entity.PigRenderer;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
@@ -51,20 +49,20 @@ public class ForgeSpawnEggItemTest
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(this);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.INGREDIENTS) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(EGG.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
var eventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(eventBus);
|
||||
ENTITIES.register(eventBus);
|
||||
eventBus.register(this);
|
||||
eventBus.addListener(this::addCreative);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(EGG);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRegisterAttributes(final EntityAttributeCreationEvent event)
|
||||
{
|
||||
|
||||
@@ -23,8 +23,6 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(HiddenTooltipPartsTest.MOD_ID)
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = HiddenTooltipPartsTest.MOD_ID)
|
||||
public class HiddenTooltipPartsTest
|
||||
@@ -37,14 +35,15 @@ public class HiddenTooltipPartsTest
|
||||
|
||||
public HiddenTooltipPartsTest()
|
||||
{
|
||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.INGREDIENTS) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(TEST_ITEM.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
var modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modBus);
|
||||
modBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.INGREDIENTS)
|
||||
event.accept(TEST_ITEM);
|
||||
}
|
||||
|
||||
static class TestItem extends Item
|
||||
|
||||
@@ -17,8 +17,6 @@ import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(RangedMobsUseModdedWeaponsTest.MOD_ID)
|
||||
public class RangedMobsUseModdedWeaponsTest {
|
||||
|
||||
@@ -45,14 +43,16 @@ public class RangedMobsUseModdedWeaponsTest {
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener(this::onClientSetup);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.COMBAT) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(MODDED_BOW.get());
|
||||
output.accept(MODDED_CROSSBOW.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.COMBAT)
|
||||
{
|
||||
event.accept(MODDED_BOW);
|
||||
event.accept(MODDED_CROSSBOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,15 +16,13 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(SnowBootsTest.MODID)
|
||||
public class SnowBootsTest
|
||||
{
|
||||
public static final String MODID = "snow_boots_test";
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
|
||||
public static RegistryObject<Item> snow_boots = ITEMS.register("snow_boots", () ->
|
||||
public static RegistryObject<Item> SNOW_BOOTS = ITEMS.register("snow_boots", () ->
|
||||
new ArmorItem(ArmorMaterials.DIAMOND, EquipmentSlot.FEET, (new Item.Properties()))
|
||||
{
|
||||
@Override
|
||||
@@ -38,12 +36,12 @@ public class SnowBootsTest
|
||||
{
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modEventBus);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.COMBAT) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(snow_boots.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.COMBAT)
|
||||
event.accept(SNOW_BOOTS);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,6 @@ import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -97,22 +96,15 @@ public class TagBasedToolTypesTest
|
||||
BLOCKS.register(modEventBus);
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener(this::gatherData);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(new Consumer<CreativeModeTabEvent.BuildContents>() {
|
||||
@Override
|
||||
public void accept(CreativeModeTabEvent.BuildContents onBuildContents) {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
|
||||
onBuildContents.register((flags, output, permission) -> {
|
||||
output.accept(TOOL.get());
|
||||
});
|
||||
} else if (onBuildContents.getTab() == CreativeModeTabs.BUILDING_BLOCKS) {
|
||||
onBuildContents.register((flags, output, permission) -> {
|
||||
output.accept(ORE_ITEM.get());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.TOOLS_AND_UTILITIES)
|
||||
event.accept(TOOL);
|
||||
if (event.getTab() == CreativeModeTabs.BUILDING_BLOCKS)
|
||||
event.accept(ORE_ITEM);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
Reference in new issue
Block a user