Fix ingredients being "empty" when playing multiplayer

These changes reflects Forge's PR https://github.com/MinecraftForge/MinecraftForge/pull/9688
This commit is contained in:
DBotThePony 2023-08-18 23:43:54 +07:00
parent 0428b60561
commit f56884705a
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 34 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.TagsUpdatedEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModList;
@ -151,6 +152,10 @@ public final class OverdriveThatMatters {
ToolsConfig.INSTANCE.register();
}
private void tagsUpdated(TagsUpdatedEvent event) {
Ingredient.invalidateAll();
}
private void setup(final FMLCommonSetupEvent event) {
EVENT_BUS.addListener(EventPriority.NORMAL, DrivePool.INSTANCE::onWorldSave);
@ -200,6 +205,8 @@ public final class OverdriveThatMatters {
EVENT_BUS.addListener(EventPriority.NORMAL, DevChestBlockEntity.Companion::mappingsChanged);
EVENT_BUS.addListener(EventPriority.NORMAL, this::tagsUpdated);
MatteryPlayerNetworkChannel.INSTANCE.register();
MenuNetworkChannel.INSTANCE.register();
WeaponNetworkChannel.INSTANCE.register();

View File

@ -0,0 +1,19 @@
package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(Ingredient.class)
public abstract class IngredientMixin {
@Inject(
method = "getItems()[Lnet/minecraft/world/item/ItemStack;",
at = @At("HEAD")
)
public void getItemsPatch(CallbackInfoReturnable<ItemStack[]> info) {
((Ingredient) (Object) this).checkInvalidation();
}
}

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.data
import com.google.gson.JsonParseException
import com.google.gson.JsonSyntaxException
import com.mojang.datafixers.util.Pair
import com.mojang.serialization.Codec
@ -14,10 +15,12 @@ object IngredientCodec : Codec<Ingredient> {
}
override fun <T : Any> decode(ops: DynamicOps<T>, input: T): DataResult<Pair<Ingredient, T>> {
try {
return DataResult.success(Pair(Ingredient.fromJson(ops.convertTo(JsonOps.INSTANCE, input)), ops.empty()))
return try {
DataResult.success(Pair(Ingredient.fromJson(ops.convertTo(JsonOps.INSTANCE, input)), ops.empty()))
} catch (err: JsonSyntaxException) {
return DataResult.error { "Error decoding Ingredient: ${err.message}" }
DataResult.error { "Error decoding Ingredient: ${err.message}" }
} catch (err: JsonParseException) {
DataResult.error { "Error decoding Ingredient: ${err.message}" }
}
}
}

View File

@ -56,9 +56,6 @@ class PlatePressRecipe(
}
override fun getIngredients(): NonNullList<Ingredient> {
if (isIncomplete)
return super.getIngredients()
return NonNullList.of(Ingredient.EMPTY, input)
}

View File

@ -15,7 +15,8 @@
"MixinAbstractHurtingProjectile",
"SimpleCriterionTriggerMixin",
"InventoryChangeTriggerMixin",
"MixinPlayer"
"MixinPlayer",
"IngredientMixin"
],
"client": [
"MixinGameRenderer",