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 Feb 8, 2024
2 parents 1c41643 + 5e1e9fa commit 77190d0
Show file tree
Hide file tree
Showing 376 changed files with 5,537 additions and 1,362 deletions.
20 changes: 4 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,6 @@ spotless {
target rootProject.fileTree("src", {
include "**/*.java"
})

endWithNewline()
indentWithSpaces()
removeUnusedImports()
toggleOffOn()
eclipse().configFile file('codeformat/formatter-config.xml')
importOrder()

// courtesy of diffplug/spotless#240
// https://github.com/diffplug/spotless/issues/240#issuecomment-385206606
custom 'noWildcardImports', { String fileContents ->
if (fileContents.contains('*;\n')) {
throw new GradleException('No wildcard imports are allowed!')
}
}
bumpThisNumberIfACustomStepChanges(1)
}
format 'patches', {
target rootProject.fileTree("patches")
Expand All @@ -106,3 +90,7 @@ spotless {
bumpThisNumberIfACustomStepChanges(2)
}
}

apply from: rootProject.file('buildscript/spotless-rules.gradle')
apply from: rootProject.file('buildscript/generate-package-infos.gradle')
apply from: rootProject.file('buildscript/apply-all-formatting.gradle')
9 changes: 9 additions & 0 deletions buildscript/apply-all-formatting.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tasks.named('licenseFormat').get().mustRunAfter generatePackageInfos
tasks.named('spotlessApply').get().mustRunAfter generatePackageInfos
tasks.named('spotlessApply').get().mustRunAfter tasks.named('licenseFormat').get()

tasks.register('applyAllFormatting', Task) {
dependsOn generatePackageInfos
dependsOn tasks.named('licenseFormat').get()
dependsOn tasks.named('spotlessApply').get()
}
27 changes: 27 additions & 0 deletions buildscript/generate-package-infos.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.regex.Matcher

