Skip to content

Commit b7df822

Browse files
committed
rework customSticky mixin
1 parent 6c60782 commit b7df822

File tree

9 files changed

+56
-40
lines changed

9 files changed

+56
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
## Changelog
2-
- fix `releaseTarget`
2+
- rework `customSticky` mixin

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ loom.platform = neoforge
1010

1111
# Mod Properties
1212
upstream_version = 1.4.147
13-
mod_version = 0.1.4
13+
mod_version = 0.1.5
1414
maven_group = org.thinkingstudio.bedsheet
1515
archives_base_name = bedsheet
1616

src/main/java/carpet/mixins/PieceGeneratorSupplier_plopMixin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
@Mixin(PieceGeneratorSupplier.class)
1212
public interface PieceGeneratorSupplier_plopMixin
1313
{
14-
@Redirect(method = "method_39845", at = @At(
14+
// method_39845 is intermediary name
15+
// lambda$simple$0 is mojmap name
16+
// NeoForge NOT HAVE intermediary name!
17+
@Redirect(method = {"method_39845", "lambda$simple$0"}, at = @At(
1518
value = "INVOKE",
1619
target = "java/util/function/Predicate.test(Ljava/lang/Object;)Z"
1720
), remap = false)

src/main/java/carpet/mixins/PistonStructureResolver_customStickyMixin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
import net.minecraft.world.level.Level;
1818
import net.minecraft.world.level.block.piston.PistonStructureResolver;
1919
import net.minecraft.world.level.block.state.BlockState;
20-
import org.thinkingstudio.bedsheet.util.PistonStructureResolverHooks;
2120

2221
@Mixin(PistonStructureResolver.class)
2322
public class PistonStructureResolver_customStickyMixin {
2423

2524
@Shadow @Final private Level level;
2625
@Shadow @Final private Direction pushDirection;
2726

28-
// NeoForge patched, see PistonStructureResolverHelper
27+
// NeoForge patched, use state.canStickTo(BlockState)
2928
// @Shadow private static boolean canStickToEachOther(BlockState blockState, BlockState blockState2) {
3029
// throw new AssertionError();
3130
// }
3231
//
32+
// NeoForge patched, inject IBlockExtension.isStickyBlock(BlockState)
3333
// @Inject(
3434
// method = "isSticky",
3535
// cancellable = true,
@@ -73,7 +73,7 @@ private boolean onAddBlockLineCanStickToEachOther(BlockState state, BlockState b
7373
return behaviourInterface.isStickyToNeighbor(level, pos_addBlockLine, state, behindPos_addBlockLine, behindState, pushDirection.getOpposite(), pushDirection);
7474
}
7575

76-
return PistonStructureResolverHooks.isAdjacentBlockStuck(state, behindState);
76+
return state.canStickTo(behindState);
7777
}
7878

7979
// fields that are needed because @Redirects cannot capture locals
@@ -106,6 +106,6 @@ private boolean onAddBranchingBlocksCanStickToEachOther(BlockState neighborState
106106
return behaviourInterface.isStickyToNeighbor(level, pos, state, neighborPos_addBranchingBlocks, neighborState, dir_addBranchingBlocks, pushDirection);
107107
}
108108

109-
return PistonStructureResolverHooks.isAdjacentBlockStuck(neighborState, state);
109+
return neighborState.canStickTo(state);
110110
}
111111
}

src/main/java/carpet/mixins/ReloadCommand_reloadAppsMixin.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111

1212
@Mixin(ReloadCommand.class)
1313
public class ReloadCommand_reloadAppsMixin {
14-
// method_13530(Lcom/mojang/brigadier/context/CommandContext;)I = lambda$register$3(Lcom/mojang/brigadier/context/CommandContext;)I
14+
// method_13530(Lcom/mojang/brigadier/context/CommandContext;)I
1515
// internal of register.
16-
// dev & compile use intermediary name, runtime use mojmap name
17-
@Inject(method = {
18-
"method_13530(Lcom/mojang/brigadier/context/CommandContext;)I", // dev & compile
19-
"lambda$register$3(Lcom/mojang/brigadier/context/CommandContext;)I" // runtime
20-
}, at = @At("TAIL"), remap = false)
16+
// method_13530 is intermediary name
17+
// lambda$register$3 is mojmap name
18+
// NeoForge NOT HAVE intermediary name!
19+
@Inject(method = {"method_13530", "lambda$register$3"}, at = @At("TAIL"), remap = false)
2120
private static void onReload(CommandContext<CommandSourceStack> context, CallbackInfoReturnable<Integer> cir)
2221
{
2322
// can't fetch here the reference to the server
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.thinkingstudio.bedsheet.mixins;
2+
3+
import carpet.fakes.BlockPistonBehaviourInterface;
4+
import net.minecraft.world.level.block.state.BlockState;
5+
import net.neoforged.neoforge.common.extensions.IBlockExtension;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10+
11+
@Mixin(IBlockExtension.class)
12+
public interface IBlockExtensionMixin {
13+
@Inject(
14+
method = "isStickyBlock",
15+
cancellable = true,
16+
at = @At(
17+
value = "HEAD"
18+
)
19+
)
20+
private void isSticky(BlockState state, CallbackInfoReturnable<Boolean> cir) {
21+
if (state.getBlock() instanceof BlockPistonBehaviourInterface behaviourInterface){
22+
cir.setReturnValue(behaviourInterface.isSticky(state));
23+
}
24+
}
25+
}

src/main/java/org/thinkingstudio/bedsheet/util/PistonStructureResolverHooks.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/resources/META-INF/neoforge.mods.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ description = '''
1414
Carpet unofficial NeoForge port.
1515
'''
1616
logoFile = "icon.png"
17+
displayTest = "IGNORE_SERVER_VERSION"
1718

1819
[[dependencies.bedsheet]]
1920
modId = "neoforge"
@@ -30,4 +31,7 @@ ordering = "NONE"
3031
side = "BOTH"
3132

3233
[[mixins]]
33-
config = "carpet.mixins.json"
34+
config = "carpet.mixins.json"
35+
36+
[[mixins]]
37+
config = "bedsheet.mixins.json"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"required": true,
3+
"package": "org.thinkingstudio.bedsheet.mixins",
4+
"compatibilityLevel": "JAVA_21",
5+
"mixins": [
6+
"IBlockExtensionMixin"
7+
],
8+
"injectors": {
9+
"defaultRequire": 1
10+
}
11+
}

0 commit comments

Comments
 (0)