Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/1.20.x' into 1.20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD committed Jan 24, 2024
2 parents 55ea652 + dc41867 commit 57071b1
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 49 deletions.
12 changes: 4 additions & 8 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Contributing to Forge
Contributing to NeoForge
=====================

1) Keep patches to Minecraft classes together. If you need a lot of things done, you may either add to relevant forge classes or make a new class. Try not to spread out your patches across multiple disjoint lines, as this makes maintenance of your patches difficult.
Expand All @@ -7,14 +7,10 @@ Contributing to Forge

3) Follow the code style of the class you're working in (braces on newlines & spaces instead of tabs in Forge classes, inline brackets in patches, etc).

For more information, refer to [the wiki][Wiki].


Contributor License Agreement
=============================
- You grant Forge a license to use your code contributed to the primary codebase (everything **not** under patches) in Forge, under the LGPLv2.1 license.
- You assign copyright ownership of your contributions to the patches codebase (everything under patches) to Forge, where it will be licensed under the LGPLv2.1 license.

"Forge" is Forge Development LLC, a legally incorporated entity in Oregon, USA.
- You grant NeoForged a license to use your code contributed to the primary codebase (everything **not** under patches) in NeoForge, under the LGPLv2.1 license.
- You assign copyright ownership of your contributions to the patches codebase (everything under patches) to NeoForged, where it will be licensed under the LGPLv2.1 license.

[Wiki]: https://github.com/MinecraftForge/MinecraftForge/wiki/If-you-want-to-contribute-to-Forge
This is intended as a **legally binding copyright assignment** to the NeoForged project for contributions under the patches codebase. However you retain your copyright for all other contributions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Please ensure you have a valid email address associated with your GitHub account

[CLA]: https://cla-assistant.io/neoforged/NeoForge
[Crowdin]: https://crowdin.neoforged.net/neoforge
[Contributing]: ../../NeoForge/docs/CONTRIBUTING.md
[Contributing]: ../docs/CONTRIBUTING.md
[Discord]: https://discord.neoforged.net/
[Documentation]: https://docs.neoforged.net/
[Download]: https://neoforged.net/
Expand Down
15 changes: 1 addition & 14 deletions patches/net/minecraft/core/MappedRegistry.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
final ResourceKey<? extends Registry<T>> key;
private final ObjectList<Holder.Reference<T>> byId = new ObjectArrayList<>(256);
@@ -123,10 +_,22 @@
}
}

+ private static final Set<ResourceLocation> KNOWN = new java.util.LinkedHashSet<>();
+ public static Set<ResourceLocation> getKnownRegistries() {
+ return java.util.Collections.unmodifiableSet(KNOWN);
+ }
+ protected final void markKnown() {
+ KNOWN.add(key().location());
+ }
+
public Holder.Reference<T> registerMapping(int p_256563_, ResourceKey<T> p_256594_, T p_256374_, Lifecycle p_256469_) {
+ markKnown();
@@ -127,6 +_,9 @@
this.validateWrite(p_256594_);
Validate.notNull(p_256594_);
Validate.notNull(p_256374_);
Expand Down
13 changes: 13 additions & 0 deletions patches/net/minecraft/core/registries/BuiltInRegistries.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/net/minecraft/core/registries/BuiltInRegistries.java
+++ b/net/minecraft/core/registries/BuiltInRegistries.java
@@ -346,6 +_,10 @@
});
}

+ public static java.util.Set<ResourceLocation> getVanillaRegistrationOrder() {
+ return java.util.Collections.unmodifiableSet(LOADERS.keySet());
+ }
+
@FunctionalInterface
interface RegistryBootstrap<T> {
T run(Registry<T> p_260128_);
2 changes: 1 addition & 1 deletion patches/net/minecraft/world/entity/LivingEntity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@
ItemStack itemstack = this.getItemInHand(p_21159_);
if (!itemstack.isEmpty() && !this.isUsingItem()) {
+ int duration = net.neoforged.neoforge.event.EventHooks.onItemUseStart(this, itemstack, itemstack.getUseDuration());
+ if (duration <= 0) return;
+ if (duration < 0) return; // Neo: Early return for negative values, as that indicates event cancellation.
this.useItem = itemstack;
- this.useItemRemaining = itemstack.getUseDuration();
+ this.useItemRemaining = duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
}

if (this.isVehicle() && this.canGallop) {
@@ -669,6 +_,12 @@
this.mouthAnim = 0.0F;
}
}
+
+ // Neo: Horse armor tick patch
+ if (this.canWearArmor()) {
+ ItemStack stack = this.inventory.getItem(1);
+ if (isArmor(stack)) stack.onHorseArmorTick(level(), this);
+ }
}