def generatePackageInfos = tasks.register('generatePackageInfos', Task) {
doLast {
fileTree('src/main/java').each { javaFile ->
def packageInfoFile = new File(javaFile.parent, 'package-info.java')
if (!packageInfoFile.exists()) {
def pkgName = javaFile.toString().replaceAll(Matcher.quoteReplacement(File.separator), '/')
pkgName = pkgName.substring(pkgName.indexOf('net/neoforged/'), pkgName.lastIndexOf('/'))
pkgName = pkgName.replaceAll('/', '.')

def pkgInfoText = """
|@FieldsAreNonnullByDefault
|@MethodsReturnNonnullByDefault
|@ParametersAreNonnullByDefault
|package $pkgName;
|
|import javax.annotation.ParametersAreNonnullByDefault;
|import net.minecraft.FieldsAreNonnullByDefault;
|import net.minecraft.MethodsReturnNonnullByDefault;
""".stripMargin().trim()

packageInfoFile.text = pkgInfoText
}
}
}
}
25 changes: 25 additions & 0 deletions buildscript/spotless-rules.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
spotless {
java {
endWithNewline()
indentWithSpaces()
removeUnusedImports()
toggleOffOn()
eclipse().configFile rootProject.file('codeformat/formatter-config.xml')
importOrder()

// courtesy of diffplug/spotless#240
// https://github.com/diffplug/spotless/issues/240#issuecomment-385206606
custom 'noWildcardImports', { String fileContents ->
if (fileContents.contains('*;\n')) {
throw new GradleException('No wildcard imports are allowed!')
}
}

custom 'noNotNull', { String fileContents ->
if (fileContents.contains('@NotNull') || fileContents.contains('@Nonnull')) {
throw new GradleException('@NotNull and @Nonnull are disallowed.')
}
}
bumpThisNumberIfACustomStepChanges(2)
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.0
fancy_mod_loader_version=2.0.7
fancy_mod_loader_version=2.0.11
mojang_logging_version=1.1.1
log4j_version=2.19.0
guava_version=31.1.2-jre
Expand Down
15 changes: 15 additions & 0 deletions patches/net/minecraft/client/MouseHandler.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
if (this.minecraft.player.isSpectator()) {
if (this.minecraft.gui.getSpectatorGui().isMenuActive()) {
this.minecraft.gui.getSpectatorGui().onMouseScrolled(-k);
@@ -209,9 +_,11 @@
double d3 = (p_91564_ - this.ypos)
* (double)this.minecraft.getWindow().getGuiScaledHeight()
/ (double)this.minecraft.getWindow().getScreenHeight();
- Screen.wrapScreenError(
- () -> screen.mouseDragged(d0, d1, this.activeButton, d2, d3), "mouseDragged event handler", screen.getClass().getCanonicalName()
- );
+ Screen.wrapScreenError(() -> {
+ if (net.neoforged.neoforge.client.ClientHooks.onScreenMouseDragPre(screen, d0, d1, this.activeButton, d2, d3)) return;
+ if (screen.mouseDragged(d0, d1, this.activeButton, d2, d3)) return;
+ net.neoforged.neoforge.client.ClientHooks.onScreenMouseDragPost(screen, d0, d1, this.activeButton, d2, d3);
+ }, "mouseDragged event handler", screen.getClass().getCanonicalName());
}

screen.afterMouseMove();
@@ -235,12 +_,13 @@
double d1 = d0 - this.lastMouseEventTime;
this.lastMouseEventTime = d0;
Expand Down
15 changes: 4 additions & 11 deletions patches/net/minecraft/client/renderer/LevelRenderer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,7 @@
float f = this.level.effects().getCloudHeight();
if (!Float.isNaN(f)) {
RenderSystem.disableCull();
@@ -2072,7 +_,7 @@
boolean flag = false;
if (this.minecraft.options.prioritizeChunkUpdates().get() == PrioritizeChunkUpdates.NEARBY) {
BlockPos blockpos1 = sectionrenderdispatcher$rendersection.getOrigin().offset(8, 8, 8);
- flag = blockpos1.distSqr(blockpos) < 768.0 || sectionrenderdispatcher$rendersection.isDirtyFromPlayer();
+ flag = !net.neoforged.neoforge.common.NeoForgeConfig.CLIENT.alwaysSetupTerrainOffThread.get() && (blockpos1.distSqr(blockpos) < 768.0D || sectionrenderdispatcher$rendersection.isDirtyFromPlayer()); // the target is the else block below, so invert the forge addition to get there early
} else if (this.minecraft.options.prioritizeChunkUpdates().get() == PrioritizeChunkUpdates.PLAYER_AFFECTED) {
flag = sectionrenderdispatcher$rendersection.isDirtyFromPlayer();
}
@@ -2585,7 +_,30 @@
@@ -2585,7 +_,32 @@
this.viewArea.setDirty(p_109502_, p_109503_, p_109504_, p_109505_);
}

Expand All @@ -210,7 +201,9 @@
+ for (var chunkInfo : this.visibleSections) {
+ chunkInfo.getCompiled().getRenderableBlockEntities().forEach(blockEntityConsumer);
+ }
+ this.globalBlockEntities.forEach(blockEntityConsumer);
+ synchronized (this.globalBlockEntities) {
+ this.globalBlockEntities.forEach(blockEntityConsumer);
+ }
+ }
+
+ /**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)
);
+ p_252136_.popPush("forge_modify_baking_result");
+ net.neoforged.neoforge.client.ClientHooks.onModifyBakingResult(p_248945_.getBakedTopLevelModels(), p_248945_);
+ net.neoforged.neoforge.client.ClientHooks.onModifyBakingResult(p_248945_.getBakedTopLevelModels(), p_250646_, p_248945_);
p_252136_.popPush("dispatch");
Map<ResourceLocation, BakedModel> map = p_248945_.getBakedTopLevelModels();
BakedModel bakedmodel = map.get(ModelBakery.MISSING_MODEL_LOCATION);
Expand Down
26 changes: 26 additions & 0 deletions patches/net/minecraft/core/Holder.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/net/minecraft/core/Holder.java
+++ b/net/minecraft/core/Holder.java
@@ -11,7 +_,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;

-public interface Holder<T> {
+public interface Holder<T> extends net.neoforged.neoforge.registries.datamaps.IWithData<T> {
T value();

boolean isBound();
@@ -201,6 +_,14 @@
} else {
this.value = p_249418_;
}
+ }
+
+ @org.jetbrains.annotations.Nullable
+ public <A> A getData(net.neoforged.neoforge.registries.datamaps.DataMapType<T, A> type) {
+ if (owner instanceof HolderLookup.RegistryLookup<T> lookup) {
+ return lookup.getData(type, key());
+ }
+ return null;
}

public void bindTags(Collection<TagKey<T>> p_205770_) {
27 changes: 27 additions & 0 deletions patches/net/minecraft/core/HolderLookup.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--- a/net/minecraft/core/HolderLookup.java
+++ b/net/minecraft/core/HolderLookup.java
@@ -117,6 +_,11 @@
: this);
}

+ @org.jetbrains.annotations.Nullable
+ default <A> A getData(net.neoforged.neoforge.registries.datamaps.DataMapType<T, A> attachment, ResourceKey<T> key) {
+ return null;
+ }
+
public abstract static class Delegate<T> implements HolderLookup.RegistryLookup<T> {
protected abstract HolderLookup.RegistryLookup<T> parent();

@@ -148,6 +_,12 @@
@Override
public Stream<HolderSet.Named<T>> listTags() {
return this.parent().listTags();
+ }
+
+ @Override
+ @org.jetbrains.annotations.Nullable
+ public <A> A getData(net.neoforged.neoforge.registries.datamaps.DataMapType<T, A> attachment, ResourceKey<T> key) {
+ return parent().getData(attachment, key);
}
}
}
13 changes: 13 additions & 0 deletions patches/net/minecraft/core/MappedRegistry.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
private static final Logger LOGGER = LogUtils.getLogger();
final ResourceKey<? extends Registry<T>> key;
private final ObjectList<Holder.Reference<T>> byId = new ObjectArrayList<>(256);
@@ -79,6 +_,12 @@
public Stream<HolderSet.Named<T>> listTags() {
return MappedRegistry.this.getTags().map(Pair::getSecond);
}
+
+ @Override
+ @org.jetbrains.annotations.Nullable
+ public <A> A getData(net.neoforged.neoforge.registries.datamaps.DataMapType<T, A> type, ResourceKey<T> key) {
+ return MappedRegistry.this.getData(type, key);
+ }
};

public MappedRegistry(ResourceKey<? extends Registry<T>> p_249899_, Lifecycle p_252249_) {
@@ -127,6 +_,9 @@
this.validateWrite(p_256594_);
Validate.notNull(p_256594_);
Expand Down
27 changes: 0 additions & 27 deletions patches/net/minecraft/data/Main.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,3 @@
} else {
optionparser.printHelpOn(System.out);
}
@@ -132,7 +_,7 @@
datagenerator$packgenerator2.addProvider(bindRegistries(RegistriesDatapackGenerator::new, completablefuture2));
datagenerator$packgenerator2.addProvider(bindRegistries(VanillaAdvancementProvider::create, completablefuture2));
datagenerator$packgenerator2.addProvider(VanillaLootTableProvider::create);
- datagenerator$packgenerator2.addProvider(VanillaRecipeProvider::new);
+ datagenerator$packgenerator2.addProvider(bindRegistries(VanillaRecipeProvider::new, completablefuture2));
TagsProvider<Block> tagsprovider3 = datagenerator$packgenerator2.addProvider(bindRegistries(VanillaBlockTagsProvider::new, completablefuture2));
TagsProvider<Item> tagsprovider = datagenerator$packgenerator2.addProvider(
p_274753_ -> new VanillaItemTagsProvider(p_274753_, completablefuture2, tagsprovider3.contentsGetter())
@@ -158,7 +_,7 @@
datagenerator$packgenerator2.addProvider(bindRegistries(CommandsReport::new, completablefuture2));
datagenerator$packgenerator2.addProvider(RegistryDumpReport::new);
datagenerator$packgenerator2 = datagenerator.getBuiltinDatapack(p_236683_, "bundle");
- datagenerator$packgenerator2.addProvider(BundleRecipeProvider::new);
+ datagenerator$packgenerator2.addProvider(bindRegistries(BundleRecipeProvider::new, completablefuture2));
datagenerator$packgenerator2.addProvider(
p_253392_ -> PackMetadataGenerator.forFeaturePack(
p_253392_, Component.translatable("dataPack.bundle.description"), FeatureFlagSet.of(FeatureFlags.BUNDLE)
@@ -176,7 +_,7 @@
CompletableFuture<HolderLookup.Provider> completablefuture = completablefuture3.thenApply(RegistrySetBuilder.PatchedRegistries::full);
CompletableFuture<HolderLookup.Provider> completablefuture1 = completablefuture3.thenApply(RegistrySetBuilder.PatchedRegistries::patches);
DataGenerator.PackGenerator datagenerator$packgenerator3 = datagenerator.getBuiltinDatapack(p_236683_, "update_1_21");
- datagenerator$packgenerator3.addProvider(UpdateOneTwentyOneRecipeProvider::new);
+ datagenerator$packgenerator3.addProvider(bindRegistries(UpdateOneTwentyOneRecipeProvider::new, completablefuture2));
TagsProvider<Block> tagsprovider2 = datagenerator$packgenerator3.addProvider(
p_307133_ -> new UpdateOneTwentyOneBlockTagsProvider(p_307133_, completablefuture1, tagsprovider3.contentsGetter())
);
31 changes: 7 additions & 24 deletions patches/net/minecraft/data/recipes/RecipeProvider.java.patch
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
--- a/net/minecraft/data/recipes/RecipeProvider.java
+++ b/net/minecraft/data/recipes/RecipeProvider.java
@@ -46,6 +_,7 @@
public abstract class RecipeProvider implements DataProvider {
protected final PackOutput.PathProvider recipePathProvider;
protected final PackOutput.PathProvider advancementPathProvider;
+ protected final CompletableFuture<net.minecraft.core.HolderLookup.Provider> lookupProvider;
private static final Map<BlockFamily.Variant, BiFunction<ItemLike, ItemLike, RecipeBuilder>> SHAPE_BUILDERS = ImmutableMap.<BlockFamily.Variant, BiFunction<ItemLike, ItemLike, RecipeBuilder>>builder(

)
@@ -66,27 +_,29 @@
@@ -66,6 +_,10 @@
.put(BlockFamily.Variant.WALL, (p_248024_, p_248025_) -> wallBuilder(RecipeCategory.DECORATIONS, p_248024_, Ingredient.of(p_248025_)))
.build();

- public RecipeProvider(PackOutput p_248933_) {
+ @Deprecated(forRemoval = true, since = "1.20.4") // TODO: remove in 1.20.5
+ public RecipeProvider(PackOutput p_248933_, CompletableFuture<net.minecraft.core.HolderLookup.Provider> lookupProvider) {
+ this(p_248933_);
+ }
public RecipeProvider(PackOutput p_248933_) {
this.recipePathProvider = p_248933_.createPathProvider(PackOutput.Target.DATA_PACK, "recipes");
this.advancementPathProvider = p_248933_.createPathProvider(PackOutput.Target.DATA_PACK, "advancements");
+ this.lookupProvider = lookupProvider;
}

@Override
public CompletableFuture<?> run(final CachedOutput p_254020_) {
+ return this.lookupProvider.thenCompose(provider -> {
final Set<ResourceLocation> set = Sets.newHashSet();
final List<CompletableFuture<?>> list = new ArrayList<>();
@@ -78,15 +_,15 @@
this.buildRecipes(
new RecipeOutput() {
@Override
Expand All @@ -42,12 +30,7 @@
)
);
}
@@ -99,16 +_,20 @@
}
}
);
- return CompletableFuture.allOf(list.toArray(p_253414_ -> new CompletableFuture[p_253414_]));
+ return CompletableFuture.allOf(list.toArray(p_253414_ -> new CompletableFuture[p_253414_])); });
@@ -103,12 +_,16 @@
}

protected CompletableFuture<?> buildAdvancement(CachedOutput p_253674_, AdvancementHolder p_301116_) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions patches/net/minecraft/server/level/ServerPlayer.java.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -234,6 +_,10 @@
}

private void broadcastDataValue(AbstractContainerMenu p_143455_, int p_143456_, int p_143457_) {
+ if (ServerPlayer.this.connection.isConnected(net.neoforged.neoforge.network.payload.AdvancedContainerSetDataPayload.ID)) {
+ ServerPlayer.this.connection.send(new net.neoforged.neoforge.network.payload.AdvancedContainerSetDataPayload(p_143455_.containerId, p_143456_, p_143457_));
+ return;
+ }
ServerPlayer.this.connection.send(new ClientboundContainerSetDataPacket(p_143455_.containerId, p_143456_, p_143457_));
}
};
@@ -594,6 +_,7 @@
@Override
public void die(DamageSource p_9035_) {
Expand Down
8 changes: 6 additions & 2 deletions patches/net/minecraft/world/effect/PoisonMobEffect.java.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
--- a/net/minecraft/world/effect/PoisonMobEffect.java
+++ b/net/minecraft/world/effect/PoisonMobEffect.java
@@ -11,7 +_,8 @@
@@ -11,7 +_,12 @@
public void applyEffectTick(LivingEntity p_296276_, int p_296233_) {
super.applyEffectTick(p_296276_, p_296233_);
if (p_296276_.getHealth() > 1.0F) {
- p_296276_.hurt(p_296276_.damageSources().magic(), 1.0F);
+ // Neo: Replace DamageSources#magic() with neoforge:poison to allow differentiating poison damage.
+ p_296276_.hurt(p_296276_.damageSources().source(net.neoforged.neoforge.common.NeoForgeMod.POISON_DAMAGE), 1.0F);
+ // Fallback to minecraft:magic in client code when connecting to a vanilla server.
+ // LivingEntity#hurt(DamageSource) will no-op in client code immediately, but the holder is resolved before the no-op.
+ var dTypeReg = p_296276_.damageSources().damageTypes;
+ var dType = dTypeReg.getHolder(net.neoforged.neoforge.common.NeoForgeMod.POISON_DAMAGE).orElse(dTypeReg.getHolderOrThrow(net.minecraft.world.damagesource.DamageTypes.MAGIC));
+ p_296276_.hurt(new net.minecraft.world.damagesource.DamageSource(dType), 1.0F);
}
}

Loading

0 comments on commit 77190d0

Please sign in to comment.