From 10c5a7c98c4954ae72f6057e13bdd25cbe227759 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Mon, 22 Jan 2024 16:54:31 -0500 Subject: [PATCH 1/4] backport fix for #68 --- gradle.properties | 4 ++-- .../porting_lib/mixin/client/ShaderInstanceMixin.java | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index c08d805bc..38d1e0a41 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,8 +7,8 @@ mod_version = 1.2.-beta # https://fabricmc.net/develop minecraft_version = 1.18.2 -loader_version = 0.14.19 -fabric_version = 0.56.0+1.18.2 +loader_version = 0.15.6 +fabric_version = 0.77.0+1.18.2 serialization_hooks_version = 0.3.23 forge_tags_version = 2.1 diff --git a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/client/ShaderInstanceMixin.java b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/client/ShaderInstanceMixin.java index eb9be9e9d..60c6b75d5 100644 --- a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/client/ShaderInstanceMixin.java +++ b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/client/ShaderInstanceMixin.java @@ -31,12 +31,5 @@ private String fixId(String path) { return split.getNamespace() + ":shaders/core/" + split.getPath() + ".json"; } - @ModifyVariable(method = "getOrCreate", at = @At("STORE"), ordinal = 1) - private static String fixPath(String path, ResourceProvider resourceProvider, Program.Type programType, String name) { - if (!name.contains(":")) { - return path; - } - ResourceLocation split = new ResourceLocation(name); - return split.getNamespace() + ":shaders/core/" + split.getPath() + programType.getExtension(); - } + // note: do not need to modify getOrCreate as FAPI does it } From 4ca6030c13bde2d260e61371c8c17a8a97dceae5 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Tue, 20 Feb 2024 20:08:08 -0500 Subject: [PATCH 2/4] during place event --- .../porting_lib/event/common/BlockEvents.java | 14 ++++++++++++++ .../mixin/common/BlockItemMixin.java | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java b/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java index baa974a46..f9cd61c1d 100644 --- a/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java +++ b/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java @@ -60,6 +60,20 @@ public interface BeforePlace { InteractionResult beforePlace(BlockPlaceContext ctx); } + /** + * Invoked during block placement from {@link BlockItem#place(BlockPlaceContext)}. + * Called on both client and server. + * Passes along the placement state of the block. + */ + public static final Event DURING_PLACE = EventFactory.createArrayBacked(DuringPlace.class, callbacks -> (context, state) -> { + for (DuringPlace callback : callbacks) + callback.duringPlace(context, state); + }); + + public interface DuringPlace { + void duringPlace(BlockPlaceContext ctx, BlockState state); + } + /** * Invoked after a block is placed, from {@link BlockItem#useOn(UseOnContext)}. Called on both client and server. */ diff --git a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java index 7bb94241e..e00791522 100644 --- a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java +++ b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java @@ -2,8 +2,13 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; + import io.github.fabricators_of_create.porting_lib.event.common.BlockEvents; +import net.minecraft.world.level.block.state.BlockState; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -24,6 +29,19 @@ public abstract class BlockItemMixin implements BlockItemExtensions { cir.setReturnValue(result); } + @WrapOperation( + method = "place", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/item/BlockItem;getPlacementState(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/level/block/state/BlockState;" + ) + ) + private BlockState create$afterPlace(BlockItem instance, BlockPlaceContext context, Operation original) { + BlockState state = original.call(instance, context); + BlockEvents.DURING_PLACE.invoker().duringPlace(context, state); + return state; + } + @ModifyExpressionValue( method = "useOn", at = @At( From ee99c4cb4d0b17c04b29d790de78dff491157908 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Tue, 20 Feb 2024 21:13:40 -0500 Subject: [PATCH 3/4] Post process place event --- .../porting_lib/event/common/BlockEvents.java | 29 ++++++++++--------- .../mixin/common/BlockItemMixin.java | 23 +++++---------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java b/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java index f9cd61c1d..d6c6f4739 100644 --- a/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java +++ b/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java @@ -60,23 +60,10 @@ public interface BeforePlace { InteractionResult beforePlace(BlockPlaceContext ctx); } - /** - * Invoked during block placement from {@link BlockItem#place(BlockPlaceContext)}. - * Called on both client and server. - * Passes along the placement state of the block. - */ - public static final Event DURING_PLACE = EventFactory.createArrayBacked(DuringPlace.class, callbacks -> (context, state) -> { - for (DuringPlace callback : callbacks) - callback.duringPlace(context, state); - }); - - public interface DuringPlace { - void duringPlace(BlockPlaceContext ctx, BlockState state); - } - /** * Invoked after a block is placed, from {@link BlockItem#useOn(UseOnContext)}. Called on both client and server. */ + @Deprecated public static final Event AFTER_PLACE = EventFactory.createArrayBacked(AfterPlace.class, callbacks -> context -> { for (AfterPlace callback : callbacks) callback.afterPlace(context); @@ -86,6 +73,20 @@ public interface AfterPlace { void afterPlace(BlockPlaceContext ctx); } + /** + * Invoked after a block is placed, from the TAIL of {@link BlockItem#place(BlockPlaceContext)}. + * Called on both client and server. + * Provides the block's Position and BlockState as well. + */ + public static final Event POST_PROCESS_PLACE = EventFactory.createArrayBacked(PostProcessPlace.class, callbacks -> (context, blockPos, blockState) -> { + for (PostProcessPlace callback : callbacks) + callback.postProcessPlace(context, blockPos, blockState); + }); + + public interface PostProcessPlace { + void postProcessPlace(BlockPlaceContext ctx, BlockPos blockPos, BlockState blockState); + } + private final LevelAccessor world; private final BlockPos pos; private final BlockState state; diff --git a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java index e00791522..65343c12e 100644 --- a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java +++ b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java @@ -2,11 +2,12 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; import io.github.fabricators_of_create.porting_lib.event.common.BlockEvents; +import net.minecraft.core.BlockPos; + import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; @@ -29,19 +30,6 @@ public abstract class BlockItemMixin implements BlockItemExtensions { cir.setReturnValue(result); } - @WrapOperation( - method = "place", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/item/BlockItem;getPlacementState(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/level/block/state/BlockState;" - ) - ) - private BlockState create$afterPlace(BlockItem instance, BlockPlaceContext context, Operation original) { - BlockState state = original.call(instance, context); - BlockEvents.DURING_PLACE.invoker().duringPlace(context, state); - return state; - } - @ModifyExpressionValue( method = "useOn", at = @At( @@ -54,4 +42,9 @@ public abstract class BlockItemMixin implements BlockItemExtensions { BlockEvents.AFTER_PLACE.invoker().afterPlace(new BlockPlaceContext(context)); return placeResult; } + + @Inject(method = "place", at = @At(value = "TAIL")) + private void port_lib$postProcessPlace(BlockPlaceContext context, CallbackInfoReturnable cir, @Local BlockPos blockPos, @Local BlockState blockState) { + BlockEvents.POST_PROCESS_PLACE.invoker().postProcessPlace(context, blockPos, blockState); + } } From 9f66b8d2677276b80563419b89fb57f028c846e8 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Wed, 21 Feb 2024 16:47:55 -0500 Subject: [PATCH 4/4] fix injection point & add deprecation javadoc --- .../porting_lib/event/common/BlockEvents.java | 1 + .../porting_lib/mixin/common/BlockItemMixin.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java b/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java index d6c6f4739..82335a354 100644 --- a/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java +++ b/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java @@ -62,6 +62,7 @@ public interface BeforePlace { /** * Invoked after a block is placed, from {@link BlockItem#useOn(UseOnContext)}. Called on both client and server. + * @deprecated Use {@link BlockEvents#POST_PROCESS_PLACE} instead. */ @Deprecated public static final Event AFTER_PLACE = EventFactory.createArrayBacked(AfterPlace.class, callbacks -> context -> { diff --git a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java index 65343c12e..21c6ee2ef 100644 --- a/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java +++ b/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java @@ -43,7 +43,7 @@ public abstract class BlockItemMixin implements BlockItemExtensions { return placeResult; } - @Inject(method = "place", at = @At(value = "TAIL")) + @Inject(method = "place", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/InteractionResult;sidedSuccess(Z)Lnet/minecraft/world/InteractionResult;")) private void port_lib$postProcessPlace(BlockPlaceContext context, CallbackInfoReturnable cir, @Local BlockPos blockPos, @Local BlockState blockState) { BlockEvents.POST_PROCESS_PLACE.invoker().postProcessPlace(context, blockPos, blockState); }