Forge 1.19.3

Created a CreativeModeTabEvent to register creative mode tabs and populate entries per tab
Moved datapack registries to DataPackRegistryEvent.NewRegistry event instead of tying them to ForgeRegistry
Made it easier for mods to datagen datapack builtin entries with DatapackBuiltinEntriesProvider
Provided access to lookupProvider for datagen
Updated dependencies to match versions used by vanilla and update JarJar to 0.3.18
Added a test mod for the new CreativeModeTabEvent
Throws better error message for Forge registries in tag datagen
Deleted ForgeRegistryTagsProvider
Updated ClientChatReceivedEvent and ServerChatEvent for Mojang changes
Added patches for both sign related methods in ModelLayers
Changed RegisterShadersEvent to use ResourceProvider
Migrated old Mojang math types to JOML

Co-authored-by: Marc Hermans <[email protected]>
Co-authored-by: LexManos <[email protected]>
Co-authored-by: sciwhiz12 <[email protected]>
Co-authored-by: coehlrich <[email protected]>
This commit is contained in:
committed 2022-12-08 01:45:22 -06:00
1 parent 617ecb7ad3
commit 8255d7aed3
726 files changed
+7615 -6653

No files matched your search

@@ -6,11 +6,12 @@
package net.minecraftforge.debug.client;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -18,12 +19,16 @@ 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.
*/
@Mod(AmbientOcclusionElementsTest.MOD_ID)
public class AmbientOcclusionElementsTest
{
private static final boolean ENABLED = false;
public static final String MOD_ID = "ambient_occlusion_elements_test";
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MOD_ID);
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
@@ -32,15 +37,21 @@ public class AmbientOcclusionElementsTest
public static final RegistryObject<Block> AO_BLOCK_NO_SHADE = BLOCKS.register("ambient_occlusion_no_shade", () -> new Block(BlockBehaviour.Properties.of(Material.STONE)));
public static final RegistryObject<Block> NO_AO_BLOCK_SHADE = BLOCKS.register("no_ambient_occlusion_shade", () -> new Block(BlockBehaviour.Properties.of(Material.STONE)));
public static final RegistryObject<Block> NO_AO_BLOCK_NO_SHADE = BLOCKS.register("no_ambient_occlusion_no_shade", () -> new Block(BlockBehaviour.Properties.of(Material.STONE)));
public static final RegistryObject<Item> AO_BLOCK_SHADE_ITEM = ITEMS.register("ambient_occlusion_shade", () -> new BlockItem(AO_BLOCK_SHADE.get(), new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
public static final RegistryObject<Item> AO_BLOCK_NO_SHADE_ITEM = ITEMS.register("ambient_occlusion_no_shade", () -> new BlockItem(AO_BLOCK_NO_SHADE.get(), new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
public static final RegistryObject<Item> NO_AO_BLOCK_SHADE_ITEM = ITEMS.register("no_ambient_occlusion_shade", () -> new BlockItem(NO_AO_BLOCK_SHADE.get(), new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
public static final RegistryObject<Item> NO_AO_BLOCK_NO_SHADE_ITEM = ITEMS.register("no_ambient_occlusion_no_shade", () -> new BlockItem(NO_AO_BLOCK_NO_SHADE.get(), new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
public static final RegistryObject<Item> AO_BLOCK_SHADE_ITEM = ITEMS.register("ambient_occlusion_shade", () -> new BlockItem(AO_BLOCK_SHADE.get(), new Item.Properties()));
public static final RegistryObject<Item> AO_BLOCK_NO_SHADE_ITEM = ITEMS.register("ambient_occlusion_no_shade", () -> new BlockItem(AO_BLOCK_NO_SHADE.get(), new Item.Properties()));
public static final RegistryObject<Item> NO_AO_BLOCK_SHADE_ITEM = ITEMS.register("no_ambient_occlusion_shade", () -> new BlockItem(NO_AO_BLOCK_SHADE.get(), new Item.Properties()));
public static final RegistryObject<Item> NO_AO_BLOCK_NO_SHADE_ITEM = ITEMS.register("no_ambient_occlusion_no_shade", () -> new BlockItem(NO_AO_BLOCK_NO_SHADE.get(), new Item.Properties()));
public AmbientOcclusionElementsTest()
{
if (!ENABLED)
return;
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
BLOCKS.register(modEventBus);
ITEMS.register(modEventBus);
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()));
}
}
@@ -5,7 +5,6 @@
package net.minecraftforge.debug.client;
import com.mojang.math.Vector3d;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
import net.minecraft.client.resources.sounds.Sound;
@@ -16,15 +16,11 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ArmorMaterials;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.*;
import net.minecraft.world.item.Item.Properties;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -43,15 +39,18 @@ public class CustomArmorModelTest
static final String MOD_ID = "custom_armor_model_test";
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
// demonstrates custom non-humanoid model
private static final RegistryObject<Item> RED_LEGGINGS = ITEMS.register("red_leggings", () -> new TintedArmorItem(ArmorMaterials.DIAMOND, EquipmentSlot.LEGS, new Properties().stacksTo(1).tab(CreativeModeTab.TAB_MISC)));
private static final RegistryObject<Item> RED_LEGGINGS = ITEMS.register("red_leggings", () -> new TintedArmorItem(ArmorMaterials.DIAMOND, EquipmentSlot.LEGS, new Properties().stacksTo(1)));
// demonstrates the properties are copied from the vanilla model
private static final RegistryObject<Item> ENDERMAN_CHESTPLATE = ITEMS.register("enderman_chestplate", () -> new EndermanArmorItem(ArmorMaterials.GOLD, EquipmentSlot.CHEST, new Properties().stacksTo(1).tab(CreativeModeTab.TAB_MISC)));
private static final RegistryObject<Item> ENDERMAN_BOOTS = ITEMS.register("enderman_boots", () -> new EndermanArmorItem(ArmorMaterials.GOLD, EquipmentSlot.FEET, new Properties().stacksTo(1).tab(CreativeModeTab.TAB_MISC)));
private static final RegistryObject<Item> ENDERMAN_CHESTPLATE = ITEMS.register("enderman_chestplate", () -> new EndermanArmorItem(ArmorMaterials.GOLD, EquipmentSlot.CHEST, new Properties().stacksTo(1)));
private static final RegistryObject<Item> ENDERMAN_BOOTS = ITEMS.register("enderman_boots", () -> new EndermanArmorItem(ArmorMaterials.GOLD, EquipmentSlot.FEET, new Properties().stacksTo(1)));
public CustomArmorModelTest()
{
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
ITEMS.register(modBus);
modBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.INGREDIENTS,
RED_LEGGINGS.get(), ENDERMAN_CHESTPLATE.get(), ENDERMAN_BOOTS.get()));
}
private static class TintedArmorItem extends ArmorItem
@@ -8,13 +8,15 @@ package net.minecraftforge.debug.client;
import java.util.Random;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.Tickable;
import net.minecraft.client.renderer.texture.*;
import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection;
import net.minecraft.client.resources.metadata.animation.FrameSize;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.item.Item;
import net.minecraftforge.client.event.RegisterTextureAtlasSpriteLoadersEvent;
import net.minecraftforge.client.textures.ForgeTextureMetadata;
import net.minecraftforge.client.textures.ITextureAtlasSpriteLoader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -23,6 +25,7 @@ import net.minecraftforge.registries.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@Mod(CustomTASTest.MOD_ID)
public class CustomTASTest
@@ -52,27 +55,48 @@ public class CustomTASTest
private static class TasLoader implements ITextureAtlasSpriteLoader
{
@Override
@NotNull
public TextureAtlasSprite load(TextureAtlas atlas, ResourceManager resourceManager, TextureAtlasSprite.Info textureInfo, Resource resource, int atlasWidth, int atlasHeight, int spriteX, int spriteY, int mipmapLevel, NativeImage image)
{
return new TextureAtlasSprite(
atlas, textureInfo, mipmapLevel, atlasWidth, atlasHeight, spriteX, spriteY, image
)
{
private final Random random = new Random();
public SpriteContents loadContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image, AnimationMetadataSection animationMeta, ForgeTextureMetadata forgeMeta) {
final class TASSpriteContents extends SpriteContents {
public TASSpriteContents(ResourceLocation p_249787_, FrameSize p_251031_, NativeImage p_252131_, AnimationMetadataSection p_250432_, @Nullable ForgeTextureMetadata forgeMeta) {
super(p_249787_, p_251031_, p_252131_, p_250432_, forgeMeta);
}
@Override
public Tickable getAnimationTicker()
{
return this::tick;
public @NotNull SpriteTicker createTicker() {
return new Ticker();
}
private void tick()
{
this.mainImage[0].fillRect(0, 0, 16, 16, 0xFF000000 | random.nextInt(0xFFFFFF));
this.uploadFirstFrame();
class Ticker implements SpriteTicker {
final Random random = new Random();
@Override
public void tickAndUpload(int p_248847_, int p_250486_) {
TASSpriteContents.this.byMipLevel[0].fillRect(0, 0, 16, 16, 0xFF000000 | random.nextInt(0xFFFFFF));
TASSpriteContents.this.uploadFirstFrame(p_248847_, p_250486_);
}
@Override
public void close() {
}
}
};
}
return new TASSpriteContents(name, frameSize, image, animationMeta, forgeMeta);
}
@Override
public @NotNull TextureAtlasSprite makeSprite(ResourceLocation atlasName, SpriteContents contents, int atlasWidth, int atlasHeight, int spriteX, int spriteY, int mipmapLevel) {
final class TASSprite extends TextureAtlasSprite {
public TASSprite(ResourceLocation p_250211_, SpriteContents p_248526_, int p_248950_, int p_249741_, int p_248672_, int p_248637_) {
super(p_250211_, p_248526_, p_248950_, p_249741_, p_248672_, p_248637_);
}
}
return new TASSprite(atlasName, contents, atlasWidth, atlasHeight, spriteX, spriteY);
}
}
@@ -12,9 +12,7 @@ import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.font.FontManager;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.network.chat.Component;
@@ -23,18 +21,14 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterClientTooltipComponentFactoriesEvent;
import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -44,10 +38,9 @@ import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
@Mod(CustomTooltipTest.ID)
public class CustomTooltipTest
@@ -59,18 +52,20 @@ public class CustomTooltipTest
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ID);
static final RegistryObject<Item> CUSTOM_ITEM = ITEMS.register(
"test_item",
() -> new CustomItemWithTooltip(new Item.Properties().tab(CreativeModeTab.TAB_MISC))
() -> new CustomItemWithTooltip(new Item.Properties())
);
public CustomTooltipTest()
{
if (ENABLED) {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
if (FMLEnvironment.dist.isClient())
{
MinecraftForge.EVENT_BUS.register(ClientEventHandler.class);
FMLJavaModLoadingContext.get().getModEventBus().register(ClientModBusEventHandler.class);
modEventBus.register(ClientModBusEventHandler.class);
}
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
ITEMS.register(modEventBus);
modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.INGREDIENTS, CUSTOM_ITEM.get()));
}
}
@@ -117,10 +112,10 @@ public class CustomTooltipTest
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand)
{
if (level.isClientSide)
/* if (level.isClientSide) Update to 1.19.3: Disable screen tests since logic for tooltips on buttons has changed massively!
{
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> TooltipTestScreen::show);
}
}*/
return InteractionResultHolder.success(player.getItemInHand(hand));
}
@@ -187,7 +182,9 @@ public class CustomTooltipTest
}
static class TooltipTestScreen extends Screen
/* Disabled on update to 1.19.3: Tooltips have changed massively, and mojang now handles them differently
static class TooltipTestScreen extends Screen
{
private ItemStack testStack = ItemStack.EMPTY;
@@ -213,19 +210,20 @@ public class CustomTooltipTest
@Override
protected void init()
{
addRenderableWidget(new Button(10, 10, 200, 20, Component.literal("Toggle Stack: EMPTY"), button -> {
addRenderableWidget(Button.builder(Component.literal("Toggle Stack: EMPTY"), button -> {
this.testStack = this.testStack.isEmpty() ? new ItemStack(Items.APPLE) : ItemStack.EMPTY;
button.setMessage(Component.literal("Toggle Stack: " + (testStack.isEmpty() ? "EMPTY" : "Apple")));
}));
addRenderableWidget(new Button(220, 10, 200, 20, Component.literal("Toggle Font: null"), button -> {
}).pos(10, 10).size(200,20).build());
addRenderableWidget(Button.builder(Component.literal("Toggle Font: null"), button -> {
this.testFont = this.testFont == null ? ClientModBusEventHandler.customFont : null;
button.setMessage(Component.literal("Toggle Font: " + (testFont == null ? "null" : "customFont")));
}));
}).pos(220, 10).size(200,20).build());
// * must have stack context
// # must have custom font
List<Map.Entry<String, Button.OnTooltip>> tooltipTests = Arrays.asList(
List<Map.Entry<String, Tooltip>> tooltipTests = Arrays.asList(
Map.entry(" 1 * ", this::test1),
Map.entry(" 2 * ", this::test2),
Map.entry(" 3 #", this::test3),
@@ -330,6 +328,6 @@ public class CustomTooltipTest
{
renderComponentTooltip(poseStack, List.of(Component.literal("test")), mouseX, mouseY, this.testFont, ItemStack.EMPTY);
}
}
}*/
}
@@ -6,11 +6,12 @@
package net.minecraftforge.debug.client;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -29,12 +30,14 @@ public class EmissiveElementsTest
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
public static final RegistryObject<Block> TEST_BLOCK = BLOCKS.register("emissive", () -> new Block(BlockBehaviour.Properties.of(Material.STONE)));
public static final RegistryObject<Item> TEST_BLOCK_ITEM = ITEMS.register("emissive", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
public static final RegistryObject<Item> TEST_BLOCK_ITEM = ITEMS.register("emissive", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties()));
public EmissiveElementsTest()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
BLOCKS.register(modEventBus);
ITEMS.register(modEventBus);
modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.BUILDING_BLOCKS, TEST_BLOCK_ITEM.get()));
}
}
@@ -21,6 +21,8 @@ import java.util.Random;
@Mod(GuiLayeringTest.MODID)
public class GuiLayeringTest
{
private static final boolean ENABLED = false;
private static final Random RANDOM = new Random();
public static final String MODID = "gui_layer_test";
@@ -30,14 +32,15 @@ public class GuiLayeringTest
@SubscribeEvent
public static void guiOpen(ScreenEvent.Init event)
{
if (event.getScreen() instanceof AbstractContainerScreen)
if (event.getScreen() instanceof AbstractContainerScreen && ENABLED)
{
event.addListener(new Button(2, 2, 150, 20, Component.literal("Test Gui Layering"), btn -> {
event.addListener(Button.builder(Component.literal("Test Gui Layering"), btn -> {
Minecraft.getInstance().pushGuiLayer(new TestLayer(Component.literal("LayerScreen")));
}));
event.addListener(new Button(2, 25, 150, 20, Component.literal("Test Gui Normal"), btn -> {
}).pos(2,2).size(150, 20).build());
event.addListener(Button.builder(Component.literal("Test Gui Normal"), btn -> {
Minecraft.getInstance().setScreen(new TestLayer(Component.literal("LayerScreen")));
}));
}).pos(2, 25).size(150, 20).build());
}
}
@@ -72,9 +75,9 @@ public class GuiLayeringTest
xoff = RANDOM.nextInt(xoff);
yoff = RANDOM.nextInt(yoff);
this.addRenderableWidget(new Button(xoff, yoff + buttonSpacing * (cnt++), buttonWidth, buttonHeight, Component.literal("Push New Layer"), this::pushLayerButton));
this.addRenderableWidget(new Button(xoff, yoff + buttonSpacing * (cnt++), buttonWidth, buttonHeight, Component.literal("Pop Current Layer"), this::popLayerButton));
this.addRenderableWidget(new Button(xoff, yoff + buttonSpacing * (cnt++), buttonWidth, buttonHeight, Component.literal("Close entire stack"), this::closeStack));
this.addRenderableWidget(Button.builder(Component.literal("Push New Layer"), this::pushLayerButton).pos(xoff, yoff + buttonSpacing * (cnt++)).size(buttonWidth, buttonHeight).build());
this.addRenderableWidget(Button.builder(Component.literal("Pop Current Layer"), this::popLayerButton).pos(xoff, yoff + buttonSpacing * (cnt++)).size(buttonWidth, buttonHeight).build());
this.addRenderableWidget(Button.builder(Component.literal("Close entire stack"), this::closeStack).pos(xoff, yoff + buttonSpacing * (cnt++)).size(buttonWidth, buttonHeight).build());
}
private void closeStack(Button button)
@@ -5,16 +5,13 @@
package net.minecraftforge.debug.client.model;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.core.BlockPos;
@@ -22,6 +19,7 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.level.BlockGetter;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.RegistryObject;
import net.minecraftforge.fml.common.Mod;
@@ -30,6 +28,8 @@ 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
{
@@ -72,7 +72,7 @@ public class CompositeModelTest
);
public static RegistryObject<Item> composite_item = ITEMS.register("composite_block", () ->
new BlockItem(composite_block.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)) {
new BlockItem(composite_block.get(), new Item.Properties()) {
@Override
public boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity)
{
@@ -87,5 +87,7 @@ public class CompositeModelTest
BLOCKS.register(modEventBus);
ITEMS.register(modEventBus);
modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.INGREDIENTS, composite_item.get()));
}
}
@@ -40,6 +40,7 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.model.generators.*;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -49,6 +50,8 @@ 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.
@@ -117,7 +120,7 @@ public class CustomTransformTypeTest
public static final RegistryObject<BlockEntityType<ItemHangerBlockEntity>>
ITEM_HANGER_BE = BLOCK_ENTITY_TYPES.register("item_hanger", () -> BlockEntityType.Builder.of(ItemHangerBlockEntity::new, ITEM_HANGER_BLOCK.get()).build(null));
public static final RegistryObject<Item>
ITEM_HANGER_ITEM = ITEMS.register("item_hanger", () -> new ItemHangerItem(ITEM_HANGER_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
ITEM_HANGER_ITEM = ITEMS.register("item_hanger", () -> new ItemHangerItem(ITEM_HANGER_BLOCK.get(), new Item.Properties()));
public CustomTransformTypeTest()
{
@@ -126,6 +129,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());
});
}
});
}
public void gatherData(GatherDataEvent event)
@@ -5,8 +5,9 @@
package net.minecraftforge.debug.client.model;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.RegistryObject;
import net.minecraftforge.fml.common.Mod;
@@ -14,22 +15,32 @@ 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
{
public static final boolean ENABLE = false; // TODO fix
public static final String MODID = "dyn_bucket_model_test";
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final RegistryObject<Item> DRIP_BUCKET = ITEMS.register("drip_bucket", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
public static final RegistryObject<Item> LAVA_OBSIDIAN = ITEMS.register("lava_obsidian", () -> new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
public static final RegistryObject<Item> DRIP_BUCKET = ITEMS.register("drip_bucket", () -> new Item(new Item.Properties()));
public static final RegistryObject<Item> LAVA_OBSIDIAN = ITEMS.register("lava_obsidian", () -> new Item(new Item.Properties()));
public DynBucketModelTest()
{
if (ENABLE)
{
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());
});
}
});
}
}
}
@@ -5,9 +5,7 @@
package net.minecraftforge.debug.client.model;
import com.mojang.math.Quaternion;
import com.mojang.math.Transformation;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
@@ -20,7 +18,7 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
@@ -36,6 +34,7 @@ import net.minecraftforge.client.model.BakedModelWrapper;
import net.minecraftforge.client.model.IQuadTransformer;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.client.model.data.ModelProperty;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -45,9 +44,12 @@ import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
/**
* Test mod that demos most Forge-provided model loaders in a single block + item, as well as in-JSON render states
@@ -75,7 +77,7 @@ public class MegaModelTest
private static final String REG_NAME = "test_block";
public static final RegistryObject<Block> TEST_BLOCK = BLOCKS.register(REG_NAME, TestBlock::new);
public static final RegistryObject<Item> TEST_BLOCK_ITEM = ITEMS.register(REG_NAME, () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_DECORATIONS)));
public static final RegistryObject<Item> TEST_BLOCK_ITEM = ITEMS.register(REG_NAME, () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties()));
public static final RegistryObject<BlockEntityType<?>> TEST_BLOCK_ENTITY = BLOCK_ENTITIES.register(REG_NAME, () -> new BlockEntityType<>(
TestBlock.Entity::new, Set.of(TEST_BLOCK.get()), null
));
@@ -86,6 +88,12 @@ public class MegaModelTest
BLOCKS.register(modEventBus);
ITEMS.register(modEventBus);
BLOCK_ENTITIES.register(modEventBus);
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()));
}
});
}
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
@@ -143,9 +151,9 @@ public class MegaModelTest
{
return ModelData.builder().with(TestData.PROPERTY, new TestData(new Transformation(
new Vector3f(0, y * 0.2f, 0),
Quaternion.ONE,
new Quaternionf(1f, 1f, 1f, 1f),
Transformation.identity().getScale(),
Quaternion.ONE
new Quaternionf(1f, 1f, 1f, 1f)
))).build();
}
}
@@ -5,21 +5,25 @@
package net.minecraftforge.debug.client.model;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Material;
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.world.item.CreativeModeTab;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;
import net.minecraftforge.registries.RegisterEvent;
import java.util.function.Consumer;
@Mod(MultiLayerModelTest.MODID)
public class MultiLayerModelTest
{
@@ -48,7 +52,14 @@ public class MultiLayerModelTest
{
if (!ENABLED || !event.getRegistryKey().equals(ForgeRegistries.Keys.ITEMS))
return;
event.register(ForgeRegistries.Keys.ITEMS, blockId, () -> new BlockItem(TEST_BLOCK, new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
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());
});
}
});
}
@SubscribeEvent
@@ -7,8 +7,9 @@ package net.minecraftforge.debug.client.model;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.mojang.datafixers.util.Pair;
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;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
@@ -38,6 +39,7 @@ import net.minecraftforge.client.model.generators.loaders.SeparateTransformsMode
import net.minecraftforge.client.model.geometry.SimpleUnbakedGeometry;
import net.minecraftforge.client.model.pipeline.QuadBakingVertexConsumer;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.RegistryObject;
import net.minecraftforge.fml.common.Mod;
@@ -46,19 +48,11 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import org.jetbrains.annotations.Nullable;
@@ -95,7 +89,7 @@ public class NewModelLoaderTest
);
public static RegistryObject<Item> obj_item = ITEMS.register("obj_block", () ->
new BlockItem(obj_block.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)) {
new BlockItem(obj_block.get(), new Item.Properties()) {
@Override
public boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity)
{
@@ -105,23 +99,23 @@ public class NewModelLoaderTest
);
public static RegistryObject<Item> custom_transforms = ITEMS.register("custom_transforms", () ->
new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))
new Item(new Item.Properties())
);
public static RegistryObject<Item> custom_vanilla_loader = ITEMS.register("custom_vanilla_loader", () ->
new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))
new Item(new Item.Properties())
);
public static RegistryObject<Item> custom_loader = ITEMS.register("custom_loader", () ->
new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))
new Item(new Item.Properties())
);
public static RegistryObject<Item> item_layers = ITEMS.register("item_layers", () ->
new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))
new Item(new Item.Properties())
);
public static RegistryObject<Item> separate_perspective = ITEMS.register("separate_perspective", () ->
new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))
new Item(new Item.Properties())
);
public NewModelLoaderTest()
@@ -133,6 +127,20 @@ public class NewModelLoaderTest
modEventBus.addListener(this::modelRegistry);
modEventBus.addListener(this::datagen);
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());
});
}
});
}
public void modelRegistry(ModelEvent.RegisterGeometryLoaders event)
@@ -152,8 +160,7 @@ public class NewModelLoaderTest
static class TestModel extends SimpleUnbakedGeometry<TestModel>
{
@Override
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBakery bakery, Function< net.minecraft.client.resources.model.Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation)
{
protected void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBaker baker, Function<net.minecraft.client.resources.model.Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation) {
TextureAtlasSprite texture = spriteGetter.apply(owner.getMaterial("particle"));
var quadBaker = new QuadBakingVertexConsumer.Buffered();
@@ -168,12 +175,6 @@ public class NewModelLoaderTest
modelBuilder.addUnculledFace(quadBaker.getQuad());
}
@Override
public Collection< net.minecraft.client.resources.model.Material> getMaterials(IGeometryBakingContext context, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
{
return Collections.singleton(context.getMaterial("particle"));
}
}
private void datagen(GatherDataEvent event)
@@ -6,9 +6,11 @@
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;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
@@ -18,18 +20,16 @@ import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import com.mojang.math.Quaternion;
import com.mojang.math.Transformation;
import com.mojang.math.Vector3f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.client.model.IQuadTransformer;
import net.minecraftforge.client.model.IDynamicBakedModel;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.common.util.TransformationHelper;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.registries.RegistryObject;
@@ -38,6 +38,8 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3f;
@Mod(TRSRTransformerTest.MODID)
public class TRSRTransformerTest {
@@ -47,13 +49,19 @@ public class TRSRTransformerTest {
private static final RegistryObject<Block> TEST_BLOCK = BLOCKS.register("test", () -> new Block(Block.Properties.of(Material.STONE)));
@SuppressWarnings("unused")
private static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
private static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties()));
public TRSRTransformerTest() {
final IEventBus mod = FMLJavaModLoadingContext.get().getModEventBus();
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> mod.addListener(this::onModelBake));
BLOCKS.register(mod);
ITEMS.register(mod);
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()));
}
});
}
public void onModelBake(ModelEvent.BakingCompleted e) {
@@ -73,7 +81,7 @@ public class TRSRTransformerTest {
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, ModelData data, @Nullable RenderType renderType) {
Quaternion rot = TransformationHelper.quatFromXYZ(new Vector3f(0, 45, 0), true);
Quaternionf rot = TransformationHelper.quatFromXYZ(new Vector3f(0, 45, 0), true);
Vector3f translation = new Vector3f(0, 0.33f, 0);
Transformation trans = new Transformation(translation, rot, null, null).blockCenterToCorner();
@@ -7,13 +7,13 @@ package net.minecraftforge.debug.client.rendering;
import java.util.Map;
import com.mojang.math.Transformation;
import net.minecraftforge.common.util.TransformationHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.common.collect.ImmutableMap;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
@@ -43,6 +43,8 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
/**
* This mod is testing the use of {@link RenderLevelStageEvent} and is a modifaction of a pre-existing test mod that used the old
@@ -185,13 +187,11 @@ public class RenderableTest
var map = ImmutableMap.<String, Matrix4f>builder();
var left = new Matrix4f();
left.setIdentity();
left.multiply(Quaternion.fromYXZ(0, 0, (float)Math.sin(time * 0.4) * 0.1f));
left.rotation((float)Math.sin(time * 0.4) * 0.1f, 0, 0, 1);
map.put("object_1", left);
var right = new Matrix4f();
right.setIdentity();
right.multiply(Quaternion.fromYXZ(0, 0, -(float)Math.sin(time * 0.4) * 0.1f));
right.rotation(-(float)Math.sin(time * 0.4) * 0.1f, 0, 0, 1);
map.put("object_9", right);
var transforms = CompositeRenderable.Transforms.of(map.build());
@@ -48,24 +48,24 @@ public class ShaderResourcesTest
modEventBus.addListener(ClientInit::registerShaders);
}
public static void registerShaders(final RegisterShadersEvent event)
{
if (!ENABLE)
return;
try
{
event.registerShader(
new ShaderInstance(
event.getResourceManager(),
event.getResourceProvider(),
new ResourceLocation(MODID, "vertex_cubemap"),
DefaultVertexFormat.POSITION),
shader ->
{
LOGGER.info("Completely loaded shader {} with no issues", shader.getName());
});
LOGGER.info("Loaded registered shaders with no exceptions");
}
catch (IOException e)