Skip to content

Commit

Permalink
Merge branch '1.21.x' into 1213load-gametest-resources-once
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt authored Nov 9, 2024
2 parents 7b32f37 + 424b600 commit bd814f4
Show file tree
Hide file tree
Showing 47 changed files with 737 additions and 241 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ neoform_version=20241023.131943
neoforge_snapshot_next_stable=21.4

mergetool_version=2.0.0
accesstransformers_version=10.0.1
accesstransformers_version=11.0.1
coremods_version=6.0.4
eventbus_version=8.0.2
modlauncher_version=11.0.4
Expand All @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.1
fancy_mod_loader_version=4.0.29
fancy_mod_loader_version=5.0.1
mojang_logging_version=1.1.1
log4j_version=2.22.1
guava_version=31.1.2-jre
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/client/resources/model/ModelManager.java
+++ b/net/minecraft/client/resources/model/ModelManager.java
@@ -71,13 +_,14 @@
@@ -71,18 +_,20 @@
TextureAtlas.LOCATION_BLOCKS,
ResourceLocation.withDefaultNamespace("blocks")
);
Expand All @@ -16,6 +16,12 @@

public ModelManager(TextureManager p_119406_, BlockColors p_119407_, int p_119408_) {
this.blockColors = p_119407_;
this.maxMipmapLevels = p_119408_;
this.blockModelShaper = new BlockModelShaper(this);
+ Map<ResourceLocation, ResourceLocation> VANILLA_ATLASES = net.neoforged.neoforge.client.ClientHooks.gatherMaterialAtlases(ModelManager.VANILLA_ATLASES);
this.atlases = new AtlasSet(VANILLA_ATLASES, p_119406_);
}

@@ -102,6 +_,7 @@
public final CompletableFuture<Void> reload(
PreparableReloadListener.PreparationBarrier p_249079_, ResourceManager p_251134_, Executor p_250550_, Executor p_249221_
Expand Down
9 changes: 0 additions & 9 deletions patches/net/minecraft/world/entity/LivingEntity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,6 @@
}

