mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Forge 1.19
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
270e778ac5
commit
4ed9117799
1485 files changed
+14960
-15446
No files matched your search
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
@@ -38,7 +38,7 @@ public class AddPackFinderEventTest
|
||||
{
|
||||
event.addRepositorySource((packConsumer, packConstructor) ->
|
||||
packConsumer.accept(packConstructor.create(
|
||||
"builtin/add_pack_finders_test", new TextComponent("display name"), false,
|
||||
"builtin/add_pack_finders_test", Component.literal("display name"), false,
|
||||
() -> pack, metadataSection, Pack.Position.BOTTOM, PackSource.BUILT_IN, false)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ package net.minecraftforge.debug;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -31,6 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
@Mod(CapabilitiesTest.MODID)
|
||||
@@ -122,11 +124,12 @@ public class CapabilitiesTest
|
||||
@SubscribeEvent
|
||||
public static void clientTick(TickEvent.ClientTickEvent event)
|
||||
{
|
||||
if (event.phase == TickEvent.Phase.END)
|
||||
if (event.phase == TickEvent.Phase.END && Minecraft.getInstance().level != null)
|
||||
{
|
||||
while(messages.size() > 0)
|
||||
{
|
||||
Minecraft.getInstance().gui.handleChat(ChatType.SYSTEM, new TextComponent(messages.poll()), Util.NIL_UUID);
|
||||
final ChatType system = Minecraft.getInstance().level.registryAccess().registryOrThrow(Registry.CHAT_TYPE_REGISTRY).getOrThrow(ChatType.SYSTEM);
|
||||
Minecraft.getInstance().gui.handleSystemChat(system, Component.literal(Objects.requireNonNull(messages.poll())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,11 @@ import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.advancements.AdvancementProvider;
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -48,6 +49,7 @@ import net.minecraftforge.common.crafting.IntersectionIngredient;
|
||||
import net.minecraftforge.common.crafting.NBTIngredient;
|
||||
import net.minecraftforge.common.data.SoundDefinition;
|
||||
import net.minecraftforge.common.data.SoundDefinitionsProvider;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -87,7 +89,6 @@ import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.client.model.generators.BlockStateProvider;
|
||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||
import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
@@ -140,21 +141,16 @@ public class DataGeneratorTest
|
||||
|
||||
DataGenerator gen = event.getGenerator();
|
||||
|
||||
if (event.includeClient())
|
||||
{
|
||||
gen.addProvider(new Lang(gen));
|
||||
// Let blockstate provider see generated item models by passing its existing file helper
|
||||
ItemModelProvider itemModels = new ItemModels(gen, event.getExistingFileHelper());
|
||||
gen.addProvider(itemModels);
|
||||
gen.addProvider(new BlockStates(gen, itemModels.existingFileHelper));
|
||||
gen.addProvider(new SoundDefinitions(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
if (event.includeServer())
|
||||
{
|
||||
gen.addProvider(new Recipes(gen));
|
||||
gen.addProvider(new Tags(gen, event.getExistingFileHelper()));
|
||||
gen.addProvider(new Advancements(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
gen.addProvider(event.includeClient(), new Lang(gen));
|
||||
// Let blockstate provider see generated item models by passing its existing file helper
|
||||
ItemModelProvider itemModels = new ItemModels(gen, event.getExistingFileHelper());
|
||||
gen.addProvider(event.includeClient(), itemModels);
|
||||
gen.addProvider(event.includeClient(), new BlockStates(gen, itemModels.existingFileHelper));
|
||||
gen.addProvider(event.includeClient(), new SoundDefinitions(gen, event.getExistingFileHelper()));
|
||||
|
||||
gen.addProvider(event.includeServer(), new Recipes(gen));
|
||||
gen.addProvider(event.includeServer(), new Tags(gen, event.getExistingFileHelper()));
|
||||
gen.addProvider(event.includeServer(), new Advancements(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
|
||||
public static class Recipes extends RecipeProvider implements IConditionBuilder
|
||||
@@ -201,8 +197,8 @@ public class DataGeneratorTest
|
||||
Advancement.Builder.advancement()
|
||||
.parent(new ResourceLocation("minecraft", "root"))
|
||||
.display(Blocks.DIAMOND_BLOCK,
|
||||
new TextComponent("Dirt2Diamonds"),
|
||||
new TextComponent("The BEST crafting recipe in the game!"),
|
||||
Component.literal("Dirt2Diamonds"),
|
||||
Component.literal("The BEST crafting recipe in the game!"),
|
||||
null, FrameType.TASK, false, false, false
|
||||
)
|
||||
.rewards(AdvancementRewards.Builder.recipe(ID))
|
||||
@@ -413,7 +409,7 @@ public class DataGeneratorTest
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
{
|
||||
super.run(cache);
|
||||
test();
|
||||
@@ -431,7 +427,7 @@ public class DataGeneratorTest
|
||||
throw new RuntimeException("Unable to test for errors due to reflection error", e);
|
||||
}
|
||||
final JsonObject actual = GSON.fromJson(
|
||||
new InputStreamReader(this.helper.getResource(new ResourceLocation("sounds.json"), PackType.CLIENT_RESOURCES).getInputStream()),
|
||||
this.helper.getResource(new ResourceLocation("sounds.json"), PackType.CLIENT_RESOURCES).openAsReader(),
|
||||
JsonObject.class
|
||||
);
|
||||
|
||||
@@ -659,7 +655,7 @@ public class DataGeneratorTest
|
||||
);
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
{
|
||||
super.run(cache);
|
||||
List<String> errors = testModelResults(this.generatedModels, existingFileHelper, IGNORED_MODELS.stream().map(s -> new ResourceLocation(MODID, folder + "/" + s)).collect(Collectors.toSet()));
|
||||
@@ -796,20 +792,22 @@ public class DataGeneratorTest
|
||||
ModelFile barrel = models().cubeBottomTop("barrel", mcLoc("block/barrel_side"), mcLoc("block/barrel_bottom"), mcLoc("block/barrel_top"));
|
||||
ModelFile barrelOpen = models().cubeBottomTop("barrel_open", mcLoc("block/barrel_side"), mcLoc("block/barrel_bottom"), mcLoc("block/barrel_top_open"));
|
||||
directionalBlock(Blocks.BARREL, state -> state.getValue(BarrelBlock.OPEN) ? barrelOpen : barrel); // Testing custom state interpreter
|
||||
|
||||
|
||||
logBlock((RotatedPillarBlock) Blocks.ACACIA_LOG);
|
||||
|
||||
stairsBlock((StairBlock) Blocks.ACACIA_STAIRS, "acacia", mcLoc("block/acacia_planks"));
|
||||
slabBlock((SlabBlock) Blocks.ACACIA_SLAB, Blocks.ACACIA_PLANKS.getRegistryName(), mcLoc("block/acacia_planks"));
|
||||
slabBlock((SlabBlock) Blocks.ACACIA_SLAB, ForgeRegistries.BLOCKS.getKey(Blocks.ACACIA_PLANKS), mcLoc("block/acacia_planks"));
|
||||
|
||||
fenceBlock((FenceBlock) Blocks.ACACIA_FENCE, "acacia", mcLoc("block/acacia_planks"));
|
||||
// TODO 1.19: fix fenceBlock, wallBlock, doorBlock, and co -SS
|
||||
// fenceBlock((FenceBlock) Blocks.ACACIA_FENCE, "acacia", mcLoc("block/acacia_planks"));
|
||||
fenceGateBlock((FenceGateBlock) Blocks.ACACIA_FENCE_GATE, "acacia", mcLoc("block/acacia_planks"));
|
||||
|
||||
wallBlock((WallBlock) Blocks.COBBLESTONE_WALL, "cobblestone", mcLoc("block/cobblestone"));
|
||||
// wallBlock((WallBlock) Blocks.COBBLESTONE_WALL, "cobblestone", mcLoc("block/cobblestone"));
|
||||
|
||||
paneBlock((IronBarsBlock) Blocks.GLASS_PANE, "glass", mcLoc("block/glass"), mcLoc("block/glass_pane_top"));
|
||||
|
||||
doorBlock((DoorBlock) Blocks.ACACIA_DOOR, "acacia", mcLoc("block/acacia_door_bottom"), mcLoc("block/acacia_door_top"));
|
||||
|
||||
// doorBlock((DoorBlock) Blocks.ACACIA_DOOR, "acacia", mcLoc("block/acacia_door_bottom"), mcLoc("block/acacia_door_top"));
|
||||
trapdoorBlock((TrapDoorBlock) Blocks.ACACIA_TRAPDOOR, "acacia", mcLoc("block/acacia_trapdoor"), true);
|
||||
trapdoorBlock((TrapDoorBlock) Blocks.OAK_TRAPDOOR, "oak", mcLoc("block/oak_trapdoor"), false); // Test a non-orientable trapdoor
|
||||
|
||||
@@ -838,7 +836,7 @@ public class DataGeneratorTest
|
||||
private List<String> errors = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
{
|
||||
super.run(cache);
|
||||
this.errors.addAll(testModelResults(models().generatedModels, models().existingFileHelper, Sets.union(IGNORED_MODELS, CUSTOM_MODELS)));
|
||||
@@ -846,8 +844,8 @@ public class DataGeneratorTest
|
||||
if (IGNORED_BLOCKS.contains(block)) return;
|
||||
JsonObject generated = state.toJson();
|
||||
try {
|
||||
Resource vanillaResource = models().existingFileHelper.getResource(block.getRegistryName(), PackType.CLIENT_RESOURCES, ".json", "blockstates");
|
||||
JsonObject existing = GSON.fromJson(new InputStreamReader(vanillaResource.getInputStream()), JsonObject.class);
|
||||
Resource vanillaResource = models().existingFileHelper.getResource(ForgeRegistries.BLOCKS.getKey(block), PackType.CLIENT_RESOURCES, ".json", "blockstates");
|
||||
JsonObject existing = GSON.fromJson(vanillaResource.openAsReader(), JsonObject.class);
|
||||
if (state instanceof VariantBlockStateBuilder) {
|
||||
compareVariantBlockstates(block, generated, existing);
|
||||
} else if (state instanceof MultiPartBlockStateBuilder) {
|
||||
@@ -1027,8 +1025,8 @@ public class DataGeneratorTest
|
||||
protected void registerAdvancements(Consumer<Advancement> consumer, ExistingFileHelper fileHelper)
|
||||
{
|
||||
Advancement.Builder.advancement().display(Items.DIRT,
|
||||
new TranslatableComponent(Items.DIRT.getDescriptionId()),
|
||||
new TranslatableComponent("dirt_description"),
|
||||
Component.translatable(Items.DIRT.getDescriptionId()),
|
||||
Component.translatable("dirt_description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
true,
|
||||
@@ -1038,8 +1036,8 @@ public class DataGeneratorTest
|
||||
.save(consumer, new ResourceLocation(MODID, "obtain_dirt"), fileHelper);
|
||||
|
||||
Advancement.Builder.advancement().display(Items.DIAMOND_BLOCK,
|
||||
new TranslatableComponent(Items.DIAMOND_BLOCK.getDescriptionId()),
|
||||
new TextComponent("You obtained a DiamondBlock"),
|
||||
Component.translatable(Items.DIAMOND_BLOCK.getDescriptionId()),
|
||||
Component.literal("You obtained a DiamondBlock"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.CHALLENGE,
|
||||
true,
|
||||
@@ -1050,8 +1048,8 @@ public class DataGeneratorTest
|
||||
|
||||
Advancement.Builder.advancement()
|
||||
.display(Blocks.GRASS_BLOCK,
|
||||
new TranslatableComponent("advancements.story.root.title"),
|
||||
new TextComponent("Changed Description"),
|
||||
Component.translatable("advancements.story.root.title"),
|
||||
Component.literal("Changed Description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
@@ -1074,8 +1072,8 @@ public class DataGeneratorTest
|
||||
.save(consumer, new ResourceLocation("illegal_parent"), fileHelper);*/
|
||||
|
||||
Advancement.Builder.advancement().display(Blocks.COBBLESTONE,
|
||||
new TranslatableComponent(Items.COBBLESTONE.getDescriptionId()),
|
||||
new TextComponent("You got cobblestone"),
|
||||
Component.translatable(Items.COBBLESTONE.getDescriptionId()),
|
||||
Component.literal("You got cobblestone"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
@@ -1097,7 +1095,7 @@ public class DataGeneratorTest
|
||||
}
|
||||
try {
|
||||
Resource vanillaResource = existingFileHelper.getResource(new ResourceLocation(loc.getPath()), PackType.CLIENT_RESOURCES, ".json", "models");
|
||||
JsonObject existing = GSON.fromJson(new InputStreamReader(vanillaResource.getInputStream()), JsonObject.class);
|
||||
JsonObject existing = GSON.fromJson(vanillaResource.openAsReader(), JsonObject.class);
|
||||
|
||||
JsonElement generatedDisplay = generated.remove("display");
|
||||
JsonElement vanillaDisplay = existing.remove("display");
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.PosRuleTestType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -36,7 +37,6 @@ import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
|
||||
@@ -50,8 +50,9 @@ public class DeferredRegistryTest {
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
private static final DeferredRegister<Custom> CUSTOMS = DeferredRegister.create(new ResourceLocation(MODID, "test_registry"), MODID);
|
||||
private static final DeferredRegister<Object> DOESNT_EXIST_REG = DeferredRegister.createOptional(new ResourceLocation(MODID, "doesnt_exist"), MODID);
|
||||
private static final DeferredRegister<RecipeType<?>> RECIPE_TYPES = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, MODID);
|
||||
// Vanilla Registry - filled directly after all RegistryEvent.Register events are fired
|
||||
private static final DeferredRegister<RecipeType<?>> RECIPE_TYPES = DeferredRegister.create(Registry.RECIPE_TYPE_REGISTRY, MODID);
|
||||
private static final DeferredRegister<PosRuleTestType<?>> POS_RULE_TEST_TYPES = DeferredRegister.create(Registry.POS_RULE_TEST_REGISTRY, MODID);
|
||||
// Vanilla Builtin Registry - filled directly after all RegistryEvent.Register events are fired
|
||||
private static final DeferredRegister<PlacedFeature> PLACED_FEATURES = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, MODID);
|
||||
|
||||
@@ -61,12 +62,13 @@ public class DeferredRegistryTest {
|
||||
// Should never be created as the registry doesn't exist - this should silently fail and remain empty
|
||||
private static final RegistryObject<Object> DOESNT_EXIST = DOESNT_EXIST_REG.register("test", Object::new);
|
||||
private static final RegistryObject<RecipeType<?>> RECIPE_TYPE = RECIPE_TYPES.register("test", () -> new RecipeType<>() {});
|
||||
private static final RegistryObject<PosRuleTestType<?>> POS_RULE_TEST_TYPE = POS_RULE_TEST_TYPES.register("test", () -> () -> null);
|
||||
private static final RegistryObject<PlacedFeature> PLACED_FEATURE = PLACED_FEATURES.register("test", () -> new PlacedFeature(Holder.hackyErase(OreFeatures.ORE_DIORITE), List.of()));
|
||||
|
||||
private static final TagKey<Custom> CUSTOM_TAG_KEY = CUSTOMS.createOptionalTagKey("test_tag", Set.of(CUSTOM));
|
||||
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(Custom.class, () ->
|
||||
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(() ->
|
||||
new RegistryBuilder<Custom>().disableSaving().setMaxID(Integer.MAX_VALUE - 1).hasTags()
|
||||
.onAdd((owner, stage, id, obj, old) -> LOGGER.info("Custom Added: " + id + " " + obj.foo()))
|
||||
.onAdd((owner, stage, id, key, obj, old) -> LOGGER.info("Custom Added: " + id + " " + obj.foo()))
|
||||
);
|
||||
|
||||
public DeferredRegistryTest() {
|
||||
@@ -75,6 +77,7 @@ public class DeferredRegistryTest {
|
||||
ITEMS.register(modBus);
|
||||
CUSTOMS.register(modBus);
|
||||
RECIPE_TYPES.register(modBus);
|
||||
POS_RULE_TEST_TYPES.register(modBus);
|
||||
PLACED_FEATURES.register(modBus);
|
||||
modBus.addListener(this::gatherData);
|
||||
|
||||
@@ -90,25 +93,24 @@ public class DeferredRegistryTest {
|
||||
if (DOESNT_EXIST.isPresent())
|
||||
throw new IllegalStateException("DeferredRegistryTest#DOESNT_EXIST should not be present!");
|
||||
RECIPE_TYPE.get();
|
||||
POS_RULE_TEST_TYPE.get();
|
||||
PLACED_FEATURE.get();
|
||||
}
|
||||
|
||||
public void gatherData(GatherDataEvent event) {
|
||||
DataGenerator gen = event.getGenerator();
|
||||
|
||||
if (event.includeClient()) {
|
||||
gen.addProvider(new BlockStateProvider(gen, MODID, event.getExistingFileHelper()) {
|
||||
@Override
|
||||
protected void registerStatesAndModels() {
|
||||
ModelFile model = models().cubeAll(BLOCK.get().getRegistryName().getPath(), mcLoc("block/furnace_top"));
|
||||
simpleBlock(BLOCK.get(), model);
|
||||
simpleBlockItem(BLOCK.get(), model);
|
||||
}
|
||||
});
|
||||
}
|
||||
gen.addProvider(event.includeClient(), new BlockStateProvider(gen, MODID, event.getExistingFileHelper()) {
|
||||
@Override
|
||||
protected void registerStatesAndModels() {
|
||||
ModelFile model = models().cubeAll(BLOCK.getId().getPath(), mcLoc("block/furnace_top"));
|
||||
simpleBlock(BLOCK.get(), model);
|
||||
simpleBlockItem(BLOCK.get(), model);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static class Custom extends ForgeRegistryEntry<Custom> {
|
||||
public static class Custom {
|
||||
public String foo() {
|
||||
return this.getClass().getName();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Tests that the values for defaulted optional tags defined in multiple places are combined.
|
||||
@@ -37,8 +38,12 @@ public class DuplicateOptionalTagTest
|
||||
static final String MODID = "duplicate_optional_tag_test";
|
||||
private static final ResourceLocation TAG_NAME = new ResourceLocation(MODID, "test_optional_tag");
|
||||
|
||||
private static final Set<Supplier<Block>> TAG_A_DEFAULTS = Set.of(Blocks.BEDROCK.delegate);
|
||||
private static final Set<Supplier<Block>> TAG_B_DEFAULTS = Set.of(Blocks.WHITE_WOOL.delegate);
|
||||
private static final Set<Supplier<Block>> TAG_A_DEFAULTS = Stream.of(Blocks.BEDROCK)
|
||||
.map(ForgeRegistries.BLOCKS::getDelegateOrThrow)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
private static final Set<Supplier<Block>> TAG_B_DEFAULTS = Stream.of(Blocks.WHITE_WOOL)
|
||||
.map(ForgeRegistries.BLOCKS::getDelegateOrThrow)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
private static final TagKey<Block> TAG_A = ForgeRegistries.BLOCKS.tags().createOptionalTagKey(TAG_NAME, TAG_A_DEFAULTS);
|
||||
private static final TagKey<Block> TAG_B = ForgeRegistries.BLOCKS.tags().createOptionalTagKey(TAG_NAME, TAG_B_DEFAULTS);
|
||||
|
||||
@@ -7,7 +7,7 @@ package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectCategory;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
@@ -131,7 +131,7 @@ public class ManyMobEffectsTest
|
||||
var effect = ((MobEffect) ObfuscationReflectionHelper.getPrivateValue(MushroomCow.class, cow, "f_289" + "09_"));
|
||||
if (effect != null)
|
||||
{
|
||||
event.getPlayer().sendMessage(new TextComponent(String.valueOf(effect.getRegistryName())), Util.NIL_UUID);
|
||||
event.getPlayer().sendSystemMessage(Component.literal(String.valueOf(ForgeRegistries.MOB_EFFECTS.getKey(effect))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ package net.minecraftforge.debug;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -32,7 +31,7 @@ public class PermissionTest
|
||||
private static final PermissionNode<Boolean> boolPerm = new PermissionNode<>("permissiontest", "test.blob", PermissionTypes.BOOLEAN, (player, playerUUID, context) -> true);
|
||||
private static final PermissionNode<String> stringPerm = new PermissionNode<>("permissiontest", "test.blobText", PermissionTypes.STRING, (player, playerUUID, context) -> "Hello World");
|
||||
private static final PermissionNode<Integer> intPerm = new PermissionNode<>("permissiontest", "test.blob.integer", PermissionTypes.INTEGER, (player, playerUUID, context) -> 3);
|
||||
private static final PermissionNode<Component> componentPerm = new PermissionNode<>("permissiontest", "test.blob.component", PermissionTypes.COMPONENT, (player, playerUUID, context) -> new TextComponent("This is a component"));
|
||||
private static final PermissionNode<Component> componentPerm = new PermissionNode<>("permissiontest", "test.blob.component", PermissionTypes.COMPONENT, (player, playerUUID, context) -> Component.literal("This is a component"));
|
||||
|
||||
private static final PermissionNode<Boolean> unregisteredPerm = new PermissionNode<>("permissiontest", "test.unregistered", PermissionTypes.BOOLEAN, (player, playerUUID, context) -> false);
|
||||
|
||||
@@ -57,9 +56,9 @@ public class PermissionTest
|
||||
event.getDispatcher().register(Commands.literal("permtest")
|
||||
.requires(src -> canUseCommand(src, boolPerm))
|
||||
.executes(context -> {
|
||||
context.getSource().sendSuccess(new TextComponent("Blob"), false);
|
||||
context.getSource().sendSuccess(new TextComponent("String:" + PermissionAPI.getPermission((ServerPlayer) context.getSource().getEntity(), stringPerm)), false);
|
||||
context.getSource().sendSuccess(new TextComponent("Int: " + PermissionAPI.getPermission((ServerPlayer) context.getSource().getEntity(), intPerm)), false);
|
||||
context.getSource().sendSuccess(Component.literal("Blob"), false);
|
||||
context.getSource().sendSuccess(Component.literal("String:" + PermissionAPI.getPermission((ServerPlayer) context.getSource().getEntity(), stringPerm)), false);
|
||||
context.getSource().sendSuccess(Component.literal("Int: " + PermissionAPI.getPermission((ServerPlayer) context.getSource().getEntity(), intPerm)), false);
|
||||
context.getSource().sendSuccess(PermissionAPI.getPermission((ServerPlayer) context.getSource().getEntity(), componentPerm), false);
|
||||
|
||||
return 1;
|
||||
@@ -70,7 +69,7 @@ public class PermissionTest
|
||||
event.getDispatcher().register(Commands.literal("permtesterr")
|
||||
.requires(src -> canUseCommand(src, unregisteredPerm))
|
||||
.executes(context -> {
|
||||
context.getSource().sendSuccess(new TextComponent("Blob"), false);
|
||||
context.getSource().sendSuccess(Component.literal("Blob"), false);
|
||||
return 1;
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ public class RegistryObjectTest
|
||||
public void commonSetup(FMLCommonSetupEvent event)
|
||||
{
|
||||
LOGGER.info("Stone 1: {}", RegistryObject.create(new ResourceLocation("minecraft", "stone"), ForgeRegistries.BLOCKS).get());
|
||||
LOGGER.info("Stone 2: {}", RegistryObject.create(new ResourceLocation("minecraft", "stone"), ForgeRegistries.BLOCKS.getRegistryKey(), MODID).get());
|
||||
LOGGER.info("Stone 2: {}", RegistryObject.create(new ResourceLocation("minecraft", "stone"), ForgeRegistries.Keys.BLOCKS, MODID).get());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
@@ -18,6 +17,7 @@ import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@Mod(RemoveTagDatagenTest.MODID)
|
||||
public class RemoveTagDatagenTest
|
||||
@@ -36,15 +36,15 @@ public class RemoveTagDatagenTest
|
||||
DataGenerator generator = event.getGenerator();
|
||||
ExistingFileHelper helper = event.getExistingFileHelper();
|
||||
|
||||
generator.addProvider(new BlockTagsProvider(generator, MODID, helper)
|
||||
generator.addProvider(true, new BlockTagsProvider(generator, MODID, helper)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void addTags()
|
||||
{
|
||||
this.tag(TEST_TAG)
|
||||
.remove(Blocks.DIRT.getRegistryName())
|
||||
.remove(Blocks.OAK_DOOR.getRegistryName(), Blocks.DARK_OAK_DOOR.getRegistryName())
|
||||
.remove(ForgeRegistries.BLOCKS.getKey(Blocks.DIRT))
|
||||
.remove(ForgeRegistries.BLOCKS.getKey(Blocks.OAK_DOOR), ForgeRegistries.BLOCKS.getKey(Blocks.DARK_OAK_DOOR))
|
||||
.remove(Blocks.ANVIL)
|
||||
.remove(Blocks.BASALT, Blocks.POLISHED_BASALT)
|
||||
.remove(BlockTags.BEEHIVES)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge - Forge Development LLC
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.world.item.BannerPatternItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.entity.BannerPattern;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@Mod("banner_pattern_test")
|
||||
public class BannerPatternTest
|
||||
{
|
||||
|
||||
private static final boolean ENABLED = true;
|
||||
|
||||
public BannerPatternTest()
|
||||
{
|
||||
if (!ENABLED) return;
|
||||
|
||||
BannerPattern.create("BANNER_PATTERN_TEST_TEST1", "banner_pattern_test:test1", "bpt:t1");
|
||||
var pattern = BannerPattern.create("BANNER_PATTERN_TEST_TEST2", "banner_pattern_test:test2", "bpt:t2", true);
|
||||
BannerPattern.create("BANNER_PATTERN_TEST_TEST3", "banner_pattern_test:test3", "bpt:t3");
|
||||
|
||||
var register = DeferredRegister.create(ForgeRegistries.ITEMS, "banner_pattern_test");
|
||||
register.register("pattern_item_test", () -> new BannerPatternItem(pattern, new Item.Properties().stacksTo(1).tab(CreativeModeTab.TAB_MISC)));
|
||||
register.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,9 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
|
||||
@Mod("be_onload_test")
|
||||
|
||||
@@ -19,11 +19,12 @@ import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.PlantType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
@Mod(CustomPlantTypeTest.MODID)
|
||||
@Mod.EventBusSubscriber(bus = Bus.MOD)
|
||||
@@ -33,22 +34,29 @@ public class CustomPlantTypeTest
|
||||
private static final String CUSTOM_SOIL_BLOCK = "test_custom_block";
|
||||
private static final String CUSTOM_PLANT_BLOCK = "test_custom_plant";
|
||||
|
||||
@ObjectHolder(CUSTOM_SOIL_BLOCK)
|
||||
@ObjectHolder(registryName = "block", value = CUSTOM_SOIL_BLOCK)
|
||||
public static Block CUSTOM_SOIL;
|
||||
@ObjectHolder(CUSTOM_PLANT_BLOCK)
|
||||
@ObjectHolder(registryName = "block", value = CUSTOM_PLANT_BLOCK)
|
||||
public static Block CUSTOM_PLANT;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
public static void registerBlocks(RegisterEvent event)
|
||||
{
|
||||
event.getRegistry().registerAll(new CustomBlock(), new CustomPlantBlock());
|
||||
event.register(ForgeRegistries.Keys.BLOCKS, helper ->
|
||||
{
|
||||
helper.register(CUSTOM_SOIL_BLOCK, new CustomBlock());
|
||||
helper.register(CUSTOM_PLANT_BLOCK, new CustomPlantBlock());
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
public static void registerItems(RegisterEvent event)
|
||||
{
|
||||
event.getRegistry().registerAll(new BlockItem(CUSTOM_SOIL, (new Item.Properties())).setRegistryName(MODID, CUSTOM_SOIL_BLOCK),
|
||||
new BlockItem(CUSTOM_PLANT, (new Item.Properties())).setRegistryName(MODID, CUSTOM_PLANT_BLOCK));
|
||||
event.register(ForgeRegistries.Keys.ITEMS, helper ->
|
||||
{
|
||||
helper.register(CUSTOM_SOIL_BLOCK, new BlockItem(CUSTOM_SOIL, new Item.Properties()));
|
||||
helper.register(CUSTOM_PLANT_BLOCK, new BlockItem(CUSTOM_PLANT, new Item.Properties()));
|
||||
});
|
||||
}
|
||||
|
||||
public static class CustomBlock extends Block
|
||||
@@ -56,7 +64,6 @@ public class CustomPlantTypeTest
|
||||
public CustomBlock()
|
||||
{
|
||||
super(Properties.of(Material.STONE));
|
||||
this.setRegistryName(MODID, CUSTOM_SOIL_BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +85,6 @@ public class CustomPlantTypeTest
|
||||
public CustomPlantBlock()
|
||||
{
|
||||
super(MobEffects.WEAKNESS, 9, Properties.of(Material.PLANT).noCollission().sound(SoundType.GRASS));
|
||||
this.setRegistryName(MODID, CUSTOM_PLANT_BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,8 +28,8 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mod(CustomRespawnTest.MODID)
|
||||
|
||||
@@ -10,9 +10,9 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.FlowerPotBlock;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
@@ -30,20 +30,26 @@ public class FlowerPotTest
|
||||
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
|
||||
|
||||
public static final RegistryObject<FlowerPotBlock> EMPTY_FLOWER_POT = BLOCKS.register(BLOCK_ID, () -> new FlowerPotBlock(null, Blocks.AIR.delegate, Block.Properties.copy(Blocks.FLOWER_POT)));
|
||||
public static final RegistryObject<FlowerPotBlock> EMPTY_FLOWER_POT = BLOCKS.register(BLOCK_ID, () -> new FlowerPotBlock(null, ForgeRegistries.BLOCKS.getDelegateOrThrow(Blocks.AIR), Block.Properties.copy(Blocks.FLOWER_POT)));
|
||||
public static final RegistryObject<FlowerPotBlock> OAK_FLOWER_POT = BLOCKS.<FlowerPotBlock>register(
|
||||
BLOCK_ID + "_oak", () -> new FlowerPotBlock(EMPTY_FLOWER_POT, Blocks.OAK_SAPLING.delegate, Block.Properties.copy(Blocks.FLOWER_POT)));
|
||||
BLOCK_ID + "_oak", () -> new FlowerPotBlock(EMPTY_FLOWER_POT, ForgeRegistries.BLOCKS.getDelegateOrThrow(Blocks.OAK_SAPLING), Block.Properties.copy(Blocks.FLOWER_POT)));
|
||||
|
||||
static {
|
||||
static
|
||||
{
|
||||
ITEMS.register(BLOCK_ID, () -> new BlockItem(EMPTY_FLOWER_POT.get(), new Item.Properties()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onItemRegister(RegistryEvent.Register<Item> event) {
|
||||
EMPTY_FLOWER_POT.get().addPlant(Blocks.OAK_SAPLING.getRegistryName(), OAK_FLOWER_POT);
|
||||
public static void onItemRegister(RegisterEvent event)
|
||||
{
|
||||
if (event.getRegistryKey().equals(ForgeRegistries.Keys.ITEMS))
|
||||
{
|
||||
EMPTY_FLOWER_POT.get().addPlant(ForgeRegistries.BLOCKS.getKey(Blocks.OAK_SAPLING), OAK_FLOWER_POT);
|
||||
}
|
||||
}
|
||||
|
||||
public FlowerPotTest() {
|
||||
public FlowerPotTest()
|
||||
{
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
BLOCKS.register(modBus);
|
||||
ITEMS.register(modBus);
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -50,9 +51,9 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
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;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -104,7 +105,7 @@ public class FullPotsAccessorDemo
|
||||
if (level.getBlockEntity(pos) instanceof DioriteFlowerPotBlockEntity be)
|
||||
{
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
boolean isFlower = stack.getItem() instanceof BlockItem item && ((FlowerPotBlock) Blocks.FLOWER_POT).getFullPotsView().containsKey(item.getRegistryName());
|
||||
boolean isFlower = stack.getItem() instanceof BlockItem item && ((FlowerPotBlock) Blocks.FLOWER_POT).getFullPotsView().containsKey(ForgeRegistries.ITEMS.getKey(item));
|
||||
boolean hasFlower = be.plant != Blocks.AIR;
|
||||
|
||||
if (isFlower != hasFlower)
|
||||
@@ -227,7 +228,7 @@ public class FullPotsAccessorDemo
|
||||
protected void saveAdditional(CompoundTag tag)
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
tag.putString("plant", plant.getRegistryName().toString());
|
||||
tag.putString("plant", ForgeRegistries.BLOCKS.getKey(plant).toString());
|
||||
super.saveAdditional(tag);
|
||||
}
|
||||
}
|
||||
@@ -284,9 +285,9 @@ public class FullPotsAccessorDemo
|
||||
|
||||
public DioritePotModel(BakedModel wrappedModel) { super(wrappedModel); }
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
|
||||
{
|
||||
List<BakedQuad> quads = new ArrayList<>(originalModel.getQuads(state, side, rand, extraData));
|
||||
|
||||
@@ -299,9 +300,9 @@ public class FullPotsAccessorDemo
|
||||
return quads;
|
||||
}
|
||||
|
||||
private List<BakedQuad> getPlantQuads(Block plant, @Nullable Direction face, Random rand)
|
||||
private List<BakedQuad> getPlantQuads(Block plant, @Nullable Direction face, RandomSource rand)
|
||||
{
|
||||
BlockState potState = ((FlowerPotBlock) Blocks.FLOWER_POT).getFullPotsView().getOrDefault(plant.getRegistryName(), Blocks.AIR.delegate).get().defaultBlockState();
|
||||
BlockState potState = ((FlowerPotBlock) Blocks.FLOWER_POT).getFullPotsView().getOrDefault(ForgeRegistries.BLOCKS.getKey(plant), ForgeRegistries.BLOCKS.getDelegateOrThrow(Blocks.AIR)).get().defaultBlockState();
|
||||
BakedModel potModel = Minecraft.getInstance().getBlockRenderer().getBlockModel(potState);
|
||||
|
||||
return potModel.getQuads(potState, face, rand, EmptyModelData.INSTANCE)
|
||||
|
||||
@@ -8,6 +8,7 @@ package net.minecraftforge.debug.block;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
@@ -22,7 +23,6 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.model.generators.BlockStateProvider;
|
||||
@@ -80,11 +80,11 @@ public class PistonEventTest
|
||||
{
|
||||
if (pistonHelper.resolve())
|
||||
{
|
||||
player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will extend moving %d blocks and destroy %d blocks", pistonHelper.getToPush().size(), pistonHelper.getToDestroy().size())), player.getUUID());
|
||||
player.sendSystemMessage(Component.literal(String.format(Locale.ENGLISH, "Piston will extend moving %d blocks and destroy %d blocks", pistonHelper.getToPush().size(), pistonHelper.getToDestroy().size())));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(new TextComponent("Piston won't extend"), player.getUUID());
|
||||
player.sendSystemMessage(Component.literal("Piston won't extend"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ public class PistonEventTest
|
||||
BlockPos targetPos = event.getFaceOffsetPos().relative(event.getDirection());
|
||||
boolean canPush = PistonBaseBlock.isPushable(event.getWorld().getBlockState(targetPos), (Level) event.getWorld(), event.getFaceOffsetPos(), event.getDirection().getOpposite(), false, event.getDirection());
|
||||
boolean isAir = event.getWorld().isEmptyBlock(targetPos);
|
||||
player.sendMessage(new TextComponent(String.format(Locale.ENGLISH, "Piston will retract moving %d blocks", !isAir && canPush ? 1 : 0)), player.getUUID());
|
||||
player.sendSystemMessage(Component.literal(String.format(Locale.ENGLISH, "Piston will retract moving %d blocks", !isAir && canPush ? 1 : 0)));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(new TextComponent("Piston will retract"), player.getUUID());
|
||||
player.sendSystemMessage(Component.literal("Piston will retract"));
|
||||
}
|
||||
}
|
||||
// Offset twice to see if retraction will pull cobblestone
|
||||
@@ -141,10 +141,7 @@ public class PistonEventTest
|
||||
{
|
||||
DataGenerator gen = event.getGenerator();
|
||||
|
||||
if (event.includeClient())
|
||||
{
|
||||
gen.addProvider(new BlockStates(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
gen.addProvider(event.includeClient(), new BlockStates(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
|
||||
private class BlockStates extends BlockStateProvider
|
||||
@@ -157,7 +154,7 @@ public class PistonEventTest
|
||||
@Override
|
||||
protected void registerStatesAndModels()
|
||||
{
|
||||
ModelFile model = models().cubeAll(shiftOnMove.get().getRegistryName().getPath(), mcLoc("block/furnace_top"));
|
||||
ModelFile model = models().cubeAll(shiftOnMove.getId().getPath(), mcLoc("block/furnace_top"));
|
||||
simpleBlock(shiftOnMove.get(), model);
|
||||
simpleBlockItem(shiftOnMove.get(), model);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Mod(RedstoneSidedConnectivityTest.MODID)
|
||||
public class RedstoneSidedConnectivityTest
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ScaffoldingTest
|
||||
private void gatherData(final GatherDataEvent event)
|
||||
{
|
||||
DataGenerator gen = event.getGenerator();
|
||||
if(event.includeClient()) gen.addProvider(new ScaffoldingBlockState(gen, MODID, event.getExistingFileHelper()));
|
||||
gen.addProvider(event.includeClient(), new ScaffoldingBlockState(gen, MODID, event.getExistingFileHelper()));
|
||||
}
|
||||
|
||||
static class ScaffoldingBlockState extends BlockStateProvider
|
||||
|
||||
@@ -14,11 +14,12 @@ import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
@Mod(SlipperinessTest.MOD_ID)
|
||||
@EventBusSubscriber
|
||||
@@ -27,26 +28,26 @@ public class SlipperinessTest
|
||||
static final String MOD_ID = "slipperiness_test";
|
||||
static final String BLOCK_ID = "test_block";
|
||||
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
@ObjectHolder(registryName = "block", value = BLOCK_ID)
|
||||
public static final Block BB_BLOCK = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> e)
|
||||
public static void registerBlocks(RegisterEvent e)
|
||||
{
|
||||
e.getRegistry().register((new Block(Block.Properties.of(Material.ICE_SOLID))
|
||||
e.register(ForgeRegistries.Keys.BLOCKS, helper -> helper.register(BLOCK_ID, new Block(Block.Properties.of(Material.ICE_SOLID))
|
||||
{
|
||||
@Override
|
||||
public float getFriction(BlockState state, LevelReader level, BlockPos pos, Entity entity)
|
||||
{
|
||||
return entity instanceof Boat ? 2 : super.getFriction(state, level, pos, entity);
|
||||
}
|
||||
}).setRegistryName(MOD_ID, BLOCK_ID));
|
||||
}));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> e)
|
||||
public static void registerItems(RegisterEvent e)
|
||||
{
|
||||
e.getRegistry().register(new BlockItem(BB_BLOCK, new Item.Properties()).setRegistryName(BB_BLOCK.getRegistryName()));
|
||||
e.register(ForgeRegistries.Keys.ITEMS, helper -> helper.register(BLOCK_ID, new BlockItem(BB_BLOCK, new Item.Properties())));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -10,11 +10,12 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
@Mod(StickyBlockTest.MODID)
|
||||
@Mod.EventBusSubscriber(bus = Bus.MOD)
|
||||
@@ -23,25 +24,25 @@ public class StickyBlockTest
|
||||
static final String MODID = "custom_slime_block_test";
|
||||
static final String BLOCK_ID = "test_block";
|
||||
|
||||
@ObjectHolder(BLOCK_ID)
|
||||
@ObjectHolder(registryName = "block", value = BLOCK_ID)
|
||||
public static Block BLUE_BLOCK;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
public static void registerBlocks(RegisterEvent event)
|
||||
{
|
||||
event.getRegistry().register((new Block(Block.Properties.of(Material.STONE))
|
||||
event.register(ForgeRegistries.Keys.BLOCKS, helper -> helper.register(BLOCK_ID, new Block(Block.Properties.of(Material.STONE))
|
||||
{
|
||||
@Override
|
||||
public boolean isStickyBlock(BlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}).setRegistryName(MODID, BLOCK_ID));
|
||||
}));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
public static void registerItems(RegisterEvent event)
|
||||
{
|
||||
event.getRegistry().register(new BlockItem(BLUE_BLOCK, new Item.Properties()).setRegistryName(MODID, BLOCK_ID));
|
||||
event.register(ForgeRegistries.Keys.ITEMS, helper -> helper.register(BLOCK_ID, new BlockItem(BLUE_BLOCK, new Item.Properties())));
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||
import net.minecraft.commands.arguments.TeamArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||
import net.minecraft.commands.synchronization.SuggestionProviders;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -49,21 +49,21 @@ public class ClientCommandTest
|
||||
.then(Commands.literal("server")
|
||||
.executes((context) -> {
|
||||
context.getSource().getServer();
|
||||
context.getSource().sendSuccess(new TextComponent("Successfully called getServer should have errored"), false);
|
||||
context.getSource().sendSuccess(Component.literal("Successfully called getServer should have errored"), false);
|
||||
return 1;
|
||||
}))
|
||||
// Used for checking if attempting to get the server level on the client side errors
|
||||
.then(Commands.literal("level")
|
||||
.executes((context) -> {
|
||||
context.getSource().getLevel();
|
||||
context.getSource().sendSuccess(new TextComponent("Successfully called getLevel should have errored"), false);
|
||||
context.getSource().sendSuccess(Component.literal("Successfully called getLevel should have errored"), false);
|
||||
return 1;
|
||||
}))
|
||||
// Used for checking if getting a known objective argument works on the client side
|
||||
.then(Commands.literal("get_objective")
|
||||
.then(Commands.argument("objective", ObjectiveArgument.objective())
|
||||
.executes((context) -> {
|
||||
context.getSource().sendSuccess(new TextComponent("Regular: ")
|
||||
context.getSource().sendSuccess(Component.literal("Regular: ")
|
||||
.append(ObjectiveArgument.getObjective(context, "objective").getFormattedDisplayName()), false);
|
||||
return 1;
|
||||
})))
|
||||
@@ -95,14 +95,14 @@ public class ClientCommandTest
|
||||
.then(Commands.argument("blockpos", BlockPosArgument.blockPos())
|
||||
.executes((context) -> {
|
||||
context.getSource()
|
||||
.sendSuccess(new TextComponent(BlockPosArgument.getLoadedBlockPos(context, "blockpos").toString()), false);
|
||||
.sendSuccess(Component.literal(BlockPosArgument.getLoadedBlockPos(context, "blockpos").toString()), false);
|
||||
return 1;
|
||||
})))
|
||||
// Used for checking if a command can have a requirement
|
||||
.then(Commands.literal("requires")
|
||||
.requires((source) -> false)
|
||||
.executes((context) -> {
|
||||
context.getSource().sendSuccess(new TextComponent("Executed command"), false);
|
||||
context.getSource().sendSuccess(Component.literal("Executed command"), false);
|
||||
return 1;
|
||||
})));
|
||||
|
||||
@@ -110,7 +110,7 @@ public class ClientCommandTest
|
||||
LiteralArgumentBuilder<CommandSourceStack> fork = Commands.literal("clientcommandfork");
|
||||
fork.fork(event.getDispatcher().getRoot(), (context) -> List.of(context.getSource(), context.getSource()))
|
||||
.executes((context) -> {
|
||||
context.getSource().sendSuccess(new TextComponent("Executing forked command"), false);
|
||||
context.getSource().sendSuccess(Component.literal("Executing forked command"), false);
|
||||
return 1;
|
||||
});
|
||||
event.getDispatcher().register(fork);
|
||||
@@ -118,12 +118,12 @@ public class ClientCommandTest
|
||||
|
||||
private int testCommand(CommandContext<CommandSourceStack> context)
|
||||
{
|
||||
context.getSource().sendSuccess(new TextComponent("Input: " + ResourceLocationArgument.getId(context, "block")), false);
|
||||
context.getSource().sendSuccess(new TextComponent("Teams: " + context.getSource().getAllTeams()), false);
|
||||
context.getSource().sendSuccess(new TextComponent("Players: " + context.getSource().getOnlinePlayerNames()), false);
|
||||
context.getSource().sendSuccess(new TextComponent("First recipe: " + context.getSource().getRecipeNames().findFirst().get()), false);
|
||||
context.getSource().sendSuccess(new TextComponent("Levels: " + context.getSource().levels()), false);
|
||||
context.getSource().sendSuccess(new TextComponent("Registry Access: " + context.getSource().registryAccess()), false);
|
||||
context.getSource().sendSuccess(Component.literal("Input: " + ResourceLocationArgument.getId(context, "block")), false);
|
||||
context.getSource().sendSuccess(Component.literal("Teams: " + context.getSource().getAllTeams()), false);
|
||||
context.getSource().sendSuccess(Component.literal("Players: " + context.getSource().getOnlinePlayerNames()), false);
|
||||
context.getSource().sendSuccess(Component.literal("First recipe: " + context.getSource().getRecipeNames().findFirst().get()), false);
|
||||
context.getSource().sendSuccess(Component.literal("Levels: " + context.getSource().levels()), false);
|
||||
context.getSource().sendSuccess(Component.literal("Registry Access: " + context.getSource().registryAccess()), false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.ParsedCommandNode;
|
||||
import net.minecraft.commands.CommandRuntimeException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -42,7 +42,7 @@ public class CommandEventTest
|
||||
if (nodes.size() > 0 && nodes.get(0).getNode() == dispatcher.getRoot().getChild("give"))
|
||||
{
|
||||
String msg = source.getTextName() + " used the give command: " + event.getParseResults().getReader().getString();
|
||||
source.getServer().getPlayerList().getPlayers().forEach(player -> player.sendMessage(new TextComponent(msg), player.getUUID()));
|
||||
source.getServer().getPlayerList().getPlayers().forEach(player -> player.sendSystemMessage(Component.literal(msg)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import net.minecraft.commands.arguments.selector.EntitySelectorParser;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.common.command.EntitySelectorManager;
|
||||
import net.minecraftforge.common.command.IEntitySelectorType;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -30,7 +29,7 @@ public class EntitySelectorTest
|
||||
|
||||
public void setup(FMLCommonSetupEvent event)
|
||||
{
|
||||
EntitySelectorOptions.register("health", this::healthArgument, parser -> true, new TextComponent("Selects entities based on their current health."));
|
||||
EntitySelectorOptions.register("health", this::healthArgument, parser -> true, Component.literal("Selects entities based on their current health."));
|
||||
EntitySelectorManager.register("er", new ExampleCustomSelector());
|
||||
}
|
||||
|
||||
@@ -76,7 +75,7 @@ public class EntitySelectorTest
|
||||
@Override
|
||||
public Component getSuggestionTooltip()
|
||||
{
|
||||
return new TextComponent("Example: Selects a random entity");
|
||||
return Component.literal("Example: Selects a random entity");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class AudioStreamTest
|
||||
{
|
||||
protected SineSound(Vec3 position)
|
||||
{
|
||||
super(new ResourceLocation(MOD_ID, "sine_wave"), SoundSource.BLOCKS);
|
||||
super(new ResourceLocation(MOD_ID, "sine_wave"), SoundSource.BLOCKS, SoundInstance.createUnseededRandom());
|
||||
x = position.x;
|
||||
y = position.y;
|
||||
z = position.z;
|
||||
|
||||
@@ -8,7 +8,6 @@ package net.minecraftforge.debug.client;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.EndermanModel;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.model.Model;
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
@@ -35,7 +34,6 @@ import net.minecraftforge.registries.RegistryObject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -68,7 +66,7 @@ public class CustomArmorModelTest
|
||||
{
|
||||
consumer.accept(new IItemRenderProperties()
|
||||
{
|
||||
@Override @Nonnull
|
||||
@Override @NotNull
|
||||
public Model getBaseArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot armorSlot, HumanoidModel<?> _default)
|
||||
{
|
||||
TintedArmorModel.INSTANCE.base = _default;
|
||||
@@ -118,7 +116,7 @@ public class CustomArmorModelTest
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderToBuffer(@Nonnull PoseStack poseStack, @Nonnull VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha)
|
||||
public void renderToBuffer(@NotNull PoseStack poseStack, @NotNull VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha)
|
||||
{
|
||||
if (base != null)
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ package net.minecraftforge.debug.client;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -26,6 +24,7 @@ import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Mod(CustomTASTest.MOD_ID)
|
||||
public class CustomTASTest
|
||||
@@ -55,7 +54,7 @@ public class CustomTASTest
|
||||
private static class TasLoader implements ITextureAtlasSpriteLoader
|
||||
{
|
||||
@Override
|
||||
@Nonnull
|
||||
@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(
|
||||
|
||||
@@ -19,7 +19,6 @@ import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
@@ -44,8 +43,8 @@ import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -113,7 +112,7 @@ public class CustomTooltipTest
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> components, TooltipFlag flag)
|
||||
{
|
||||
super.appendHoverText(stack, level, components, flag);
|
||||
components.add(new TextComponent("This is a very very very very very very long hover text that should really really be split across multiple lines.").withStyle(ChatFormatting.YELLOW));
|
||||
components.add(Component.literal("This is a very very very very very very long hover text that should really really be split across multiple lines.").withStyle(ChatFormatting.YELLOW));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,7 +191,7 @@ public class CustomTooltipTest
|
||||
|
||||
protected TooltipTestScreen()
|
||||
{
|
||||
super(new TextComponent("TooltipMethodTest"));
|
||||
super(Component.literal("TooltipMethodTest"));
|
||||
}
|
||||
|
||||
static void show()
|
||||
@@ -210,14 +209,14 @@ public class CustomTooltipTest
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
addRenderableWidget(new Button(10, 10, 200, 20, new TextComponent("Toggle Stack: EMPTY"), button -> {
|
||||
addRenderableWidget(new Button(10, 10, 200, 20, Component.literal("Toggle Stack: EMPTY"), button -> {
|
||||
this.testStack = this.testStack.isEmpty() ? new ItemStack(Items.APPLE) : ItemStack.EMPTY;
|
||||
button.setMessage(new TextComponent("Toggle Stack: " + (testStack.isEmpty() ? "EMPTY" : "Apple")));
|
||||
button.setMessage(Component.literal("Toggle Stack: " + (testStack.isEmpty() ? "EMPTY" : "Apple")));
|
||||
}));
|
||||
|
||||
addRenderableWidget(new Button(220, 10, 200, 20, new TextComponent("Toggle Font: null"), button -> {
|
||||
addRenderableWidget(new Button(220, 10, 200, 20, Component.literal("Toggle Font: null"), button -> {
|
||||
this.testFont = this.testFont == null ? ClientModBusEventHandler.customFont : null;
|
||||
button.setMessage(new TextComponent("Toggle Font: " + (testFont == null ? "null" : "customFont")));
|
||||
button.setMessage(Component.literal("Toggle Font: " + (testFont == null ? "null" : "customFont")));
|
||||
}));
|
||||
|
||||
// * must have stack context
|
||||
@@ -242,7 +241,7 @@ public class CustomTooltipTest
|
||||
int y = 50;
|
||||
for (var test : tooltipTests)
|
||||
{
|
||||
addRenderableWidget(new Button(x, y, 100, 20, new TextComponent(test.getKey()), button -> {}, test.getValue()));
|
||||
addRenderableWidget(new Button(x, y, 100, 20, Component.literal(test.getKey()), button -> {}, test.getValue()));
|
||||
y+= 22;
|
||||
if (y >= height - 50)
|
||||
{
|
||||
@@ -260,72 +259,72 @@ public class CustomTooltipTest
|
||||
// renderTooltip with List<Component> and all combinations of ItemStack/Font
|
||||
private void test2(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, List.of(new TextComponent("test")), Optional.empty(), mouseX, mouseY, this.testStack);
|
||||
renderTooltip(poseStack, List.of(Component.literal("test")), Optional.empty(), mouseX, mouseY, this.testStack);
|
||||
}
|
||||
|
||||
private void test3(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, List.of(new TextComponent("test")), Optional.empty(), mouseX, mouseY, this.testFont);
|
||||
renderTooltip(poseStack, List.of(Component.literal("test")), Optional.empty(), mouseX, mouseY, this.testFont);
|
||||
}
|
||||
|
||||
private void test4(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, List.of(new TextComponent("test")), Optional.empty(), mouseX, mouseY, this.testFont, this.testStack);
|
||||
renderTooltip(poseStack, List.of(Component.literal("test")), Optional.empty(), mouseX, mouseY, this.testFont, this.testStack);
|
||||
}
|
||||
|
||||
private void test5(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, List.of(new TextComponent("test")), Optional.empty(), mouseX, mouseY);
|
||||
renderTooltip(poseStack, List.of(Component.literal("test")), Optional.empty(), mouseX, mouseY);
|
||||
}
|
||||
|
||||
// renderTooltip with just Component
|
||||
private void test6(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, new TextComponent("test"), mouseX, mouseY);
|
||||
renderTooltip(poseStack, Component.literal("test"), mouseX, mouseY);
|
||||
}
|
||||
|
||||
// renderComponentTooltip with all combinations of ItemStack/Font
|
||||
private void test7(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderComponentTooltip(poseStack, List.of(new TextComponent("test")), mouseX, mouseY, this.testStack);
|
||||
renderComponentTooltip(poseStack, List.of(Component.literal("test")), mouseX, mouseY, this.testStack);
|
||||
}
|
||||
|
||||
private void test8(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderComponentTooltip(poseStack, List.of(new TextComponent("test")), mouseX, mouseY, this.testFont);
|
||||
renderComponentTooltip(poseStack, List.of(Component.literal("test")), mouseX, mouseY, this.testFont);
|
||||
}
|
||||
|
||||
private void test9(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderComponentTooltip(poseStack, List.of(new TextComponent("test")), mouseX, mouseY, this.testFont, this.testStack);
|
||||
renderComponentTooltip(poseStack, List.of(Component.literal("test")), mouseX, mouseY, this.testFont, this.testStack);
|
||||
}
|
||||
|
||||
private void test10(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderComponentTooltip(poseStack, List.of(new TextComponent("test")), mouseX, mouseY);
|
||||
renderComponentTooltip(poseStack, List.of(Component.literal("test")), mouseX, mouseY);
|
||||
}
|
||||
|
||||
// renderTooltip with list of FormattedCharSequence
|
||||
private void test11(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, List.of(new TextComponent("test").getVisualOrderText()), mouseX, mouseY);
|
||||
renderTooltip(poseStack, List.of(Component.literal("test").getVisualOrderText()), mouseX, mouseY);
|
||||
}
|
||||
|
||||
// renderTooltip with list of FormattedCharSequence and Font
|
||||
private void test12(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, List.of(new TextComponent("test").getVisualOrderText()), mouseX, mouseY, this.testFont);
|
||||
renderTooltip(poseStack, List.of(Component.literal("test").getVisualOrderText()), mouseX, mouseY, this.testFont);
|
||||
}
|
||||
|
||||
// legacy ToolTip methods
|
||||
private void test13(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderTooltip(poseStack, List.of(new TextComponent("test").getVisualOrderText()), mouseX, mouseY, this.testFont);
|
||||
renderTooltip(poseStack, List.of(Component.literal("test").getVisualOrderText()), mouseX, mouseY, this.testFont);
|
||||
}
|
||||
|
||||
private void test14(Button button, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
renderComponentTooltip(poseStack, List.of(new TextComponent("test")), mouseX, mouseY, this.testFont, ItemStack.EMPTY);
|
||||
renderComponentTooltip(poseStack, List.of(Component.literal("test")), mouseX, mouseY, this.testFont, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -33,11 +32,11 @@ public class GuiLayeringTest
|
||||
{
|
||||
if (event.getScreen() instanceof AbstractContainerScreen)
|
||||
{
|
||||
event.addListener(new Button(2, 2, 150, 20, new TextComponent("Test Gui Layering"), btn -> {
|
||||
Minecraft.getInstance().pushGuiLayer(new TestLayer(new TextComponent("LayerScreen")));
|
||||
event.addListener(new Button(2, 2, 150, 20, Component.literal("Test Gui Layering"), btn -> {
|
||||
Minecraft.getInstance().pushGuiLayer(new TestLayer(Component.literal("LayerScreen")));
|
||||
}));
|
||||
event.addListener(new Button(2, 25, 150, 20, new TextComponent("Test Gui Normal"), btn -> {
|
||||
Minecraft.getInstance().setScreen(new TestLayer(new TextComponent("LayerScreen")));
|
||||
event.addListener(new Button(2, 25, 150, 20, Component.literal("Test Gui Normal"), btn -> {
|
||||
Minecraft.getInstance().setScreen(new TestLayer(Component.literal("LayerScreen")));
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -73,9 +72,9 @@ public class GuiLayeringTest
|
||||
xoff = RANDOM.nextInt(xoff);
|
||||
yoff = RANDOM.nextInt(yoff);
|
||||
|
||||
this.addRenderableWidget(new Button(xoff, yoff + buttonSpacing * (cnt++), buttonWidth, buttonHeight, new TextComponent("Push New Layer"), this::pushLayerButton));
|
||||
this.addRenderableWidget(new Button(xoff, yoff + buttonSpacing * (cnt++), buttonWidth, buttonHeight, new TextComponent("Pop Current Layer"), this::popLayerButton));
|
||||
this.addRenderableWidget(new Button(xoff, yoff + buttonSpacing * (cnt++), buttonWidth, buttonHeight, new TextComponent("Close entire stack"), this::closeStack));
|
||||
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));
|
||||
}
|
||||
|
||||
private void closeStack(Button button)
|
||||
@@ -90,7 +89,7 @@ public class GuiLayeringTest
|
||||
|
||||
private void pushLayerButton(Button button)
|
||||
{
|
||||
this.minecraft.pushGuiLayer(new TestLayer(new TextComponent("LayerScreen")));
|
||||
this.minecraft.pushGuiLayer(new TestLayer(Component.literal("LayerScreen")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Mod(CompositeModelTest.MODID)
|
||||
public class CompositeModelTest
|
||||
|
||||
@@ -113,7 +113,7 @@ public class CustomTransformTypeTest
|
||||
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, MODID);
|
||||
|
||||
public static final RegistryObject<Block>
|
||||
ITEM_HANGER_BLOCK = BLOCKS.register("item_hanger", () -> new ItemHangerBlock(BlockBehaviour.Properties.of(Material.WOOL).noCollission().noOcclusion().noDrops()));
|
||||
ITEM_HANGER_BLOCK = BLOCKS.register("item_hanger", () -> new ItemHangerBlock(BlockBehaviour.Properties.of(Material.WOOL).noCollission().noOcclusion().noLootTable()));
|
||||
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>
|
||||
@@ -132,11 +132,8 @@ public class CustomTransformTypeTest
|
||||
{
|
||||
DataGenerator gen = event.getGenerator();
|
||||
|
||||
if (event.includeClient())
|
||||
{
|
||||
gen.addProvider(new ItemModels(gen, event.getExistingFileHelper()));
|
||||
gen.addProvider(new BlockStateModels(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
gen.addProvider(event.includeClient(), new ItemModels(gen, event.getExistingFileHelper()));
|
||||
gen.addProvider(event.includeClient(), new BlockStateModels(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
|
||||
public static class BlockStateModels extends BlockStateProvider
|
||||
|
||||
@@ -13,10 +13,12 @@ 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.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
@Mod(MultiLayerModelTest.MODID)
|
||||
public class MultiLayerModelTest
|
||||
@@ -27,33 +29,29 @@ public class MultiLayerModelTest
|
||||
|
||||
private static final String blockName = "test_layer_block";
|
||||
private static final ResourceLocation blockId = new ResourceLocation(MODID, blockName);
|
||||
@ObjectHolder(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
|
||||
{
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegisterEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
if (!ENABLED || !event.getRegistryKey().equals(ForgeRegistries.Keys.BLOCKS))
|
||||
return;
|
||||
event.getRegistry().register(
|
||||
new Block(Block.Properties.of(Material.WOOD).noOcclusion())
|
||||
{
|
||||
}.setRegistryName(blockId)
|
||||
);
|
||||
event.register(ForgeRegistries.Keys.BLOCKS, blockId, () -> new Block(Block.Properties.of(Material.WOOD).noOcclusion()));
|
||||
}
|
||||
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegisterEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
if (!ENABLED || !event.getRegistryKey().equals(ForgeRegistries.Keys.ITEMS))
|
||||
return;
|
||||
event.getRegistry().register(new BlockItem(TEST_BLOCK, new Item.Properties().tab(CreativeModeTab.TAB_MISC)).setRegistryName(TEST_BLOCK.getRegistryName()));
|
||||
event.register(ForgeRegistries.Keys.ITEMS, blockId, () -> new BlockItem(TEST_BLOCK, new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
|
||||
}
|
||||
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
@SubscribeEvent
|
||||
public static void clientSetup(FMLClientSetupEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
|
||||
@@ -50,7 +50,6 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
@@ -65,6 +64,7 @@ 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;
|
||||
|
||||
@Mod(NewModelLoaderTest.MODID)
|
||||
public class NewModelLoaderTest
|
||||
@@ -215,13 +215,10 @@ public class NewModelLoaderTest
|
||||
{
|
||||
DataGenerator gen = event.getGenerator();
|
||||
|
||||
if (event.includeClient())
|
||||
{
|
||||
// Let blockstate provider see generated item models by passing its existing file helper
|
||||
ItemModelProvider itemModels = new ItemModels(gen, event.getExistingFileHelper());
|
||||
gen.addProvider(itemModels);
|
||||
gen.addProvider(new BlockStates(gen, itemModels.existingFileHelper));
|
||||
}
|
||||
// Let blockstate provider see generated item models by passing its existing file helper
|
||||
ItemModelProvider itemModels = new ItemModels(gen, event.getExistingFileHelper());
|
||||
gen.addProvider(event.includeClient(), itemModels);
|
||||
gen.addProvider(event.includeClient(), new BlockStates(gen, itemModels.existingFileHelper));
|
||||
}
|
||||
|
||||
public static class ItemModels extends ItemModelProvider
|
||||
|
||||
@@ -6,12 +6,10 @@
|
||||
package net.minecraftforge.debug.client.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
@@ -41,6 +39,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Mod(TRSRTransformerTest.MODID)
|
||||
public class TRSRTransformerTest {
|
||||
@@ -75,7 +74,7 @@ public class TRSRTransformerTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data) {
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, IModelData data) {
|
||||
ImmutableList.Builder<BakedQuad> quads = new ImmutableList.Builder<>();
|
||||
|
||||
Quaternion rot = TransformationHelper.quatFromXYZ(new Vector3f(0, 45, 0), true);
|
||||
|
||||
+9
-5
@@ -25,11 +25,12 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -38,14 +39,17 @@ import java.util.Collections;
|
||||
public class EntityRendererEventsTest
|
||||
{
|
||||
private static final ResourceLocation MY_ENTITY = new ResourceLocation("entity_renderer_events_test", "test_entity");
|
||||
|
||||
@ObjectHolder("entity_renderer_events_test:test_entity")
|
||||
|
||||
@ObjectHolder(registryName = "entity_type", value = "entity_renderer_events_test:test_entity")
|
||||
public static EntityType<MyEntity> MY_ENTITY_TYPE;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void entityRegistry(RegistryEvent.Register<EntityType<?>> event)
|
||||
public static void entityRegistry(RegisterEvent event)
|
||||
{
|
||||
event.getRegistry().register(EntityType.Builder.of(MyEntity::new, MobCategory.MONSTER).build("test_entity").setRegistryName("test_entity"));
|
||||
if (event.getRegistryKey().equals(ForgeRegistries.Keys.ENTITY_TYPES))
|
||||
{
|
||||
event.register(ForgeRegistries.Keys.ENTITY_TYPES, MY_ENTITY, () -> EntityType.Builder.of(MyEntity::new, MobCategory.MONSTER).build("test_entity"));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
+2
-2
@@ -5,9 +5,9 @@
|
||||
|
||||
package net.minecraftforge.debug.client.rendering;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.animal.Cow;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.client.event.RenderNameplateEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
@@ -34,7 +34,7 @@ public class NameplateRenderingEventTest
|
||||
|
||||
if(event.getEntity() instanceof Cow)
|
||||
{
|
||||
event.setContent(new TextComponent("Evil Cow").withStyle(ChatFormatting.RED));
|
||||
event.setContent(Component.literal("Evil Cow").withStyle(ChatFormatting.RED));
|
||||
event.setResult(Event.Result.ALLOW);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package net.minecraftforge.debug.command;
|
||||
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -32,14 +32,14 @@ public class EnumArgumentTest
|
||||
event.getDispatcher().register(Commands.literal("enumargumenttest")
|
||||
.then(Commands.argument("string", StringArgumentType.string())
|
||||
.executes(context -> {
|
||||
context.getSource().sendSuccess(new TextComponent("string: " + StringArgumentType.getString(context, "string")), false);
|
||||
context.getSource().sendSuccess(Component.literal("string: " + StringArgumentType.getString(context, "string")), false);
|
||||
|
||||
return 1;
|
||||
}))
|
||||
.then(Commands.argument("enum", EnumArgument.enumArgument(ExampleEnum.class))
|
||||
.executes(context -> {
|
||||
context.getSource()
|
||||
.sendSuccess(new TextComponent("enum: " + context.getArgument("enum", ExampleEnum.class)), false);
|
||||
.sendSuccess(Component.literal("enum: " + context.getArgument("enum", ExampleEnum.class)), false);
|
||||
|
||||
return 1;
|
||||
})));
|
||||
|
||||
@@ -12,9 +12,12 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -31,10 +34,8 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeCategory;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -94,7 +95,8 @@ public class GravityAttributeTest
|
||||
for(LivingEntity liv : list)
|
||||
{
|
||||
AttributeInstance grav = liv.getAttribute(ForgeMod.ENTITY_GRAVITY.get());
|
||||
boolean inPlains = Biome.getBiomeCategory(liv.level.getBiome(liv.blockPosition())) == BiomeCategory.PLAINS;
|
||||
|
||||
boolean inPlains = liv.level.getBiome(liv.blockPosition()).is(BiomeTags.IS_FOREST);
|
||||
if (inPlains && !grav.hasModifier(REDUCED_GRAVITY))
|
||||
{
|
||||
logger.info("Granted low gravity to Entity: {}", liv);
|
||||
@@ -112,9 +114,10 @@ public class GravityAttributeTest
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerItems(RegistryEvent.Register<Item> event)
|
||||
public void registerItems(RegisterEvent event)
|
||||
{
|
||||
event.getRegistry().register(new ItemGravityStick(new Properties().tab(CreativeModeTab.TAB_TOOLS).rarity(Rarity.RARE)).setRegistryName("gravity_attribute_test:gravity_stick"));
|
||||
event.register(ForgeRegistries.Keys.ITEMS, helper -> helper.register("gravity_stick",
|
||||
new ItemGravityStick(new Properties().tab(CreativeModeTab.TAB_TOOLS).rarity(Rarity.RARE))));
|
||||
}
|
||||
|
||||
public static class ItemGravityStick extends Item
|
||||
|
||||
@@ -8,7 +8,7 @@ package net.minecraftforge.debug.entity;
|
||||
import net.minecraft.client.renderer.entity.PigRenderer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundAddMobPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
@@ -64,8 +64,8 @@ public class PartEntityTest
|
||||
event.registerEntityRenderer(TEST_ENTITY.get(), PigRenderer::new);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestEntity extends Pig
|
||||
|
||||
private static class TestEntity extends Pig
|
||||
{
|
||||
private final TestEntityPart[] subEntities;
|
||||
public final TestEntityPart head;
|
||||
@@ -76,8 +76,8 @@ public class PartEntityTest
|
||||
private final TestEntityPart tail3;
|
||||
private final TestEntityPart wing1;
|
||||
private final TestEntityPart wing2;
|
||||
|
||||
public TestEntity(EntityType<? extends Pig> entity, Level world)
|
||||
|
||||
public TestEntity(EntityType<? extends Pig> entity, Level world)
|
||||
{
|
||||
super(entity, world);
|
||||
this.head = new TestEntityPart(this, 1.0F, 1.0F);
|
||||
@@ -92,22 +92,22 @@ public class PartEntityTest
|
||||
}
|
||||
|
||||
@Override
|
||||
public void aiStep()
|
||||
public void aiStep()
|
||||
{
|
||||
super.aiStep();
|
||||
|
||||
for (TestEntityPart part : this.subEntities)
|
||||
for (TestEntityPart part : this.subEntities)
|
||||
{
|
||||
part.setPos(this.getX(), this.getY(), this.getZ());
|
||||
}
|
||||
|
||||
|
||||
Vec3[] vec3 = new Vec3[this.subEntities.length];
|
||||
for(int j = 0; j < this.subEntities.length; ++j)
|
||||
for(int j = 0; j < this.subEntities.length; ++j)
|
||||
{
|
||||
vec3[j] = new Vec3(this.subEntities[j].getX(), this.subEntities[j].getY(), this.subEntities[j].getZ());
|
||||
}
|
||||
|
||||
for(int l = 0; l < this.subEntities.length; ++l)
|
||||
|
||||
for(int l = 0; l < this.subEntities.length; ++l)
|
||||
{
|
||||
this.subEntities[l].xo = vec3[l].x;
|
||||
this.subEntities[l].yo = vec3[l].y;
|
||||
@@ -119,24 +119,24 @@ public class PartEntityTest
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultipartEntity()
|
||||
public boolean isMultipartEntity()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartEntity<?>[] getParts()
|
||||
public PartEntity<?>[] getParts()
|
||||
{
|
||||
return this.subEntities;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void recreateFromPacket(ClientboundAddMobPacket packet)
|
||||
public void recreateFromPacket(ClientboundAddEntityPacket packet)
|
||||
{
|
||||
super.recreateFromPacket(packet);
|
||||
PartEntity<?>[] parts = this.getParts();
|
||||
|
||||
for(int i = 0; i < parts.length; ++i)
|
||||
for(int i = 0; i < parts.length; ++i)
|
||||
{
|
||||
parts[i].setId(i + packet.getId());
|
||||
}
|
||||
@@ -144,12 +144,12 @@ public class PartEntityTest
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestEntityPart extends PartEntity<TestEntity>
|
||||
private static class TestEntityPart extends PartEntity<TestEntity>
|
||||
{
|
||||
public final TestEntity parent;
|
||||
private final EntityDimensions size;
|
||||
|
||||
public TestEntityPart(TestEntity parent, float width, float height)
|
||||
public TestEntityPart(TestEntity parent, float width, float height)
|
||||
{
|
||||
super(parent);
|
||||
this.size = EntityDimensions.scalable(width, height);
|
||||
@@ -163,32 +163,32 @@ public class PartEntityTest
|
||||
|
||||
protected void addAdditionalSaveData(CompoundTag nbt) {}
|
||||
|
||||
public boolean isPickable()
|
||||
public boolean isPickable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hurt(DamageSource source, float amount)
|
||||
public boolean hurt(DamageSource source, float amount)
|
||||
{
|
||||
return !this.isInvulnerableTo(source) && this.parent.hurt(source, amount);
|
||||
}
|
||||
|
||||
public boolean is(Entity entity)
|
||||
public boolean is(Entity entity)
|
||||
{
|
||||
return this == entity || this.parent == entity;
|
||||
}
|
||||
|
||||
public Packet<?> getAddEntityPacket()
|
||||
public Packet<?> getAddEntityPacket()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public EntityDimensions getDimensions(Pose matrix)
|
||||
public EntityDimensions getDimensions(Pose matrix)
|
||||
{
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public boolean shouldBeSaved()
|
||||
public boolean shouldBeSaved()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.minecraftforge.debug.entity.player;
|
||||
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -20,6 +20,6 @@ public class PlayerNameEventTest
|
||||
public static void onPlayerNameEvent(PlayerEvent.NameFormat event)
|
||||
{
|
||||
if (!ENABLE) return;
|
||||
event.setDisplayname(new TextComponent("Test Name"));
|
||||
event.setDisplayname(Component.literal("Test Name"));
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
package net.minecraftforge.debug.fluid;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
@@ -34,7 +34,7 @@ public class MilkFluidTest
|
||||
ItemStack stack = event.getItemStack();
|
||||
if (stack.getItem() == Items.MILK_BUCKET)
|
||||
{
|
||||
FluidUtil.getFluidContained(stack).ifPresent((fluid) -> event.getPlayer().displayClientMessage(new TextComponent("Contains ").append(fluid.getDisplayName()), true));
|
||||
FluidUtil.getFluidContained(stack).ifPresent((fluid) -> event.getPlayer().displayClientMessage(Component.literal("Contains ").append(fluid.getDisplayName()), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class NewFluidTest
|
||||
);
|
||||
|
||||
public static RegistryObject<LiquidBlock> test_fluid_block = BLOCKS.register("test_fluid_block", () ->
|
||||
new LiquidBlock(test_fluid, Properties.of(Material.WATER).noCollission().strength(100.0F).noDrops())
|
||||
new LiquidBlock(test_fluid, Properties.of(Material.WATER).noCollission().strength(100.0F).noLootTable())
|
||||
);
|
||||
public static RegistryObject<Item> test_fluid_bucket = ITEMS.register("test_fluid_bucket", () ->
|
||||
new BucketItem(test_fluid, new Item.Properties().craftRemainder(Items.BUCKET).stacksTo(1).tab(CreativeModeTab.TAB_MISC))
|
||||
@@ -82,7 +82,7 @@ public class NewFluidTest
|
||||
|
||||
// WARNING: this doesn't allow "any fluid", only the fluid from this test mod!
|
||||
public static RegistryObject<Block> fluidloggable_block = BLOCKS.register("fluidloggable_block", () ->
|
||||
new FluidloggableBlock(Properties.of(Material.WOOD).noCollission().strength(100.0F).noDrops())
|
||||
new FluidloggableBlock(Properties.of(Material.WOOD).noCollission().strength(100.0F).noLootTable())
|
||||
);
|
||||
public static RegistryObject<Item> fluidloggable_blockitem = ITEMS.register("fluidloggable_block", () ->
|
||||
new BlockItem(fluidloggable_block.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC))
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.debug.gameplay.loot;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.advancements.critereon.EnchantmentPredicate;
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||
@@ -46,8 +47,8 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -81,7 +82,7 @@ public class GlobalLootModifiersTest {
|
||||
public static void runData(GatherDataEvent event)
|
||||
{
|
||||
if(ENABLE)
|
||||
event.getGenerator().addProvider(new DataProvider(event.getGenerator(), MODID));
|
||||
event.getGenerator().addProvider(event.includeServer(), new DataProvider(event.getGenerator(), MODID));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,10 +134,10 @@ public class GlobalLootModifiersTest {
|
||||
super(conditionsIn);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
public ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||
ObjectArrayList<ItemStack> ret = new ObjectArrayList<ItemStack>();
|
||||
generatedLoot.forEach((stack) -> ret.add(smelt(stack, context)));
|
||||
return ret;
|
||||
}
|
||||
@@ -171,9 +172,9 @@ public class GlobalLootModifiersTest {
|
||||
super(conditionsIn);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
|
||||
public ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||
ItemStack ctxTool = context.getParamOrNull(LootContextParams.TOOL);
|
||||
//return early if silk-touch is already applied (otherwise we'll get stuck in an infinite loop).
|
||||
if(EnchantmentHelper.getEnchantments(ctxTool).containsKey(Enchantments.SILK_TOUCH)) return generatedLoot;
|
||||
@@ -215,9 +216,9 @@ public class GlobalLootModifiersTest {
|
||||
itemReward = reward;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
|
||||
public ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||
//
|
||||
// Additional conditions can be checked, though as much as possible should be parameterized via JSON data.
|
||||
// It is better to write a new ILootCondition implementation than to do things here.
|
||||
@@ -271,11 +272,11 @@ public class GlobalLootModifiersTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
|
||||
protected ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||
return generatedLoot.stream()
|
||||
.map(ItemStack::copy)
|
||||
.peek(stack -> stack.setCount(Math.min(stack.getMaxStackSize(), stack.getCount() * this.multiplicationFactor)))
|
||||
.collect(Collectors.toList());
|
||||
.collect(Collectors.toCollection(ObjectArrayList::new));
|
||||
}
|
||||
|
||||
private static class Serializer extends GlobalLootModifierSerializer<DungeonLootEnhancerModifier> {
|
||||
|
||||
@@ -27,14 +27,13 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.item.Item.Properties;
|
||||
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Mod(CustomElytraTest.MOD_ID)
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = CustomElytraTest.MOD_ID)
|
||||
@@ -100,7 +99,7 @@ public class CustomElytraTest
|
||||
{
|
||||
stack.hurtAndBreak(1, entity, e -> e.broadcastBreakEvent(EquipmentSlot.CHEST));
|
||||
}
|
||||
entity.gameEvent(GameEvent.ELYTRA_FREE_FALL);
|
||||
entity.gameEvent(GameEvent.ELYTRA_GLIDE);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -110,73 +110,67 @@ public class TagBasedToolTypesTest
|
||||
DataGenerator gen = event.getGenerator();
|
||||
ExistingFileHelper existing = event.getExistingFileHelper();
|
||||
|
||||
if (event.includeServer())
|
||||
gen.addProvider(event.includeServer(), new BlockTagsProvider(gen, MODID, existing)
|
||||
{
|
||||
gen.addProvider(new BlockTagsProvider(gen, MODID, existing)
|
||||
@Override
|
||||
protected void addTags()
|
||||
{
|
||||
@Override
|
||||
protected void addTags()
|
||||
{
|
||||
this.tag(MINEABLE_TAG).add(STONE.get());
|
||||
this.tag(REQUIRES_TAG).add(STONE.get());
|
||||
}
|
||||
});
|
||||
this.tag(MINEABLE_TAG).add(STONE.get());
|
||||
this.tag(REQUIRES_TAG).add(STONE.get());
|
||||
}
|
||||
});
|
||||
|
||||
gen.addProvider(new LootTableProvider(gen)
|
||||
gen.addProvider(event.includeServer(), new LootTableProvider(gen)
|
||||
{
|
||||
@Override
|
||||
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext validationtracker)
|
||||
{
|
||||
@Override
|
||||
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext validationtracker)
|
||||
{
|
||||
map.forEach((name, table) -> LootTables.validate(validationtracker, name, table));
|
||||
}
|
||||
map.forEach((name, table) -> LootTables.validate(validationtracker, name, table));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables()
|
||||
@Override
|
||||
protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables()
|
||||
{
|
||||
return ImmutableList.of(Pair.of(() ->
|
||||
{
|
||||
return ImmutableList.of(Pair.of(() ->
|
||||
return new BlockLoot()
|
||||
{
|
||||
return new BlockLoot()
|
||||
|
||||
@Override
|
||||
protected Iterable<Block> getKnownBlocks()
|
||||
{
|
||||
return BLOCKS.getEntries().stream().map(Supplier::get).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<Block> getKnownBlocks()
|
||||
{
|
||||
return BLOCKS.getEntries().stream().map(Supplier::get).collect(Collectors.toList());
|
||||
}
|
||||
@Override
|
||||
protected void addTables()
|
||||
{
|
||||
this.dropSelf(STONE.get());
|
||||
}
|
||||
};
|
||||
}, LootContextParamSets.BLOCK));
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
protected void addTables()
|
||||
{
|
||||
this.dropSelf(STONE.get());
|
||||
}
|
||||
};
|
||||
}, LootContextParamSets.BLOCK));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (event.includeClient())
|
||||
gen.addProvider(event.includeClient(), new BlockStateProvider(gen, MODID, existing)
|
||||
{
|
||||
gen.addProvider(new BlockStateProvider(gen, MODID, existing)
|
||||
@Override
|
||||
protected void registerStatesAndModels()
|
||||
{
|
||||
@Override
|
||||
protected void registerStatesAndModels()
|
||||
{
|
||||
ModelFile model = models().cubeAll(STONE.get().getRegistryName().getPath(), mcLoc("block/debug"));
|
||||
simpleBlock(STONE.get(), model);
|
||||
simpleBlockItem(STONE.get(), model);
|
||||
}
|
||||
});
|
||||
gen.addProvider(new ItemModelProvider(gen, MODID, existing)
|
||||
ModelFile model = models().cubeAll(STONE.getId().getPath(), mcLoc("block/debug"));
|
||||
simpleBlock(STONE.get(), model);
|
||||
simpleBlockItem(STONE.get(), model);
|
||||
}
|
||||
});
|
||||
gen.addProvider(event.includeClient(), new ItemModelProvider(gen, MODID, existing)
|
||||
{
|
||||
@Override
|
||||
protected void registerModels()
|
||||
{
|
||||
@Override
|
||||
protected void registerModels()
|
||||
{
|
||||
getBuilder(TOOL.get().getRegistryName().getPath())
|
||||
.parent(new UncheckedModelFile("item/generated"))
|
||||
.texture("layer0", mcLoc("item/wooden_pickaxe"));
|
||||
}
|
||||
});
|
||||
}
|
||||
getBuilder(TOOL.getId().getPath())
|
||||
.parent(new UncheckedModelFile("item/generated"))
|
||||
.texture("layer0", mcLoc("item/wooden_pickaxe"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -22,31 +22,31 @@ import net.minecraft.world.item.Items;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
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.network.NetworkHooks;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
@Mod("containertypetest")
|
||||
public class ContainerTypeTest
|
||||
{
|
||||
@ObjectHolder("containertypetest:container")
|
||||
@ObjectHolder(registryName = "menu", value = "containertypetest:container")
|
||||
public static final MenuType<TestContainer> TYPE = null;
|
||||
public class TestContainer extends AbstractContainerMenu
|
||||
{
|
||||
private final String text;
|
||||
|
||||
|
||||
protected TestContainer(int windowId, Inventory playerInv, FriendlyByteBuf extraData)
|
||||
{
|
||||
this(windowId, new SimpleContainer(9), extraData.readUtf(128));
|
||||
}
|
||||
|
||||
|
||||
public TestContainer(int windowId, SimpleContainer inv, String text)
|
||||
{
|
||||
super(TYPE, windowId);
|
||||
@@ -57,13 +57,19 @@ public class ContainerTypeTest
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player p_38941_, int p_38942_)
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player playerIn)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class TestGui extends AbstractContainerScreen<TestContainer>
|
||||
{
|
||||
public TestGui(TestContainer container, Inventory inv, Component name)
|
||||
@@ -80,21 +86,21 @@ public class ContainerTypeTest
|
||||
|
||||
public ContainerTypeTest()
|
||||
{
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(MenuType.class, this::registerContainers);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerContainers);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::onRightClick);
|
||||
}
|
||||
|
||||
private void registerContainers(final RegistryEvent.Register<MenuType<?>> event)
|
||||
private void registerContainers(final RegisterEvent event)
|
||||
{
|
||||
event.getRegistry().register(IForgeMenuType.create(TestContainer::new).setRegistryName("container"));
|
||||
event.register(ForgeRegistries.Keys.CONTAINER_TYPES, helper -> helper.register("container", IForgeMenuType.create(TestContainer::new)));
|
||||
}
|
||||
|
||||
|
||||
private void setup(FMLClientSetupEvent event)
|
||||
{
|
||||
MenuScreens.register(TYPE, TestGui::new);
|
||||
}
|
||||
|
||||
|
||||
private void onRightClick(PlayerInteractEvent.RightClickBlock event)
|
||||
{
|
||||
if (!event.getWorld().isClientSide && event.getHand() == InteractionHand.MAIN_HAND)
|
||||
@@ -114,11 +120,11 @@ public class ContainerTypeTest
|
||||
}
|
||||
return new TestContainer(p_createMenu_1_, inv, text);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Component getDisplayName()
|
||||
{
|
||||
return new TextComponent("Test");
|
||||
return Component.literal("Test");
|
||||
}
|
||||
}, extraData -> {
|
||||
extraData.writeUtf(text);
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -42,7 +43,6 @@ import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.fml.util.thread.EffectiveSide;
|
||||
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DataPackRegistriesTest
|
||||
public static final String MODID = "data_pack_registries_test";
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final ResourceLocation TEST_RL = new ResourceLocation(MODID, "test");
|
||||
|
||||
|
||||
private final RegistryObject<Unsyncable> datagenTestObject;
|
||||
|
||||
public DataPackRegistriesTest()
|
||||
@@ -75,40 +75,36 @@ public class DataPackRegistriesTest
|
||||
|
||||
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
final IEventBus forgeBus = MinecraftForge.EVENT_BUS;
|
||||
|
||||
|
||||
// Deferred Registers can be created for datapack registries in static init or mod constructor.
|
||||
// (We'll do it in mod constructor, as when doing the ENABLED check it's less verbose than static init.)
|
||||
// As with static registries, any mod can make a Deferred Register for a given datapack registry,
|
||||
// but only one mod can register the internal registry with makeRegistry.
|
||||
final DeferredRegister<Unsyncable> unsyncables = DeferredRegister.create(Unsyncable.REGISTRY_KEY, MODID);
|
||||
final DeferredRegister<Syncable> syncables = DeferredRegister.create(Syncable.REGISTRY_KEY, MODID);
|
||||
|
||||
|
||||
// RegistryBuilder#dataPackRegistry marks the registry as a datapack registry rather than a static registry.
|
||||
unsyncables.makeRegistry(Unsyncable.class,
|
||||
() -> new RegistryBuilder<Unsyncable>().disableSaving().dataPackRegistry(Unsyncable.DIRECT_CODEC));
|
||||
unsyncables.makeRegistry(() -> new RegistryBuilder<Unsyncable>().disableSaving().dataPackRegistry(Unsyncable.DIRECT_CODEC));
|
||||
// The overload of #dataPackRegistry that takes a second codec marks the datapack registry as syncable.
|
||||
syncables.makeRegistry(Syncable.class,
|
||||
() -> new RegistryBuilder<Syncable>().disableSaving().dataPackRegistry(Syncable.DIRECT_CODEC, Syncable.DIRECT_CODEC));
|
||||
|
||||
syncables.makeRegistry(() -> new RegistryBuilder<Syncable>().disableSaving().dataPackRegistry(Syncable.DIRECT_CODEC, Syncable.DIRECT_CODEC));
|
||||
|
||||
// Datapack registry elements can be datagenerated, but they must be registered as builtin objects first.
|
||||
this.datagenTestObject = unsyncables.register("datagen_test", () -> new Unsyncable("Datagen Success"));
|
||||
|
||||
|
||||
unsyncables.register(modBus);
|
||||
syncables.register(modBus);
|
||||
|
||||
|
||||
modBus.addListener(this::onGatherData);
|
||||
forgeBus.addListener(this::onServerStarting);
|
||||
|
||||
|
||||
if (FMLEnvironment.dist == Dist.CLIENT)
|
||||
{
|
||||
ClientEvents.subscribeClientEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onGatherData(final GatherDataEvent event)
|
||||
{
|
||||
if (!event.includeServer())
|
||||
return;
|
||||
// Example of how to datagen datapack registry objects.
|
||||
// Objects to be datagenerated must be registered (e.g. via DeferredRegister above).
|
||||
// This outputs to data/data_pack_registries_test/data_pack_registries_test/unsyncable/datagen_test.json
|
||||
@@ -121,10 +117,11 @@ public class DataPackRegistriesTest
|
||||
final Unsyncable element = this.datagenTestObject.get();
|
||||
final String pathString = String.join("/", PackType.SERVER_DATA.getDirectory(), id.getNamespace(), registryId.getNamespace(), registryId.getPath(), id.getPath()+".json");
|
||||
final Path path = outputFolder.resolve(pathString);
|
||||
generator.addProvider(new DataProvider()
|
||||
|
||||
generator.addProvider(event.includeServer(), new DataProvider()
|
||||
{
|
||||
@Override
|
||||
public void run(final HashCache cache) throws IOException
|
||||
public void run(final CachedOutput cache) throws IOException
|
||||
{
|
||||
Unsyncable.DIRECT_CODEC.encodeStart(ops, element)
|
||||
.resultOrPartial(msg -> LOGGER.error("Failed to encode {}: {}", path, msg)) // Log error on encode failure.
|
||||
@@ -132,7 +129,7 @@ public class DataPackRegistriesTest
|
||||
{
|
||||
try
|
||||
{
|
||||
DataProvider.save(gson, cache, json, path);
|
||||
DataProvider.saveStable(cache, json, path);
|
||||
}
|
||||
catch (IOException e) // The throws can't deal with this exception, because we're inside the ifPresent.
|
||||
{
|
||||
@@ -148,7 +145,7 @@ public class DataPackRegistriesTest
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void onServerStarting(final ServerStartingEvent event)
|
||||
{
|
||||
// Assert existence of json objects and tags.
|
||||
@@ -162,17 +159,17 @@ public class DataPackRegistriesTest
|
||||
final TagKey<Unsyncable> tag = TagKey.create(Unsyncable.REGISTRY_KEY, TEST_RL);
|
||||
if (!registry.getTag(tag).get().contains(holder))
|
||||
throw new IllegalStateException(String.format(Locale.ENGLISH, "Tag %s does not contain %s", tag, TEST_RL));
|
||||
|
||||
|
||||
LOGGER.info("DataPackRegistriesTest server data loaded successfully!");
|
||||
}
|
||||
|
||||
|
||||
public static class ClientEvents
|
||||
{
|
||||
private static void subscribeClientEvents()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.addListener(ClientEvents::onClientTagsUpdated);
|
||||
}
|
||||
|
||||
|
||||
private static void onClientTagsUpdated(final TagsUpdatedEvent event)
|
||||
{
|
||||
// We want to check whether tags have been synced after the player logs in.
|
||||
@@ -196,12 +193,12 @@ public class DataPackRegistriesTest
|
||||
final TagKey<Syncable> tag = TagKey.create(Syncable.REGISTRY_KEY, TEST_RL);
|
||||
if (!registry.getTag(tag).get().contains(holder))
|
||||
throw new IllegalStateException(String.format(Locale.ENGLISH, "Tag %s does not contain %s", tag, TEST_RL));
|
||||
|
||||
|
||||
LOGGER.info("DataPackRegistriesTest client data synced successfully!");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Unsyncable extends ForgeRegistryEntry<Unsyncable>
|
||||
public static class Unsyncable
|
||||
{
|
||||
public static final ResourceKey<Registry<Unsyncable>> REGISTRY_KEY = ResourceKey.createRegistryKey(new ResourceLocation(MODID, "unsyncable"));
|
||||
public static final Codec<Unsyncable> DIRECT_CODEC = Codec.STRING.fieldOf("value").codec().xmap(Unsyncable::new, Unsyncable::value);
|
||||
@@ -218,19 +215,19 @@ public class DataPackRegistriesTest
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Syncable extends ForgeRegistryEntry<Syncable>
|
||||
|
||||
public static class Syncable
|
||||
{
|
||||
public static final ResourceKey<Registry<Syncable>> REGISTRY_KEY = ResourceKey.createRegistryKey(new ResourceLocation(MODID, "syncable"));
|
||||
public static final Codec<Syncable> DIRECT_CODEC = Codec.STRING.fieldOf("value").codec().xmap(Syncable::new, Syncable::value);
|
||||
|
||||
|
||||
private final String value;
|
||||
|
||||
|
||||
public Syncable(final String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
public String value()
|
||||
{
|
||||
return this.value;
|
||||
|
||||
@@ -25,12 +25,11 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* This test mod show a few example usages of {@link IForgeRegistry#getCodec()} to serialize and deserialize {@link IForgeRegistryEntry} to json or nbt.
|
||||
* This test mod show a few example usages of {@link IForgeRegistry#getCodec()} to serialize and deserialize registry entries to JSON or NBT.
|
||||
* There are 4 tested cases :
|
||||
* 1. json -> Pair
|
||||
* 2. Pair -> nbt
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class RecipeBookExtensionClientHelper
|
||||
{
|
||||
RecipeBookRegistry.addCategoriesToType(RecipeBookExtensionTest.TEST_TYPE, ImmutableList.of(TESTING_SEARCH.get(), TESTING_CAT_1.get(), TESTING_CAT_2.get()));
|
||||
RecipeBookRegistry.addAggregateCategories(TESTING_SEARCH.get(), ImmutableList.of(TESTING_CAT_1.get(), TESTING_CAT_2.get()));
|
||||
RecipeBookRegistry.addCategoriesFinder(RecipeBookTestRecipe.TYPE.get(), r ->
|
||||
RecipeBookRegistry.addCategoriesFinder(RecipeBookExtensionTest.RECIPE_BOOK_TEST_RECIPE_TYPE.get(), r ->
|
||||
{
|
||||
if (r.getResultItem().getItem() == Items.DIAMOND_BLOCK)
|
||||
return TESTING_CAT_1.get();
|
||||
|
||||
+25
-16
@@ -6,7 +6,7 @@
|
||||
package net.minecraftforge.debug.recipe.recipebook;
|
||||
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
@@ -14,19 +14,18 @@ import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.RecipeBookType;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
@@ -49,22 +48,20 @@ public class RecipeBookExtensionTest
|
||||
public static final RegistryObject<MenuType<RecipeBookTestMenu>> RECIPE_BOOK_TEST_MENU_TYPE =
|
||||
MENU_TYPE.register("test_recipe_menu", () -> IForgeMenuType.create(RecipeBookTestMenu::new));
|
||||
|
||||
public static final DeferredRegister<RecipeType<?>> RECIPE_TYPE = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, MOD_ID);
|
||||
public static final RegistryObject<RecipeType<RecipeBookTestRecipe>> RECIPE_BOOK_TEST_RECIPE_TYPE = registerRecipeType("test_recipe");
|
||||
|
||||
public RecipeBookExtensionTest()
|
||||
{
|
||||
if (!ENABLED)
|
||||
return;
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
|
||||
RECIPE_SERIALIZER.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
MENU_TYPE.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
MinecraftForge.EVENT_BUS.addListener(this::onRightClick);
|
||||
}
|
||||
|
||||
private void commonSetup(FMLCommonSetupEvent event)
|
||||
{
|
||||
event.enqueueWork(() ->
|
||||
{
|
||||
RecipeType.register(getId("test_recipe").toString());
|
||||
});
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
RECIPE_SERIALIZER.register(modBus);
|
||||
MENU_TYPE.register(modBus);
|
||||
RECIPE_TYPE.register(modBus);
|
||||
|
||||
MinecraftForge.EVENT_BUS.addListener(this::onRightClick);
|
||||
}
|
||||
|
||||
private void onRightClick(PlayerInteractEvent.RightClickBlock event)
|
||||
@@ -72,7 +69,7 @@ public class RecipeBookExtensionTest
|
||||
if (event.getWorld().isClientSide)
|
||||
return;
|
||||
if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.GRASS_BLOCK)
|
||||
NetworkHooks.openGui((ServerPlayer) event.getPlayer(), new SimpleMenuProvider((id, inv, p) -> new RecipeBookTestMenu(id, inv, ContainerLevelAccess.create(event.getWorld(), event.getPos())), new TextComponent("Test")));
|
||||
NetworkHooks.openGui((ServerPlayer) event.getPlayer(), new SimpleMenuProvider((id, inv, p) -> new RecipeBookTestMenu(id, inv, ContainerLevelAccess.create(event.getWorld(), event.getPos())), Component.literal("Test")));
|
||||
}
|
||||
|
||||
public static ResourceLocation getId(String name)
|
||||
@@ -80,6 +77,18 @@ public class RecipeBookExtensionTest
|
||||
return new ResourceLocation(MOD_ID, name);
|
||||
}
|
||||
|
||||
private static <T extends Recipe<?>> RegistryObject<RecipeType<T>> registerRecipeType(String name) {
|
||||
String id = getId(name).toString();
|
||||
return RECIPE_TYPE.register(name, () -> new RecipeType<>()
|
||||
{
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class ClientHandler
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.debug.recipe.recipebook;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.recipebook.ServerPlaceRecipe;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
@@ -59,7 +58,7 @@ public class RecipeBookTestMenu extends RecipeBookMenu<RecipeBookTestContainer>
|
||||
{
|
||||
this.checkTakeAchievements(stack);
|
||||
Container craftingContainer = RecipeBookTestMenu.this.container;
|
||||
NonNullList<ItemStack> remainders = player.level.getRecipeManager().getRemainingItemsFor(RecipeBookTestRecipe.TYPE.get(), RecipeBookTestMenu.this.container, player.level);
|
||||
NonNullList<ItemStack> remainders = player.level.getRecipeManager().getRemainingItemsFor(RecipeBookExtensionTest.RECIPE_BOOK_TEST_RECIPE_TYPE.get(), RecipeBookTestMenu.this.container, player.level);
|
||||
for (int i = 0; i < remainders.size(); ++i)
|
||||
{
|
||||
ItemStack toRemove = craftingContainer.getItem(i);
|
||||
@@ -163,7 +162,7 @@ public class RecipeBookTestMenu extends RecipeBookMenu<RecipeBookTestContainer>
|
||||
if (container == this.container)
|
||||
{
|
||||
Optional<RecipeBookTestRecipe> recipe = level.getRecipeManager()
|
||||
.getRecipeFor(RecipeBookTestRecipe.TYPE.get(), this.container, level);
|
||||
.getRecipeFor(RecipeBookExtensionTest.RECIPE_BOOK_TEST_RECIPE_TYPE.get(), this.container, level);
|
||||
if (recipe.isEmpty())
|
||||
this.resultContainer.setItem(0, ItemStack.EMPTY);
|
||||
else if (player instanceof ServerPlayer sp && this.resultContainer.setRecipeUsed(level, sp, recipe.get())) {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package net.minecraftforge.debug.recipe.recipebook;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.serialization.Codec;
|
||||
@@ -14,7 +13,6 @@ import com.mojang.serialization.Dynamic;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
@@ -33,9 +31,6 @@ import java.util.stream.Stream;
|
||||
|
||||
public class RecipeBookTestRecipe implements Recipe<RecipeBookExtensionTest.RecipeBookTestContainer>
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final Supplier<RecipeType<RecipeBookTestRecipe>> TYPE = Suppliers.memoize(() -> (RecipeType<RecipeBookTestRecipe>) Registry.RECIPE_TYPE.get(RecipeBookExtensionTest.getId("test_recipe")));
|
||||
|
||||
public final ResourceLocation id;
|
||||
public final Ingredients ingredients;
|
||||
private final int width;
|
||||
@@ -132,7 +127,7 @@ public class RecipeBookTestRecipe implements Recipe<RecipeBookExtensionTest.Reci
|
||||
@Override
|
||||
public RecipeType<?> getType()
|
||||
{
|
||||
return TYPE.get();
|
||||
return RecipeBookExtensionTest.RECIPE_BOOK_TEST_RECIPE_TYPE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-4
@@ -11,11 +11,9 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraftforge.debug.recipe.recipebook.RecipeBookTestRecipe.Ingredients;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RecipeBookTestRecipeSerializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<RecipeBookTestRecipe>
|
||||
public class RecipeBookTestRecipeSerializer implements RecipeSerializer<RecipeBookTestRecipe>
|
||||
{
|
||||
@Override
|
||||
public RecipeBookTestRecipe fromJson(ResourceLocation id, JsonObject json)
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.world;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.BiomeLoadingEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@Mod(BiomeLoadingEventTest.MODID)
|
||||
public class BiomeLoadingEventTest {
|
||||
static final String MODID = "biome_loading_event_test";
|
||||
private static final Logger LOGGER = LogManager.getLogger(MODID);
|
||||
private static final boolean ENABLED = false;
|
||||
public BiomeLoadingEventTest(){
|
||||
if(ENABLED) {
|
||||
MinecraftForge.EVENT_BUS.addListener(this::onBiomeLoading);
|
||||
}
|
||||
}
|
||||
public void onBiomeLoading(BiomeLoadingEvent event){
|
||||
ResourceLocation biome = event.getName();
|
||||
LOGGER.info("Biome loaded: {}", biome);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.world;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.worldgen.features.NetherFeatures;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.BiomeFilter;
|
||||
import net.minecraft.world.level.levelgen.placement.CountOnEveryLayerPlacement;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.common.world.ModifiableBiomeInfo.BiomeInfo.Builder;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
/**
|
||||
* <p>This tests the following features and requirements of biome modifier jsons::</p>
|
||||
* <ul>
|
||||
* <li>A biome modifier json is created via datagen.</li>
|
||||
* <li>The biome modifier modifies all four modifiable fields in biomes, to ensure patches and coremods apply correctly (generation, spawns, climate, and client effects).</li>
|
||||
* <li>The biome modifier uses a biome tag to determine which biomes to modify.</li>
|
||||
* <li>The biome modifier adds json feature to modified biomes, to ensure json features are usable in biome modifiers.</li>
|
||||
* </ul>
|
||||
* <p>If the biome modifier is applied correctly, then badlands biomes should generate large basalt columns,
|
||||
* spawn magma cubes, have red-colored water, and be snowy.</p>
|
||||
*/
|
||||
@Mod(BiomeModifierTest.MODID)
|
||||
public class BiomeModifierTest
|
||||
{
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final String MODID = "biome_modifiers_test";
|
||||
public static final boolean ENABLED = true;
|
||||
public static final String BASALT_PILLARS = "large_basalt_columns";
|
||||
public static final ResourceLocation BASALT_PILLARS_RL = new ResourceLocation(MODID, BASALT_PILLARS);
|
||||
public static final String TEST = "test";
|
||||
public static final ResourceLocation ADD_FEATURES_TO_BIOMES_RL = new ResourceLocation(MODID, TEST);
|
||||
public static final String MODIFY_BADLANDS = "modify_badlands";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public BiomeModifierTest()
|
||||
{
|
||||
if (!ENABLED)
|
||||
return;
|
||||
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
// Serializer types can be registered via deferred register.
|
||||
final DeferredRegister<Codec<? extends BiomeModifier>> serializers = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MODID);
|
||||
serializers.register(modBus);
|
||||
serializers.register(TEST, TestModifier::makeCodec);
|
||||
|
||||
// Biome modifiers don't need to be registered when defined in json, but they do need to be registered if we are to datagenerate the jsons.
|
||||
// We'll also datagenerate a placedfeature json (using our own placedfeature avoids feature cycle problems when we add it to biomes).
|
||||
final DeferredRegister<PlacedFeature> placedFeatures = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, MODID);
|
||||
placedFeatures.register(modBus);
|
||||
placedFeatures.register(BASALT_PILLARS,
|
||||
() -> new PlacedFeature((Holder<ConfiguredFeature<?,?>>) (Holder<? extends ConfiguredFeature<?,?>>)NetherFeatures.LARGE_BASALT_COLUMNS,
|
||||
List.of(CountOnEveryLayerPlacement.of(1), BiomeFilter.biome())));
|
||||
|
||||
modBus.addListener(this::onGatherData);
|
||||
}
|
||||
|
||||
private void onGatherData(GatherDataEvent event)
|
||||
{
|
||||
// Example of how to datagen datapack registry objects.
|
||||
// Datapack registry objects referred to by other datapack registry objects must be registered first.
|
||||
DataGenerator generator = event.getGenerator();
|
||||
final Path outputFolder = generator.getOutputFolder();
|
||||
final RegistryOps<JsonElement> ops = RegistryOps.create(JsonOps.INSTANCE, RegistryAccess.BUILTIN.get());
|
||||
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
final String directory = PackType.SERVER_DATA.getDirectory();
|
||||
Registry<PlacedFeature> placedFeatures = ops.registry(Registry.PLACED_FEATURE_REGISTRY).get();
|
||||
|
||||
// prepare to datagenerate our placed feature
|
||||
final String featurePathString = String.join("/", directory, MODID, Registry.PLACED_FEATURE_REGISTRY.location().getPath(), BASALT_PILLARS + ".json");
|
||||
final Path featurePath = outputFolder.resolve(featurePathString);
|
||||
final PlacedFeature feature = placedFeatures.get(BASALT_PILLARS_RL);
|
||||
|
||||
// prepare to datagenerate our biome modifier
|
||||
final ResourceLocation biomeModifiersRegistryID = ForgeRegistries.Keys.BIOME_MODIFIERS.location();
|
||||
final String biomeModifierPathString = String.join("/", directory, MODID, biomeModifiersRegistryID.getNamespace(), biomeModifiersRegistryID.getPath(), MODIFY_BADLANDS + ".json");
|
||||
final Path biomeModifierPath = outputFolder.resolve(biomeModifierPathString);
|
||||
final BiomeModifier biomeModifier = new TestModifier(
|
||||
new HolderSet.Named<>(ops.registry(Registry.BIOME_REGISTRY).get(), BiomeTags.IS_BADLANDS),
|
||||
Decoration.TOP_LAYER_MODIFICATION,
|
||||
HolderSet.direct(placedFeatures.getOrCreateHolderOrThrow(ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, BASALT_PILLARS_RL))),
|
||||
new SpawnerData(EntityType.MAGMA_CUBE, 100, 1, 4),
|
||||
Precipitation.SNOW,
|
||||
0xFF0000
|
||||
);
|
||||
|
||||
generator.addProvider(event.includeServer(), new DataProvider()
|
||||
{
|
||||
@Override
|
||||
public void run(final CachedOutput cache) throws IOException
|
||||
{
|
||||
PlacedFeature.DIRECT_CODEC.encodeStart(ops, feature)
|
||||
.resultOrPartial(msg -> LOGGER.error("Failed to encode {}: {}", featurePathString, msg)) // Log error on encode failure.
|
||||
.ifPresent(json -> // Output to file on encode success.
|
||||
{
|
||||
try
|
||||
{
|
||||
DataProvider.saveStable(cache, json, featurePath);
|
||||
}
|
||||
catch (IOException e) // The throws can't deal with this exception, because we're inside the ifPresent.
|
||||
{
|
||||
LOGGER.error("Failed to save " + featurePathString, e);
|
||||
}
|
||||
});
|
||||
|
||||
BiomeModifier.DIRECT_CODEC.encodeStart(ops, biomeModifier)
|
||||
.resultOrPartial(msg -> LOGGER.error("Failed to encode {}: {}", biomeModifierPathString, msg)) // Log error on encode failure.
|
||||
.ifPresent(json -> // Output to file on encode success.
|
||||
{
|
||||
try
|
||||
{
|
||||
DataProvider.saveStable(cache, json, biomeModifierPath);
|
||||
}
|
||||
catch (IOException e) // The throws can't deal with this exception, because we're inside the ifPresent.
|
||||
{
|
||||
LOGGER.error("Failed to save " + biomeModifierPathString, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return MODID + " data provider";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public record TestModifier(HolderSet<Biome> biomes, Decoration generationStage, HolderSet<PlacedFeature> features, SpawnerData spawn, Precipitation precipitation, int waterColor)
|
||||
implements BiomeModifier
|
||||
{
|
||||
private static final RegistryObject<Codec<? extends BiomeModifier>> SERIALIZER = RegistryObject.create(ADD_FEATURES_TO_BIOMES_RL, ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MODID);
|
||||
|
||||
@Override
|
||||
public void modify(Holder<Biome> biome, Phase phase, Builder builder)
|
||||
{
|
||||
if (phase == Phase.ADD && this.biomes.contains(biome))
|
||||
{
|
||||
BiomeGenerationSettingsBuilder generation = builder.getGenerationSettings();
|
||||
this.features.forEach(holder -> generation.addFeature(this.generationStage, holder));
|
||||
builder.getMobSpawnSettings().addSpawn(this.spawn.type.getCategory(), this.spawn);
|
||||
}
|
||||
else if (phase == Phase.MODIFY && this.biomes.contains(biome))
|
||||
{
|
||||
builder.getClimateSettings().setPrecipitation(this.precipitation);
|
||||
builder.getEffects().waterColor(this.waterColor);
|
||||
if (this.precipitation == Precipitation.SNOW)
|
||||
builder.getClimateSettings().setTemperature(0F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec<? extends BiomeModifier> codec()
|
||||
{
|
||||
return SERIALIZER.get();
|
||||
}
|
||||
|
||||
private static Codec<TestModifier> makeCodec()
|
||||
{
|
||||
return RecordCodecBuilder.create(builder -> builder.group(
|
||||
Biome.LIST_CODEC.fieldOf("biomes").forGetter(TestModifier::biomes),
|
||||
Codec.STRING.comapFlatMap(TestModifier::generationStageFromString, Decoration::toString).fieldOf("generation_stage").forGetter(TestModifier::generationStage),
|
||||
PlacedFeature.LIST_CODEC.fieldOf("features").forGetter(TestModifier::features),
|
||||
SpawnerData.CODEC.fieldOf("spawn").forGetter(TestModifier::spawn),
|
||||
Precipitation.CODEC.fieldOf("precipitation").forGetter(TestModifier::precipitation),
|
||||
Codec.INT.fieldOf("water_color").forGetter(TestModifier::waterColor)
|
||||
).apply(builder, TestModifier::new));
|
||||
}
|
||||
|
||||
private static DataResult<Decoration> generationStageFromString(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return DataResult.success(Decoration.valueOf(name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return DataResult.error("Not a decoration stage: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,8 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mod(ChunkWatchEventTest.MODID)
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.sun.jna.Structure;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
|
||||
|
||||
@@ -8,68 +8,64 @@ package net.minecraftforge.debug.world;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.ForgeWorldPresetScreens;
|
||||
import net.minecraftforge.common.world.ForgeWorldPreset;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
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;
|
||||
|
||||
@Mod("forge_world_type_test")
|
||||
public class ForgeWorldTypeTest
|
||||
{
|
||||
@ObjectHolder("forge_world_type_test:test_world_type")
|
||||
public static ForgeWorldPreset testWorldType;
|
||||
|
||||
public ForgeWorldTypeTest()
|
||||
{
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(ForgeWorldPreset.class, this::registerWorldTypes);
|
||||
}
|
||||
|
||||
private void registerWorldTypes(RegistryEvent.Register<ForgeWorldPreset> event)
|
||||
{
|
||||
event.getRegistry().registerAll(
|
||||
new ForgeWorldPreset(WorldGenSettings::makeDefaultOverworld).setRegistryName("test_world_type")
|
||||
);
|
||||
event.getRegistry().registerAll(
|
||||
new ForgeWorldPreset(this::createChunkGenerator).setRegistryName("test_world_type2")
|
||||
);
|
||||
}
|
||||
|
||||
private ChunkGenerator createChunkGenerator(RegistryAccess registry, long seed, String settings)
|
||||
{
|
||||
return WorldGenSettings.makeDefaultOverworld(registry, seed);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid="forge_world_type_test", value=Dist.CLIENT, bus=Bus.MOD)
|
||||
public static class ForgeWorldTypeTestClientModEvents
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerWorldTypeScreenFactories(FMLClientSetupEvent event)
|
||||
{
|
||||
ForgeWorldPresetScreens.registerPresetEditor(testWorldType, (returnTo, dimensionGeneratorSettings) -> new Screen(testWorldType.getDisplayName())
|
||||
{
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
addRenderableWidget(new Button(0, 0, 120, 20, new TextComponent("close"), btn -> {
|
||||
Minecraft.getInstance().setScreen(returnTo);
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// TODO-PATCHING: find what changed to world loading to see what gets passed to ForgeWorldPreset -sci
|
||||
// @ObjectHolder(registryName = "forge:world_types", value = "forge_world_type_test:test_world_type")
|
||||
// public static ForgeWorldPreset testWorldType;
|
||||
//
|
||||
// public ForgeWorldTypeTest()
|
||||
// {
|
||||
// FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerWorldTypes);
|
||||
// }
|
||||
//
|
||||
// private void registerWorldTypes(RegisterEvent event)
|
||||
// {
|
||||
// event.register(ForgeRegistries.Keys.WORLD_TYPES, helper ->
|
||||
// {
|
||||
// helper.register("test_world_type", new ForgeWorldPreset(WorldGenSettings::makeDefaultOverworld));
|
||||
// helper.register("test_world_type2", new ForgeWorldPreset(this::createChunkGenerator));
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private ChunkGenerator createChunkGenerator(RegistryAccess registry, long seed, String settings)
|
||||
// {
|
||||
// return WorldGenSettings.makeDefaultOverworld(registry, seed);
|
||||
// }
|
||||
//
|
||||
// @Mod.EventBusSubscriber(modid="forge_world_type_test", value=Dist.CLIENT, bus=Bus.MOD)
|
||||
// public static class ForgeWorldTypeTestClientModEvents
|
||||
// {
|
||||
// @SubscribeEvent
|
||||
// public static void registerWorldTypeScreenFactories(FMLClientSetupEvent event)
|
||||
// {
|
||||
// // ForgeWorldPresetScreens.registerPresetEditor(testWorldType, (returnTo, dimensionGeneratorSettings) -> new Screen(testWorldType.getDisplayName())
|
||||
// // {
|
||||
// // @Override
|
||||
// // protected void init()
|
||||
// // {
|
||||
// // super.init();
|
||||
// //
|
||||
// // addRenderableWidget(new Button(0, 0, 120, 20, Component.literal("close"), btn -> {
|
||||
// // Minecraft.getInstance().setScreen(returnTo);
|
||||
// // }));
|
||||
// // }
|
||||
// // });
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -5,10 +5,11 @@
|
||||
|
||||
package net.minecraftforge.debug.world;
|
||||
|
||||
import net.minecraft.data.worldgen.Structures;
|
||||
import net.minecraft.tags.StructureTags;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.StructureSpawnListGatherEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
@@ -30,12 +31,13 @@ public class StructureSpawnListGatherEventTest
|
||||
|
||||
private void onStructureSpawnListGather(StructureSpawnListGatherEvent event)
|
||||
{
|
||||
if (event.getStructure() == StructureFeature.STRONGHOLD)
|
||||
// TODO-PATCHING: we likely want to get registry access here, so we can resolve tags instead of hardcoding structure objects
|
||||
if (Structures.STRONGHOLD.get() == event.getStructure())
|
||||
{
|
||||
event.addEntitySpawn(MobCategory.MONSTER, new MobSpawnSettings.SpawnerData(EntityType.WITHER_SKELETON, 100, 5, 15));
|
||||
LOGGER.info("Adding wither skeleton spawns to strong holds");
|
||||
}
|
||||
else if (event.getStructure() == StructureFeature.SHIPWRECK)
|
||||
else if (Structures.SHIPWRECK.get() == event.getStructure())
|
||||
{
|
||||
event.setInsideOnly(false);
|
||||
event.addEntitySpawn(MobCategory.MONSTER, new MobSpawnSettings.SpawnerData(EntityType.GUARDIAN, 100, 5, 15));
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.internal;
|
||||
|
||||
/**
|
||||
* The basis of the Event regression testing framework.
|
||||
* Allows each bootstrap event to be queried in turn to see whether the event passed.
|
||||
* For gameplay events, a callback is set for when the respective event is fired.
|
||||
*
|
||||
* Test cases should be in a subclass of this, annotated with TestHolder.
|
||||
* If the test is for an event that fires in Bootstrap, set the field in constructor.
|
||||
* Register the event handler in the registerEvents method, which will be fired automatically.
|
||||
*
|
||||
* Use the pass / fail / error methods in this class to tell the Framework what the result of the test is.
|
||||
*
|
||||
* @author Curle
|
||||
*/
|
||||
public abstract class EventTest {
|
||||
protected Result testResult = Result.NOT_PROCESSED;
|
||||
protected String errorDetail = "Event not processed";
|
||||
protected boolean bootstrap; // true for events that fire when the game is loading to the main menu. false for events that fire after the game has loaded.
|
||||
|
||||
/**
|
||||
* A summarised view of the test result.
|
||||
* For passes: "PASS"
|
||||
* For failures: "FAIL - ($errorDetail)"
|
||||
* @return test result
|
||||
*/
|
||||
public String getTestResult() {
|
||||
return (testResult.passed() ? "PASS" : "FAIL; ") + (testResult.failed() ? getEnhancedDetail() : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide extra detail about the error.
|
||||
* Pass-through of errorDetail is default, but some events require something more robust.
|
||||
* @return information to be shown in case of a test failure
|
||||
*/
|
||||
protected String getEnhancedDetail() { return errorDetail; }
|
||||
|
||||
/**
|
||||
* @return whether or not this event should be monitored while the game is loading to the main menu.
|
||||
*/
|
||||
public boolean isBootstrap() { return bootstrap; }
|
||||
|
||||
/**
|
||||
* Register event handlers for this event.
|
||||
* Trade-off between "magic annotations" and verbosity should be evaluated.
|
||||
*/
|
||||
public abstract void registerEvents();
|
||||
|
||||
/**
|
||||
* Helper method - combines setting failure state with detail message.
|
||||
* @param reason extra detail about why the failure occurred
|
||||
*/
|
||||
protected void fail(String reason) {
|
||||
testResult = Result.FAIL;
|
||||
errorDetail = reason;
|
||||
|
||||
TestFramework.testChangedState(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method - sets the test pass flag.
|
||||
*/
|
||||
protected void pass() {
|
||||
testResult = Result.PASS;
|
||||
|
||||
TestFramework.testChangedState(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method - combines setting error state with detail message.
|
||||
* @param reason extra detail about why the error occured.
|
||||
*/
|
||||
protected void error(String reason) {
|
||||
testResult = Result.TESTFAIL;
|
||||
errorDetail = reason;
|
||||
|
||||
TestFramework.testChangedState(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes information about how the test progressed.
|
||||
*/
|
||||
public enum Result {
|
||||
PASS, // The test passed with no errors
|
||||
FAIL, // The code being tested failed to meet the requirements
|
||||
TESTFAIL, // The test threw an error when trying to evaluate the requirements
|
||||
NOT_PROCESSED; // The test was not fired, or did not return a result.
|
||||
|
||||
/**
|
||||
* @return whether the test passed.
|
||||
*/
|
||||
public boolean passed() {
|
||||
return this == PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the test or the code being tested failed.
|
||||
*/
|
||||
public boolean failed() {
|
||||
return this != PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the test encountered an error
|
||||
*/
|
||||
public boolean errored() {
|
||||
return this == TESTFAIL;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.internal;
|
||||
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraftforge.client.event.ScreenOpenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.GameShuttingDownEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.loading.LoadingModList;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender;
|
||||
import org.apache.logging.log4j.core.appender.rolling.OnStartupTriggeringPolicy;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
import org.apache.logging.log4j.core.config.LoggerConfig;
|
||||
import org.apache.logging.log4j.core.layout.PatternLayout;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The backend of the "curletest" event testing framework.
|
||||
* All tests are registered to this class, and are set up according to the needs they declare.
|
||||
*
|
||||
* All bootstrap tests will be summed up into a log file when the main menu loads.
|
||||
* All gameplay events will be printed to the console when they fire, and written to the above log.
|
||||
*
|
||||
* To register a new event test, simply create the class in the events package and add it to the list here.
|
||||
*/
|
||||
@Mod(TestFramework.MODID)
|
||||
public class TestFramework {
|
||||
public static final String MODID = "eventtests";
|
||||
|
||||
final List<EventTest> tests;
|
||||
final static Map<EventTest, String> testNames = new HashMap<>();
|
||||
final static Logger LOGGER = LogManager.getLogger();
|
||||
final static Type CURLETEST_ANNOTATION = Type.getType(TestHolder.class);
|
||||
|
||||
boolean bootstrapHandled = false;
|
||||
|
||||
/**
|
||||
* Pre-initialize the framework and all events.
|
||||
*/
|
||||
public TestFramework() {
|
||||
prepareLogger();
|
||||
|
||||
LOGGER.info("Preparing all event tests.");
|
||||
|
||||
tests = gatherEvents();
|
||||
// Let each event set up
|
||||
tests.forEach(EventTest::registerEvents);
|
||||
|
||||
// Register the screen opened listener.
|
||||
// The main menu signals the end of the bootstrap tests.
|
||||
MinecraftForge.EVENT_BUS.addListener(this::collectBootstrapTests);
|
||||
|
||||
// Register the game shutting down listener.
|
||||
// If there are any unhandled tests after shutdown, notify of an event not fired.
|
||||
MinecraftForge.EVENT_BUS.addListener(this::collectMissedTests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gameplay events require to be able to notify the framework when their task is completed.
|
||||
* Bootstrap events are ignored when updates occur.
|
||||
*/
|
||||
public static void testChangedState(EventTest test) {
|
||||
if(test.isBootstrap()) return;
|
||||
|
||||
LOGGER.info("Test " + testNames.get(test) + ": " + test.getTestResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumerate all tests that should be ran with the framework.
|
||||
* All classes with the @TestHolder annotation are resolved and instantiated as tests.
|
||||
*
|
||||
* @return all tests to run
|
||||
*/
|
||||
private List<EventTest> gatherEvents() {
|
||||
var tests = new ArrayList<EventTest>();
|
||||
|
||||
// Search all annotations in the current mod, filter for @CurleTest, and condense to a list.
|
||||
var anns = LoadingModList.get().getModFileById(MODID).getFile().getScanResult().getAnnotations()
|
||||
.stream()
|
||||
.filter(ann -> CURLETEST_ANNOTATION.equals(ann.annotationType()))
|
||||
.toList();
|
||||
|
||||
// For each instance of the annotation, resolve the class it's attached to, create a new instance, and add it to the list.
|
||||
anns.forEach(annotationData -> {
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(annotationData.clazz().getClassName());
|
||||
EventTest instance = (EventTest) clazz.getDeclaredConstructor().newInstance();
|
||||
tests.add(instance);
|
||||
testNames.put(instance, (String) annotationData.annotationData().get("value"));
|
||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* At the mark of the end of the bootstrap period, collect and log all test results.
|
||||
* the ScreenOpenEvent fired by TitleScreen is the last event fired without user interaction, so it is the
|
||||
* end of the "automatic" bootstrap time.
|
||||
*/
|
||||
private void collectBootstrapTests(ScreenOpenEvent event) {
|
||||
if(!(event.getScreen() instanceof TitleScreen) || bootstrapHandled)
|
||||
return;
|
||||
|
||||
LOGGER.info("Preparing to run bootstrap tests:");
|
||||
tests.forEach(test -> {
|
||||
if(test.isBootstrap()) {
|
||||
LOGGER.info(" - " + testNames.get(test) + ": " + test.getTestResult());
|
||||
}
|
||||
});
|
||||
LOGGER.info("All bootstrap tests evaluated.");
|
||||
|
||||
bootstrapHandled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for unfired events when the game is shutting down.
|
||||
* Summarise all test results.
|
||||
*/
|
||||
private void collectMissedTests(GameShuttingDownEvent event) {
|
||||
LOGGER.info("Test summary processing..");
|
||||
tests.forEach(test -> {
|
||||
LOGGER.info("\tTest " + testNames.get(test) + ": ");
|
||||
LOGGER.info(test.testResult == EventTest.Result.NOT_PROCESSED ?
|
||||
"\t\tMISSED - Not fired." :
|
||||
"\t\t" + test.getTestResult()
|
||||
);
|
||||
});
|
||||
LOGGER.info("Event Test Framework finished.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the LOGGER instance in this class to only write to logs/curletest.log.
|
||||
* Log4J is annoying and requires manual initialization and preparation.
|
||||
*/
|
||||
private void prepareLogger() {
|
||||
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
final Configuration config = ctx.getConfiguration();
|
||||
final LoggerConfig loggerConfig = getLoggerConfiguration(config, LOGGER.getName());
|
||||
|
||||
final RollingRandomAccessFileAppender appender = RollingRandomAccessFileAppender.newBuilder()
|
||||
.setName("EventTestLog")
|
||||
.withFileName("logs/curletest.log")
|
||||
.withFilePattern("logs/%d{yyyy-MM-dd}-%i.log.gz")
|
||||
.setLayout(PatternLayout.newBuilder()
|
||||
.withPattern("[%d{ddMMMyyyy HH:mm:ss}] [%logger]: %minecraftFormatting{%msg}{strip}%n%xEx")
|
||||
.build()
|
||||
)
|
||||
.withPolicy(
|
||||
OnStartupTriggeringPolicy.createPolicy(1)
|
||||
)
|
||||
.build();
|
||||
|
||||
appender.start();
|
||||
|
||||
loggerConfig.setParent(null);
|
||||
loggerConfig.getAppenders().keySet().forEach(loggerConfig::removeAppender);
|
||||
loggerConfig.addAppender(
|
||||
appender,
|
||||
Level.INFO,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private static LoggerConfig getLoggerConfiguration(@NotNull final Configuration configuration, @NotNull final String loggerName)
|
||||
{
|
||||
final LoggerConfig lc = configuration.getLoggerConfig(loggerName);
|
||||
if (lc.getName().equals(loggerName))
|
||||
{
|
||||
return lc;
|
||||
}
|
||||
else
|
||||
{
|
||||
final LoggerConfig nlc = new LoggerConfig(loggerName, lc.getLevel(), lc.isAdditive());
|
||||
nlc.setParent(lc);
|
||||
configuration.addLogger(loggerName, nlc);
|
||||
configuration.getLoggerContext().updateLoggers();
|
||||
|
||||
return nlc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.internal;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* A marker annotation used with the Event Testing Framework.
|
||||
* Can only be placed on a class, enum or record.
|
||||
*
|
||||
* This annotation is used with FML Scan Data to construct and register the test automatically.
|
||||
* The testName field is used in the output of the test.
|
||||
*
|
||||
* @author Curle
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface TestHolder {
|
||||
String value();
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.eventtest.tests.forge.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.eventtest.internal.EventTest;
|
||||
import net.minecraftforge.eventtest.internal.TestHolder;
|
||||
|
||||
/**
|
||||
* Test case for the EntityJoinWorldEvent.
|
||||
*
|
||||
* Event fires during gameplay.
|
||||
* Success condition:
|
||||
* EntityJoinWorldEvent fired for Minecraft.getInstance().player
|
||||
* Failure info:
|
||||
* "EntityJoinWorldEvent was not fired"
|
||||
*
|
||||
*/
|
||||
|
||||
@TestHolder("EntityJoinWorld")
|
||||
public class EntityJoinedWorldTest extends EventTest {
|
||||
|
||||
@Override
|
||||
public void registerEvents() {
|
||||
MinecraftForge.EVENT_BUS.addListener(this::eventListener);
|
||||
}
|
||||
|
||||
private void eventListener(EntityJoinWorldEvent event) {
|
||||
final Entity eventEntity = event.getEntity();
|
||||
final Player gamePlayer = Minecraft.getInstance().player;
|
||||
|
||||
final boolean eventFiredForPlayer = eventEntity == gamePlayer;
|
||||
|
||||
if(eventFiredForPlayer)
|
||||
pass();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user