Skip to content

Commit

Permalink
Merge branch 'mc1.19/fabric/dev' into mc1.20.1/fabric/dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	FABRIC_CHANGELOG.txt
#	gradle.properties
#	src/main/java/com/simibubi/create/foundation/mixin/client/MapRendererMapInstanceMixin.java
  • Loading branch information
IThundxr committed Mar 24, 2024
2 parents 5bfc04e + b750261 commit 7831164
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 77 deletions.
23 changes: 6 additions & 17 deletions FABRIC_CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@ No formatting, just plain text. CurseForge support for it is terrible.

Change logging starts below:
----------
- update to patch F
- fix schematic-printing deployers consuming double the resources they should (#1273)
- fix invalid auto-shapeless recipes from appearing in EMI (#1148)
- potential fix for a rare belt-related crash (#941)
- potential fix for errors/crashes due to a missing locale (#1120)
- fix emptying and filling recipes across JEI, REI, and EMI
- fix crash with belts and funnels (#1246)
- add in-world interaction EMI recipes for Create's fluid interactions (#1170)
- fix some errors in REI with chanced recipe outputs (#646, #902)
- fix a crash with Jade and Deployers (#1139)
- fix the Wand of Symmetry always placing double slabs (#1086)
- fix switched inputs in clipboard tooltip (#1212)
- fix copycats having bad translucency (#1167)
- fix intense fog underwater with Sodium (#1045)
- fix piston extension poles being considered unmovable (#1307)
- fix running on the edge of copycats producing missing texture particles (#1084)
- fix backtanks being damageable (#1217)
- fix crashes with fluid and item schedule conditions (#1363, #1391, #1392)
- fix crashes viewing recipes in REI (#1378, #1379, #1380, #1382, #1395)
- fix ingredients of sequenced assembly recipes not being properly linked to their uses (#1394)
- marked known outdated broken addon versions as incompatible
- marked Sound Physics Remastered as broken due to calling non thread safe code off thread
- add cycling to the block displayed in manual item application in EMI
63 changes: 25 additions & 38 deletions src/main/java/com/simibubi/create/compat/emi/CreateEmiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllFluids;
Expand Down Expand Up @@ -66,8 +65,7 @@
import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.item.TagDependentIngredientItem;

import com.tterrag.registrate.fabric.SimpleFlowableFluid;
import com.tterrag.registrate.util.nullness.NonnullType;
import com.tterrag.registrate.util.entry.FluidEntry;

import dev.emi.emi.api.EmiApi;
import dev.emi.emi.api.EmiPlugin;
Expand Down Expand Up @@ -114,8 +112,6 @@
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;

import org.jetbrains.annotations.NotNull;

public class CreateEmiPlugin implements EmiPlugin {
public static final Map<ResourceLocation, EmiRecipeCategory> ALL = new LinkedHashMap<>();

Expand Down Expand Up @@ -287,10 +283,8 @@ public void register(EmiRegistry registry) {
addAll(registry, AllRecipeTypes.MECHANICAL_CRAFTING, MECHANICAL_CRAFTING, MechanicalCraftingEmiRecipe::new);

// In World Interaction recipes
addFluidInteractionRecipe(registry, "create/limestone", AllFluids.HONEY.get(),
Fluids.LAVA, AllPaletteStoneTypes.LIMESTONE.getBaseBlock().get());
addFluidInteractionRecipe(registry, "create/scoria", AllFluids.CHOCOLATE.get(),
Fluids.LAVA, AllPaletteStoneTypes.SCORIA.getBaseBlock().get());
addLavaCollision(registry, AllFluids.HONEY, AllPaletteStoneTypes.LIMESTONE);
addLavaCollision(registry, AllFluids.CHOCOLATE, AllPaletteStoneTypes.SCORIA);

// Introspective recipes based on present stacks need to make sure
// all stacks are populated by other plugins
Expand All @@ -313,41 +307,34 @@ private <T extends Recipe<?>> void addAll(EmiRegistry registry, AllRecipeTypes t
}

/**
* Register an In World Interaction recipe
*
* @param registry EmiRegistry
* @param outputId The block being outputted in the form of `modid/block` an example for stone would be `minecraft/stone`
* @param left The stack that will be shown in the left input
* @param right The stack that will be shown in the right input
* @param output The stack that will be outputted from this interaction recipe
* Register an In World Interaction recipe for a fluid colliding with lava.
*/
private void addFluidInteractionRecipe(@NotNull EmiRegistry registry, String outputId, Fluid left, Fluid right, Block output) {
// EmiStack doesn't accept flowing fluids, must always be a source
if (left instanceof SimpleFlowableFluid.Flowing flowing)
left = flowing.getSource();
if (right instanceof SimpleFlowableFluid.Flowing flowing)
right = flowing.getSource();
private void addLavaCollision(EmiRegistry registry, FluidEntry<?> fluid, AllPaletteStoneTypes outputType) {
EmiStack lava = EmiStack.of(Fluids.LAVA, FluidConstants.BUCKET);
lava = lava.setRemainder(lava);

EmiStack fluidStack = EmiStack.of(fluid.get().getSource(), FluidConstants.BUCKET);
fluidStack = fluidStack.setRemainder(fluidStack);

EmiStack leftInput = EmiStack.of(left, 81000);
EmiStack rightInput = EmiStack.of(right, 81000);
Block block = outputType.getBaseBlock().get();
EmiStack output = EmiStack.of(block);
String blockName = Registry.BLOCK.getKey(block).getPath();

// fabric: 81000 droplets = 1000 mb
addRecipeSafe(registry, () -> EmiWorldInteractionRecipe.builder()
.id(new ResourceLocation("emi", "/world/fluid_interaction/" + outputId))
.leftInput(leftInput.copy().setRemainder(leftInput))
.rightInput(rightInput.copy().setRemainder(rightInput), false)
.output(EmiStack.of(output))
.build()
registry.addRecipe(
EmiWorldInteractionRecipe.builder()
.id(synthetic("emi/fluid_interaction/" + blockName))
.leftInput(fluidStack)
.rightInput(lava, false)
.output(output)
.build()
);
}

private static void addRecipeSafe(EmiRegistry registry, Supplier<EmiRecipe> supplier) {
try {
registry.addRecipe(supplier.get());
} catch (Throwable e) {
Create.LOGGER.warn("[Create] Exception thrown when parsing EMI recipe (no ID available)");
Create.LOGGER.error(e.toString());
}
private static ResourceLocation synthetic(String path) {
if (path.startsWith("/"))
throw new IllegalArgumentException("Starting slash is added automatically");
// EMI recommends starting synthetic IDs with a slash so that they can't possibly conflict with data packs.
return Create.asResource('/' + path);
}

private void addDeferredRecipes(Consumer<EmiRecipe> consumer) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/simibubi/create/compat/emi/CyclingDrawable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.simibubi.create.compat.emi;

import com.mojang.blaze3d.vertex.PoseStack;

import dev.emi.emi.api.widget.DrawableWidget.DrawableWidgetConsumer;

import java.util.List;

public record CyclingDrawable(List<? extends DrawableWidgetConsumer> children) implements DrawableWidgetConsumer {
@Override
public void render(PoseStack matrices, int x, int y, float delta) {
this.choose().render(matrices, x, y, delta);
}

private DrawableWidgetConsumer choose() {
// ticks are not available, use system time.
long millis = System.currentTimeMillis();
long seconds = millis / 1000;
int index = (int) (seconds % this.children.size());
return this.children.get(index);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.simibubi.create.compat.emi.recipes;

import com.simibubi.create.compat.emi.CreateEmiPlugin;
import com.simibubi.create.compat.emi.CyclingDrawable;
import com.simibubi.create.compat.emi.RenderedBlock;
import com.simibubi.create.content.kinetics.deployer.ItemApplicationRecipe;
import com.simibubi.create.foundation.gui.AllGuiTextures;
import com.simibubi.create.foundation.utility.Lang;

import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.widget.DrawableWidget.DrawableWidgetConsumer;
import dev.emi.emi.api.widget.SlotWidget;
import dev.emi.emi.api.widget.WidgetHolder;
import net.minecraft.ChatFormatting;

import java.util.List;
import java.util.Objects;

public class ManualItemApplicationEmiRecipe extends CreateEmiRecipe<ItemApplicationRecipe> {
public ManualItemApplicationEmiRecipe(ItemApplicationRecipe recipe) {
super(CreateEmiPlugin.ITEM_APPLICATION, recipe, 177, 60);
Expand All @@ -21,8 +26,13 @@ public void addWidgets(WidgetHolder widgets) {
EmiIngredient base = input.get(0);
addSlot(widgets, base, 27, 38);

RenderedBlock block = RenderedBlock.of(base);
if (block != null) {
List<? extends DrawableWidgetConsumer> blocks = base.getEmiStacks().stream()
.map(RenderedBlock::of)
.filter(Objects::nonNull)
.toList();

if (!blocks.isEmpty()) {
CyclingDrawable block = new CyclingDrawable(blocks);
widgets.addDrawable(0, 0, 0, 0, block);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ public NonNullList<Ingredient> getIngredients() {
if (ingredientList == null) {
ingredientList = NonNullList.create();
ingredientList.add(ingredient);
for (SequencedRecipe<?> recipe : this.sequence) {
ingredientList.addAll(recipe.getRecipe().getIngredients());
}
}
return ingredientList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,54 @@

import java.util.Iterator;

import org.joml.Matrix4f;
import com.google.common.collect.Iterators;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;

import com.llamalad7.mixinextras.sugar.Local;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.foundation.map.CustomRenderedMapDecoration;

import net.minecraft.client.gui.MapRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;

import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

// fabric: we have an AW for it, and compiler complains if specified by string
@Mixin(value = MapRenderer.MapInstance.class, priority = 1100) // apply after porting lib's current busted mixin here
@Mixin(MapRenderer.MapInstance.class)
public class MapRendererMapInstanceMixin {
@Shadow
private MapItemSavedData data;

// @Group(name = "custom_decoration_rendering", min = 1, max = 1)
// fabric: we inject in a different place to call our method before porting lib returns
@Inject(method = "draw(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ZI)V", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;hasNext()Z"), locals = LocalCapture.CAPTURE_FAILHARD)
private void onDraw(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, CallbackInfo ci, int i, int j, float f, Matrix4f matrix4f, VertexConsumer vertexConsumer, int index, Iterator<MapDecoration> iterator) {
if (iterator.next() instanceof CustomRenderedMapDecoration renderer) {
renderer.render(poseStack, bufferSource, active, packedLight, data, index);
}
// fabric: completely redone

@ModifyExpressionValue(
method = "draw",
at = @At(
value = "INVOKE",
target = "Ljava/lang/Iterable;iterator()Ljava/util/Iterator;"
)
)
private Iterator<MapDecoration> wrapIterator(Iterator<MapDecoration> original) {
// skip rendering custom ones in the main loop
return Iterators.filter(original, decoration -> !(decoration instanceof CustomRenderedMapDecoration));
}

// fabric: optifine is not supported
// @Group(name = "custom_decoration_rendering")
// @Inject(method = "draw(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ZI)V", at = @At(value = "FIELD", target = "net/optifine/reflect/Reflector.ForgeMapDecoration_render:Lnet/optifine/reflect/ReflectorMethod;", opcode = Opcodes.GETSTATIC, ordinal = 1, remap = false), locals = LocalCapture.CAPTURE_FAILHARD)
// private void onDrawOptifine(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, CallbackInfo ci, int i, int j, float f, Matrix4f matrix4f, VertexConsumer vertexConsumer, int index, Iterator<MapDecoration> iterator, MapDecoration decoration) {
// if (decoration instanceof CustomRenderedMapDecoration renderer) {
// renderer.render(poseStack, bufferSource, active, packedLight, data, index);
// }
// }
@Inject(method = "draw", at = @At("TAIL"))
private void renderCustomDecorations(PoseStack poseStack, MultiBufferSource bufferSource, boolean active,
int packedLight, CallbackInfo ci, @Local(ordinal = 3) int index) { // ignore error, works
// render custom ones in second loop
for (MapDecoration decoration : this.data.getDecorations()) {
if (decoration instanceof CustomRenderedMapDecoration renderer) {
renderer.render(poseStack, bufferSource, active, packedLight, data, index);
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"iris": "<=1.2.5",
"sodium": "<=0.4.10",

"sound_physics_remastered": "*",

"railways": "<1.5.3",
"create_enchantment_industry": "<1.2.16",
"create_interactive": "<=1.0.2-beta.1",
Expand Down

0 comments on commit 7831164

Please sign in to comment.