protected float getWaterSlowDown() {
@@ -2184,7 +_,7 @@
public void travel(Vec3 p_21280_) {
if (this.isControlledByLocalInstance()) {
FluidState fluidstate = this.level().getFluidState(this.blockPosition());
- if ((this.isInWater() || this.isInLava()) && this.isAffectedByFluids() && !this.canStandOnFluid(fluidstate)) {
+ if ((this.isInWater() || (this.isInFluidType(fluidstate) && fluidstate.getFluidType() != net.neoforged.neoforge.common.NeoForgeMod.LAVA_TYPE.value())) && this.isAffectedByFluids() && !this.canStandOnFluid(fluidstate)) {
this.travelInFluid(p_21280_);
} else if (this.isFallFlying()) {
this.travelFallFlying();
@@ -2196,7 +_,7 @@

private void travelInAir(Vec3 p_362457_) {
Expand Down
26 changes: 24 additions & 2 deletions patches/net/minecraft/world/level/ServerExplosion.java.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -165,7 +_,12 @@
return new ObjectArrayList<>(set);
}

+ @Deprecated
private void hurtEntities() {
+ this.hurtEntities(List.of());
+ }
+
+ private void hurtEntities(List<BlockPos> blocks) {
float f = this.radius * 2.0F;
int i = Mth.floor(this.center.x - (double)f - 1.0);
int j = Mth.floor(this.center.x + (double)f + 1.0);
@@ -174,7 +_,9 @@
int i1 = Mth.floor(this.center.z - (double)f - 1.0);
int j1 = Mth.floor(this.center.z + (double)f + 1.0);

- for (Entity entity : this.level.getEntities(this.source, new AABB((double)i, (double)k, (double)i1, (double)j, (double)l, (double)j1))) {
+ List<Entity> list = this.level.getEntities(this.source, new AABB((double)i, (double)k, (double)i1, (double)j, (double)l, (double)j1));
+ net.neoforged.neoforge.event.EventHooks.onExplosionDetonate(this.level, this, list, f);
+ net.neoforged.neoforge.event.EventHooks.onExplosionDetonate(this.level, this, list, blocks);
+ for (Entity entity : list) {
if (!entity.ignoreExplosion(this)) {
double d0 = Math.sqrt(entity.distanceToSqr(this.center)) / (double)f;
Expand All @@ -15,7 +28,16 @@
d2 *= d6;
d3 *= d6;
Vec3 vec3 = new Vec3(d1, d2, d3);
+ vec3 = net.neoforged.neoforge.event.EventHooks.getExplosionKnockback(this.level, this, entity, vec3);
+ vec3 = net.neoforged.neoforge.event.EventHooks.getExplosionKnockback(this.level, this, entity, vec3, blocks);
entity.setDeltaMovement(entity.getDeltaMovement().add(vec3));
if (entity instanceof Player) {
Player player = (Player)entity;
@@ -246,7 +_,7 @@
public void explode() {
this.level.gameEvent(this.source, GameEvent.EXPLODE, this.center);
List<BlockPos> list = this.calculateExplodedPositions();
- this.hurtEntities();
+ this.hurtEntities(list);
if (this.interactsWithBlocks()) {
ProfilerFiller profilerfiller = Profiler.get();
profilerfiller.push("explosion_blocks");
7 changes: 7 additions & 0 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
import net.neoforged.neoforge.client.event.RegisterMaterialAtlasesEvent;
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
import net.neoforged.neoforge.client.event.RegisterShadersEvent;
import net.neoforged.neoforge.client.event.RegisterSpriteSourceTypesEvent;
Expand Down Expand Up @@ -1094,4 +1095,10 @@ public static boolean isInTranslucentBlockOutlinePass(Level level, BlockPos pos,
ChunkRenderTypeSet renderTypes = model.getRenderTypes(state, OUTLINE_PASS_RANDOM, level.getModelData(pos));
return renderTypes.contains(RenderType.TRANSLUCENT) || renderTypes.contains(RenderType.TRIPWIRE);
}

public static Map<ResourceLocation, ResourceLocation> gatherMaterialAtlases(Map<ResourceLocation, ResourceLocation> vanillaAtlases) {
vanillaAtlases = new HashMap<>(vanillaAtlases);
ModLoader.postEvent(new RegisterMaterialAtlasesEvent(vanillaAtlases));
return Map.copyOf(vanillaAtlases);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.client.event;

import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.resources.TextureAtlasHolder;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.ICancellableEvent;
import net.neoforged.fml.LogicalSide;
import net.neoforged.fml.event.IModBusEvent;
import org.jetbrains.annotations.ApiStatus;

/**
* Fired for registering {@linkplain TextureAtlas texture atlases} that will be used with {@link Material} or
* other systems which retrieve the atlas via {@link Minecraft#getTextureAtlas(ResourceLocation)} or
* {@link ModelManager#getAtlas(ResourceLocation)}.
* <p>
* If an atlas is registered via this event, then it must <b>NOT</b> be used through a {@link TextureAtlasHolder}.
* <p>
* This event fires during startup when the {@link ModelManager} is constructed.
* <p>
* This event is not {@linkplain ICancellableEvent cancellable}.
* <p>
* This event is fired on the mod-specific event bus, only on the {@linkplain LogicalSide#CLIENT logical client}.
*/
public class RegisterMaterialAtlasesEvent extends Event implements IModBusEvent {
private final Map<ResourceLocation, ResourceLocation> atlases;

@ApiStatus.Internal
public RegisterMaterialAtlasesEvent(Map<ResourceLocation, ResourceLocation> atlases) {
this.atlases = atlases;
}

/**
* Register a texture atlas with the given name and info location
*
* @param atlasLocation The name of the texture atlas
* @param atlasInfoLocation The location of the atlas info JSON relative to the {@code atlases} directory
*/
public void register(ResourceLocation atlasLocation, ResourceLocation atlasInfoLocation) {
ResourceLocation oldAtlasInfoLoc = this.atlases.putIfAbsent(atlasLocation, atlasInfoLocation);
if (oldAtlasInfoLoc != null) {
throw new IllegalStateException(String.format(
"Duplicate registration of atlas: %s (old info: %s, new info: %s)",
atlasLocation,
oldAtlasInfoLoc,
atlasInfoLocation));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Functio
if (!context.isComponentVisible(name, true))
continue;
var model = entry.getValue();
bakedPartsBuilder.put(name, model.bake(baker, spriteGetter, modelState));
bakedPartsBuilder.put(name, baker.bakeUncached(model, modelState, spriteGetter));
}
var bakedParts = bakedPartsBuilder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public BakedModel bake(IGeometryBakingContext context, ModelBaker baker, Functio
BakedModel baked = new Baked(
context.useAmbientOcclusion(), context.isGui3d(), context.useBlockLight(),
spriteGetter.apply(context.getMaterial("particle")),
baseModel.bake(baker, spriteGetter, modelState),
ImmutableMap.copyOf(Maps.transformValues(perspectives, value -> value.bake(baker, spriteGetter, modelState))));
baker.bakeUncached(baseModel, modelState, spriteGetter),
ImmutableMap.copyOf(Maps.transformValues(perspectives, value -> baker.bakeUncached(value, modelState, spriteGetter))));
if (!overrides.isEmpty()) {
baked = new ItemModel.BakedModelWithOverrides(baked, new BakedOverrides(baker, overrides, spriteGetter));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ public <V extends Comparable<? super V>> ConfigValue<V> defineInRange(String pat
public <V extends Comparable<? super V>> ConfigValue<V> defineInRange(List<String> path, Supplier<V> defaultSupplier, V min, V max, Class<V> clazz) {
Range<V> range = new Range<>(clazz, min, max);
context.setRange(range);
comment("Range: " + range.toString());
comment(" Default: " + defaultSupplier.get());
comment(" Range: " + range);
return define(path, defaultSupplier, range);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -63,7 +62,7 @@ public CompletableFuture<?> run(CachedOutput cache) {
return lookupProvider.thenCompose(provider -> {
gather(provider);

final DynamicOps<JsonElement> dynamicOps = RegistryOps.create(JsonOps.INSTANCE, provider);
final DynamicOps<JsonElement> dynamicOps = provider.createSerializationContext(JsonOps.INSTANCE);

return CompletableFuture.allOf(this.builders.entrySet().stream().map(entry -> {
DataMapType<?, ?> type = entry.getKey();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/neoforged/neoforge/event/EventHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public static boolean onExplosionStart(Level level, ServerExplosion explosion) {
return NeoForge.EVENT_BUS.post(new ExplosionEvent.Start(level, explosion)).isCanceled();
}

public static void onExplosionDetonate(Level level, ServerExplosion explosion, List<Entity> list, double diameter) {
public static void onExplosionDetonate(Level level, ServerExplosion explosion, List<Entity> entities, List<BlockPos> blocks) {
//Filter entities to only those who are effected, to prevent modders from seeing more then will be hurt.
/* Enable this if we get issues with modders looping to much.
Iterator<Entity> itr = list.iterator();
Expand All @@ -600,7 +600,7 @@ public static void onExplosionDetonate(Level level, ServerExplosion explosion, L
if (e.isImmuneToExplosions() || dist > 1.0F) itr.remove();
}
*/
NeoForge.EVENT_BUS.post(new ExplosionEvent.Detonate(level, explosion, list));
NeoForge.EVENT_BUS.post(new ExplosionEvent.Detonate(level, explosion, entities, blocks));
}

/**
Expand All @@ -613,8 +613,8 @@ public static void onExplosionDetonate(Level level, ServerExplosion explosion, L
* @param initialVelocity The explosion calculated velocity for the entity
* @return The new explosion velocity to add to the entity's existing velocity
*/
public static Vec3 getExplosionKnockback(Level level, ServerExplosion explosion, Entity entity, Vec3 initialVelocity) {
ExplosionKnockbackEvent event = new ExplosionKnockbackEvent(level, explosion, entity, initialVelocity);
public static Vec3 getExplosionKnockback(Level level, ServerExplosion explosion, Entity entity, Vec3 initialVelocity, List<BlockPos> blocks) {
ExplosionKnockbackEvent event = new ExplosionKnockbackEvent(level, explosion, entity, initialVelocity, blocks);
NeoForge.EVENT_BUS.post(event);
return event.getKnockbackVelocity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package net.neoforged.neoforge.event.level;

import java.util.List;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerExplosion;
Expand Down Expand Up @@ -63,17 +64,18 @@ public Start(Level level, ServerExplosion explosion) {
*/
public static class Detonate extends ExplosionEvent {
private final List<Entity> entityList;
private final List<BlockPos> blockList;

public Detonate(Level level, ServerExplosion explosion, List<Entity> entityList) {
public Detonate(Level level, ServerExplosion explosion, List<Entity> entityList, List<BlockPos> blockList) {
super(level, explosion);
this.entityList = entityList;
this.blockList = blockList;
}

/** return the list of blocks affected by the explosion. */
// FIXME porting: explosions changed a bit
/*public List<BlockPos> getAffectedBlocks() {
return getExplosion().getToBlow();
}*/
public List<BlockPos> getAffectedBlocks() {
return this.blockList;
}

/** return the list of entities affected by the explosion. */
public List<Entity> getAffectedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package net.neoforged.neoforge.event.level;

import java.util.List;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerExplosion;
Expand All @@ -21,19 +23,20 @@
*/
public class ExplosionKnockbackEvent extends ExplosionEvent {
private final Entity entity;
private final List<BlockPos> blockList;
private Vec3 knockbackVelocity;

public ExplosionKnockbackEvent(Level level, ServerExplosion explosion, Entity entity, Vec3 knockbackVelocity) {
public ExplosionKnockbackEvent(Level level, ServerExplosion explosion, Entity entity, Vec3 knockbackVelocity, List<BlockPos> blockList) {
super(level, explosion);
this.entity = entity;
this.blockList = blockList;
this.knockbackVelocity = knockbackVelocity;
}

/** return the list of blocks affected by the explosion. */
// FIXME porting: explosions changed a bit
/*public List<BlockPos> getAffectedBlocks() {
return getExplosion().getToBlow();
}*/
public List<BlockPos> getAffectedBlocks() {
return this.blockList;
}

/** return the entity affected by the explosion knockback. */
public Entity getAffectedEntity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,41 +75,41 @@ public static void handleClientboundPayload(ExtensibleEnumDataPayload payload, I
Map<String, EnumEntry> localEnumEntries = getEnumEntries();
Map<String, EnumEntry> remoteEnumEntries = payload.enumEntries();

Set<String> keyDiff = Sets.symmetricDifference(localEnumEntries.keySet(), remoteEnumEntries.keySet());
if (!keyDiff.isEmpty()) {
context.disconnect(Component.translatable("neoforge.network.extensible_enums.enum_set_mismatch"));
return;
}

Map<String, Mismatch> mismatched = new HashMap<>();
for (EnumEntry localEntry : localEnumEntries.values()) {
EnumEntry remoteEntry = remoteEnumEntries.get(localEntry.className);
if (!localEntry.isExtended() && !remoteEntry.isExtended()) {
for (String className : Sets.union(localEnumEntries.keySet(), remoteEnumEntries.keySet())) {
EnumEntry localEntry = localEnumEntries.get(className);
EnumEntry remoteEntry = remoteEnumEntries.get(className);
if ((localEntry == null && remoteEntry.isExtended()) || (remoteEntry == null && localEntry.isExtended())) {
mismatched.put(className, Mismatch.EXTENSIBILITY);
continue;
}

if ((localEntry == null || !localEntry.isExtended()) && (remoteEntry == null || !remoteEntry.isExtended())) {
continue;
}

if (localEntry.networkCheck != remoteEntry.networkCheck) {
mismatched.put(localEntry.className, Mismatch.NETWORK_CHECK);
mismatched.put(className, Mismatch.NETWORK_CHECK);
continue;
}

if (localEntry.isExtended() != remoteEntry.isExtended()) {
mismatched.put(localEntry.className, Mismatch.EXTENSION);
mismatched.put(className, Mismatch.EXTENSION);
continue;
}

ExtensionData localData = localEntry.data.orElseThrow();
ExtensionData remoteData = remoteEntry.data.orElseThrow();
if (localData.vanillaCount != remoteData.vanillaCount || localData.totalCount != remoteData.totalCount) {
mismatched.put(localEntry.className, Mismatch.ENTRY_COUNT);
mismatched.put(className, Mismatch.ENTRY_COUNT);
continue;
}

List<String> localValues = localData.entries;
List<String> remoteValues = remoteData.entries;
for (int i = 0; i < localData.totalCount - localData.vanillaCount; i++) {
if (!localValues.get(i).equals(remoteValues.get(i))) {
mismatched.put(localEntry.className, Mismatch.ENTRY_MISMATCH);
mismatched.put(className, Mismatch.ENTRY_MISMATCH);
break;
}
}
Expand All @@ -122,6 +122,13 @@ public static void handleClientboundPayload(ExtensibleEnumDataPayload payload, I
String enumClass = entry.getKey();
message.append("\n").append(enumClass).append(": ");
switch (entry.getValue()) {
case EXTENSIBILITY -> {
if (remoteEnumEntries.containsKey(enumClass)) {
message.append("Enum is extensible on the server but not on the client");
} else {
message.append("Enum is extensible on the client but not on the server");
}
}
case NETWORK_CHECK -> message.append("Mismatched NetworkCheck (server: ")
.append(remoteEnumEntries.get(enumClass).networkCheck)
.append(", client: ")
Expand Down Expand Up @@ -258,6 +265,7 @@ public record ExtensionData(int vanillaCount, int totalCount, List<String> entri
}

private enum Mismatch {
EXTENSIBILITY,
NETWORK_CHECK,
EXTENSION,
ENTRY_COUNT,
Expand Down
Loading

0 comments on commit bd814f4

Please sign in to comment.