@Override
@@ -802,6 +_,7 @@
this.setDeltaMovement(vec3.x, d1, vec3.z);
this.setIsJumping(true);
Expand Down
11 changes: 0 additions & 11 deletions patches/net/minecraft/world/entity/animal/horse/Horse.java.patch

This file was deleted.

74 changes: 74 additions & 0 deletions src/generated/resources/reports/registry_order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"order": [
"minecraft:game_event",
"minecraft:sound_event",
"minecraft:fluid",
"minecraft:mob_effect",
"minecraft:block",
"minecraft:enchantment",
"minecraft:entity_type",
"minecraft:item",
"minecraft:potion",
"minecraft:particle_type",
"minecraft:block_entity_type",
"minecraft:painting_variant",
"minecraft:custom_stat",
"minecraft:chunk_status",
"minecraft:rule_test",
"minecraft:rule_block_entity_modifier",
"minecraft:pos_rule_test",
"minecraft:menu",
"minecraft:recipe_type",
"minecraft:recipe_serializer",
"minecraft:attribute",
"minecraft:position_source_type",
"minecraft:command_argument_type",
"minecraft:stat_type",
"minecraft:villager_type",
"minecraft:villager_profession",
"minecraft:point_of_interest_type",
"minecraft:memory_module_type",
"minecraft:sensor_type",
"minecraft:schedule",
"minecraft:activity",
"minecraft:loot_pool_entry_type",
"minecraft:loot_function_type",
"minecraft:loot_condition_type",
"minecraft:loot_number_provider_type",
"minecraft:loot_nbt_provider_type",
"minecraft:loot_score_provider_type",
"minecraft:float_provider_type",
"minecraft:int_provider_type",
"minecraft:height_provider_type",
"minecraft:block_predicate_type",
"minecraft:worldgen/carver",
"minecraft:worldgen/feature",
"minecraft:worldgen/structure_placement",
"minecraft:worldgen/structure_piece",
"minecraft:worldgen/structure_type",
"minecraft:worldgen/placement_modifier_type",
"minecraft:worldgen/block_state_provider_type",
"minecraft:worldgen/foliage_placer_type",
"minecraft:worldgen/trunk_placer_type",
"minecraft:worldgen/root_placer_type",
"minecraft:worldgen/tree_decorator_type",
"minecraft:worldgen/feature_size_type",
"minecraft:worldgen/biome_source",
"minecraft:worldgen/chunk_generator",
"minecraft:worldgen/material_condition",
"minecraft:worldgen/material_rule",
"minecraft:worldgen/density_function_type",
"minecraft:block_type",
"minecraft:worldgen/structure_processor",
"minecraft:worldgen/structure_pool_element",
"minecraft:worldgen/pool_alias_binding",
"minecraft:cat_variant",
"minecraft:frog_variant",
"minecraft:banner_pattern",
"minecraft:instrument",
"minecraft:decorated_pot_patterns",
"minecraft:creative_mode_tab",
"minecraft:trigger_type",
"minecraft:number_format_type"
]
}
2 changes: 2 additions & 0 deletions src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
import net.neoforged.neoforge.common.data.internal.NeoForgeItemTagsProvider;
import net.neoforged.neoforge.common.data.internal.NeoForgeLootTableProvider;
import net.neoforged.neoforge.common.data.internal.NeoForgeRecipeProvider;
import net.neoforged.neoforge.common.data.internal.NeoForgeRegistryOrderReportProvider;
import net.neoforged.neoforge.common.data.internal.NeoForgeSpriteSourceProvider;
import net.neoforged.neoforge.common.data.internal.VanillaSoundDefinitionsProvider;
import net.neoforged.neoforge.common.extensions.IEntityExtension;
Expand Down Expand Up @@ -642,6 +643,7 @@ public void gatherData(GatherDataEvent event) {
gen.addProvider(event.includeServer(), new NeoForgeLootTableProvider(packOutput));
gen.addProvider(event.includeServer(), new NeoForgeBiomeTagsProvider(packOutput, lookupProvider, existingFileHelper));
gen.addProvider(event.includeServer(), new NeoForgeDamageTypeTagsProvider(packOutput, lookupProvider, existingFileHelper));
gen.addProvider(event.includeServer(), new NeoForgeRegistryOrderReportProvider(packOutput));

gen.addProvider(event.includeClient(), new NeoForgeSpriteSourceProvider(packOutput, lookupProvider, existingFileHelper));
gen.addProvider(event.includeClient(), new VanillaSoundDefinitionsProvider(packOutput, existingFileHelper));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.common.data.internal;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;

public final class NeoForgeRegistryOrderReportProvider implements DataProvider {
private final PackOutput output;

public NeoForgeRegistryOrderReportProvider(PackOutput output) {
this.output = output;
}

@Override
public CompletableFuture<?> run(CachedOutput output) {
JsonObject json = new JsonObject();

JsonArray array = new JsonArray();
BuiltInRegistries.getVanillaRegistrationOrder().forEach(name -> array.add(name.toString()));
json.add("order", array);

Path path = this.output.getOutputFolder(PackOutput.Target.REPORTS).resolve("registry_order.json");
return DataProvider.saveStable(output, json, path);
}

@Override
public String getName() {
return "registry_order_report";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.animal.horse.Horse;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.monster.piglin.PiglinAi;
Expand All @@ -31,6 +33,7 @@
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterials;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.HorseArmorItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -595,13 +598,16 @@ default int getBurnTime(ItemStack itemStack, @Nullable RecipeType<?> recipeType)
}

/**
* Called every tick from {@code Horse#playGallopSound(SoundEvent)} on the item in the
* armor slot.
* Called every tick when this item is equipped {@linkplain AbstractHorse#isArmor(ItemStack) as an armor item} by a horse {@linkplain AbstractHorse#canWearArmor() that can wear armor}.
* <p>
* In vanilla, only {@linkplain Horse horses} can wear armor, and they can only equip items that extend {@link HorseArmorItem}.
*
* @param stack the armor itemstack
* @param level the level the horse is in
* @param horse the horse wearing this armor
* @param stack The armor stack
* @param level The level the horse is in
* @param horse The horse wearing this item
* @apiNote Call from {@link IItemStackExtension#onHorseArmorTick(Level, Mob)}.
*/
@ApiStatus.OverrideOnly
default void onHorseArmorTick(ItemStack stack, Level level, Mob horse) {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.animal.horse.Horse;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.EnderMan;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.HorseArmorItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
Expand Down Expand Up @@ -275,11 +278,12 @@ default void onArmorTick(Level level, Player player) {
}

/**
* Called every tick from {@code Horse#playGallopSound(SoundEvent)} on the item in the
* armor slot.
* Called every tick when this item is equipped {@linkplain AbstractHorse#isArmor(ItemStack) as an armor item} by a horse {@linkplain AbstractHorse#canWearArmor() that can wear armor}.
* <p>
* In vanilla, only {@linkplain Horse horses} can wear armor, and they can only equip items that extend {@link HorseArmorItem}.
*
* @param level the level the horse is in
* @param horse the horse wearing this armor
* @param level The level the horse is in
* @param horse The horse wearing this item
*/
default void onHorseArmorTick(Level level, Mob horse) {
self().getItem().onHorseArmorTick(self(), level, horse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static void freezeData() {
}

public static void postRegisterEvents() {
Set<ResourceLocation> ordered = new LinkedHashSet<>(MappedRegistry.getKnownRegistries());
Set<ResourceLocation> ordered = new LinkedHashSet<>(BuiltInRegistries.getVanillaRegistrationOrder());
ordered.retainAll(RegistryManager.getVanillaRegistryKeys());
ordered.addAll(BuiltInRegistries.REGISTRY.keySet().stream().sorted(ResourceLocation::compareNamespaced).toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.fml.util.ObfuscationReflectionHelper;
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.AddPackFindersEvent;
Expand Down Expand Up @@ -131,9 +130,6 @@ record RegistryData(Registry<BigData> registry) {}

final int size = buf.writerIndex();
LOG.warn("Dummy big registry size: " + size + ", or " + ((double) size / CompressionDecoder.MAXIMUM_UNCOMPRESSED_LENGTH * 100) + "% of the maximum packet size.");

final Set<ResourceLocation> known = ObfuscationReflectionHelper.getPrivateValue(MappedRegistry.class, null, "KNOWN");
known.remove(dummyRegistry.key().location());
}

private String randomString(Random random, int length) {
Expand Down

0 comments on commit 57071b1

Please sign in to comment.