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
@@ -8,19 +8,19 @@ package net.minecraftforge.debug.entity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.event.CreativeModeTabEvent;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -39,20 +39,24 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
import net.minecraft.world.item.Item.Properties;
|
||||
|
||||
@Mod("gravity_attribute_test")
|
||||
@Mod(GravityAttributeTest.MODID)
|
||||
public class GravityAttributeTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger = LogManager.getLogger();
|
||||
public static final String MODID = "gravity_attribute_test";
|
||||
private static Logger logger = LogManager.getLogger(MODID);
|
||||
private int ticks;
|
||||
private static final UUID REDUCED_GRAVITY_ID = UUID.fromString("DEB06000-7979-4242-8888-00000DEB0600");
|
||||
private static final AttributeModifier REDUCED_GRAVITY = (new AttributeModifier(REDUCED_GRAVITY_ID, "Reduced gravity", (double)-0.80, Operation.MULTIPLY_TOTAL));
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
private static final RegistryObject<Item> TEST_ITEM = ITEMS.register("gravity_stick", () -> new ItemGravityStick(new Properties().rarity(Rarity.RARE)));
|
||||
|
||||
|
||||
public GravityAttributeTest()
|
||||
@@ -60,7 +64,10 @@ public class GravityAttributeTest
|
||||
if (ENABLE)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(this);
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
modEventBus.register(this);
|
||||
ITEMS.register(modEventBus);
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,19 +122,10 @@ public class GravityAttributeTest
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerItems(RegisterEvent event)
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
event.register(ForgeRegistries.Keys.ITEMS, helper -> helper.register("gravity_stick",
|
||||
new ItemGravityStick(new Properties().rarity(Rarity.RARE))));
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((Consumer<CreativeModeTabEvent.BuildContents>) onBuildContents -> {
|
||||
if (onBuildContents.getTab() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
|
||||
onBuildContents.register((flags, output, permissions) -> {
|
||||
output.accept(ForgeRegistries.ITEMS.getValue(new ResourceLocation("gravity_attribute_test", "gravity_stick")));
|
||||
});
|
||||
}
|
||||
});
|
||||
if (event.getTab() == CreativeModeTabs.TOOLS_AND_UTILITIES)
|
||||
event.accept(TEST_ITEM);
|
||||
}
|
||||
|
||||
public static class ItemGravityStick extends Item
|
||||
|
||||
@@ -41,14 +41,15 @@ public class ItemUseAnimationTest
|
||||
|
||||
public ItemUseAnimationTest()
|
||||
{
|
||||
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(THING.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(THING);
|
||||
}
|
||||
|
||||
private static class ThingItem extends Item
|
||||
|
||||
@@ -21,7 +21,6 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Tests if the patch to PlayerEntity to make it utilize Attributes.ATTACK_KNOCKBACK works
|
||||
@@ -46,13 +45,13 @@ public class PlayerAttackKnockbackTest {
|
||||
{
|
||||
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(KNOCKBACK_SWORD.get());
|
||||
});
|
||||
}
|
||||
});
|
||||
modEventBus.addListener(this::addCreative);
|
||||
}
|
||||
|
||||
private void addCreative(CreativeModeTabEvent.BuildContents event)
|
||||
{
|
||||
if (event.getTab() == CreativeModeTabs.COMBAT)
|
||||
event.accept(KNOCKBACK_SWORD);
|
||||
}
|
||||
|
||||
static class KnockbackSwordItem extends SwordItem {
|
||||
|
||||
Reference in new issue
Block a user