Skip to content

Commit 6d2d7d0

Browse files
authored
Merge pull request #203 from Frontiers-PackForge/main-1.21.X-Neoforged
Because Apparently I've been working on two NF branches
2 parents a0a6dfb + 1e3b771 commit 6d2d7d0

5 files changed

Lines changed: 138 additions & 2 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.ghostipedia.cosmiccore.integration.sable;
2+
3+
import net.minecraft.world.level.block.Rotation;
4+
5+
public final class SableAssemblyRotationHolder {
6+
7+
private static final ThreadLocal<Rotation> CURRENT = new ThreadLocal<>();
8+
9+
private SableAssemblyRotationHolder() {}
10+
11+
public static void set(Rotation rotation) {
12+
CURRENT.set(rotation);
13+
}
14+
15+
public static void clear() {
16+
CURRENT.remove();
17+
}
18+
19+
public static Rotation current() {
20+
Rotation rotation = CURRENT.get();
21+
return rotation == null ? Rotation.NONE : rotation;
22+
}
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.ghostipedia.cosmiccore.mixin.sable;
2+
3+
import com.gregtechceu.gtceu.client.ClientEventListener;
4+
import com.gregtechceu.gtceu.client.renderer.BlockHighlightRenderer;
5+
6+
import net.minecraft.client.Minecraft;
7+
import net.minecraft.core.Vec3i;
8+
import net.minecraft.world.level.Level;
9+
import net.minecraft.world.phys.BlockHitResult;
10+
import net.minecraft.world.phys.HitResult;
11+
import net.neoforged.neoforge.client.event.RenderHighlightEvent;
12+
13+
import dev.ryanhcode.sable.Sable;
14+
import dev.ryanhcode.sable.mixinhelpers.block_outline_render.SubLevelCamera;
15+
import dev.ryanhcode.sable.sublevel.ClientSubLevel;
16+
import org.spongepowered.asm.mixin.Mixin;
17+
import org.spongepowered.asm.mixin.injection.At;
18+
import org.spongepowered.asm.mixin.injection.Inject;
19+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
20+
21+
@Mixin(value = ClientEventListener.class, remap = false)
22+
public abstract class BlockHighlightSubLevelMixin {
23+
24+
@Inject(method = "onBlockHighlightEvent", at = @At("HEAD"), cancellable = true)
25+
private static void cosmiccore$transformSubLevelOverlay(RenderHighlightEvent.Block event, CallbackInfo ci) {
26+
HitResult target = event.getTarget();
27+
if (!(target instanceof BlockHitResult blockTarget)) {
28+
return;
29+
}
30+
Level level = Minecraft.getInstance().level;
31+
if (level == null) {
32+
return;
33+
}
34+
ClientSubLevel subLevel = (ClientSubLevel) Sable.HELPER.getContaining(level, (Vec3i) blockTarget.getBlockPos());
35+
if (subLevel == null) {
36+
return;
37+
}
38+
SubLevelCamera subLevelCamera = new SubLevelCamera();
39+
subLevelCamera.setCamera(Minecraft.getInstance().gameRenderer.getMainCamera());
40+
subLevelCamera.setPose(subLevel.renderPose());
41+
BlockHighlightRenderer.renderBlockHighlight(event.getPoseStack(), subLevelCamera, blockTarget,
42+
event.getMultiBufferSource(), event.getDeltaTracker().getGameTimeDeltaPartialTick(false));
43+
ci.cancel();
44+
}
45+
}

src/main/java/com/ghostipedia/cosmiccore/mixin/sable/PipeBlockSubLevelMixin.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package com.ghostipedia.cosmiccore.mixin.sable;
22

3+
import com.ghostipedia.cosmiccore.integration.sable.SableAssemblyRotationHolder;
4+
35
import com.gregtechceu.gtceu.api.block.PipeBlock;
46
import com.gregtechceu.gtceu.api.blockentity.PipeBlockEntity;
57
import com.gregtechceu.gtceu.api.pipenet.LevelPipeNet;
68

79
import net.minecraft.core.BlockPos;
10+
import net.minecraft.core.Direction;
811
import net.minecraft.server.level.ServerLevel;
912
import net.minecraft.util.RandomSource;
13+
import net.minecraft.world.level.block.Rotation;
1014
import net.minecraft.world.level.block.state.BlockState;
1115

1216
import dev.ryanhcode.sable.api.block.BlockSubLevelAssemblyListener;
1317
import org.spongepowered.asm.mixin.Mixin;
1418
import org.spongepowered.asm.mixin.Shadow;
19+
import org.spongepowered.asm.mixin.Unique;
1520

1621
@Mixin(value = PipeBlock.class, remap = false)
1722
public abstract class PipeBlockSubLevelMixin implements BlockSubLevelAssemblyListener {
@@ -29,8 +34,36 @@ public void afterMove(ServerLevel originLevel, ServerLevel resultingLevel, Block
2934
tick(state, resultingLevel, newPos, resultingLevel.getRandom());
3035
}
3136
if (resultingLevel.getBlockEntity(newPos) instanceof PipeBlockEntity<?, ?> pipe) {
37+
cosmiccore$rotateConnections(pipe);
3238
pipe.getSyncDataHolder().resyncAllFields();
3339
pipe.scheduleRenderUpdate();
3440
}
3541
}
42+
43+
@Unique
44+
private static void cosmiccore$rotateConnections(PipeBlockEntity<?, ?> pipe) {
45+
Rotation rotation = SableAssemblyRotationHolder.current();
46+
if (rotation == Rotation.NONE) {
47+
return;
48+
}
49+
int connections = cosmiccore$rotateMask(pipe.getConnections(), rotation);
50+
if (connections != pipe.getConnections()) {
51+
pipe.setConnections(connections);
52+
}
53+
int blocked = cosmiccore$rotateMask(pipe.getBlockedConnections(), rotation);
54+
if (blocked != pipe.getBlockedConnections()) {
55+
pipe.setBlockedConnections(blocked);
56+
}
57+
}
58+
59+
@Unique
60+
private static int cosmiccore$rotateMask(int mask, Rotation rotation) {
61+
int result = 0;
62+
for (Direction dir : Direction.values()) {
63+
if (PipeBlockEntity.isConnected(mask, dir)) {
64+
result |= 1 << rotation.rotate(dir).ordinal();
65+
}
66+
}
67+
return result;
68+
}
3669
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.ghostipedia.cosmiccore.mixin.sable;
2+
3+
import com.ghostipedia.cosmiccore.integration.sable.SableAssemblyRotationHolder;
4+
5+
import net.minecraft.core.BlockPos;
6+
import net.minecraft.server.level.ServerLevel;
7+
8+
import dev.ryanhcode.sable.api.SubLevelAssemblyHelper;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(value = SubLevelAssemblyHelper.class, remap = false)
15+
public abstract class SubLevelAssemblyHelperRotationCaptureMixin {
16+
17+
@Inject(
18+
method = "moveBlocks(Lnet/minecraft/server/level/ServerLevel;Ldev/ryanhcode/sable/api/SubLevelAssemblyHelper$AssemblyTransform;Ljava/lang/Iterable;)V",
19+
at = @At("HEAD"))
20+
private static void cosmiccore$captureRotation(ServerLevel level,
21+
SubLevelAssemblyHelper.AssemblyTransform transform,
22+
Iterable<BlockPos> positions, CallbackInfo ci) {
23+
SableAssemblyRotationHolder.set(transform.getRotation());
24+
}
25+
26+
@Inject(
27+
method = "moveBlocks(Lnet/minecraft/server/level/ServerLevel;Ldev/ryanhcode/sable/api/SubLevelAssemblyHelper$AssemblyTransform;Ljava/lang/Iterable;)V",
28+
at = @At("RETURN"))
29+
private static void cosmiccore$clearRotation(ServerLevel level, SubLevelAssemblyHelper.AssemblyTransform transform,
30+
Iterable<BlockPos> positions, CallbackInfo ci) {
31+
SableAssemblyRotationHolder.clear();
32+
}
33+
}

src/main/resources/cosmiccore.mixins.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"gtfix.QuantumChestUpwardFacingCrashFixMixin",
4949
"gtfix.SchemaWidgetZoomMixin",
5050
"gtfix.SchemaWidgetPanMixin",
51-
"gtfix.DummyChunkSourceThreadSafeMixin"
51+
"gtfix.DummyChunkSourceThreadSafeMixin",
52+
"sable.BlockHighlightSubLevelMixin"
5253
],
5354
"mixins": [
5455
"BlockPatternMixin",
@@ -89,7 +90,8 @@
8990
"worldgen.CubicSplineMultipointMixin",
9091
"sable.PipeBlockSubLevelMixin",
9192
"sable.MachineUIFactorySubLevelRangeMixin",
92-
"sable.MetaMachineBlockSubLevelMixin"
93+
"sable.MetaMachineBlockSubLevelMixin",
94+
"sable.SubLevelAssemblyHelperRotationCaptureMixin"
9395
],
9496
"injectors": {
9597
"defaultRequire": 1,

0 commit comments

Comments
 (0)