Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

import appeng.api.AECapabilities;
import appeng.api.networking.IInWorldGridNodeHost;
import dev.ryanhcode.sable.companion.SableCompanion;
import dev.ryanhcode.sable.companion.SubLevelAccess;
import lombok.Getter;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -162,6 +164,11 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
}

Vec3 pos = player.position();

if (GTCEu.Mods.isSableLoaded()) {
pos = SableUtils.transformIntoSubLevel(pos, player.level(), blockPos);
}

if (Math.abs(pos.x - (double) ((float) blockPos.getX() + 0.5F)) < 2.0D &&
Math.abs(pos.z - (double) ((float) blockPos.getZ() + 0.5F)) < 2.0D) {
double d0 = pos.y + (double) player.getEyeHeight();
Expand Down Expand Up @@ -584,4 +591,15 @@ public static int colorTinted(BlockState blockState, @Nullable BlockAndTintGette
public final BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return getDefinition().getBlockEntityType().create(pos, state);
}

private static class SableUtils {

public static Vec3 transformIntoSubLevel(Vec3 pos, Level level, BlockPos blockPos) {
// transform the players "global" position into the sublevel plot's local space for the distance checks
SubLevelAccess subLevel = SableCompanion.INSTANCE.getContaining(level, blockPos);
if (subLevel != null) return subLevel.logicalPose().transformPositionInverse(pos);

return pos;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.common.machine.multiblock.part;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.blockentity.BlockEntityCreationInfo;
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
Expand All @@ -21,6 +22,7 @@
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.items.ItemHandlerHelper;
Expand All @@ -29,9 +31,13 @@
import brachy.modularui.screen.UISettings;
import brachy.modularui.value.sync.PanelSyncManager;
import brachy.modularui.widget.ParentWidget;
import dev.ryanhcode.sable.companion.ClientSubLevelAccess;
import dev.ryanhcode.sable.companion.SableCompanion;
import dev.ryanhcode.sable.companion.math.JOMLConversion;
import lombok.Getter;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3d;

import java.util.stream.IntStream;

Expand Down Expand Up @@ -146,6 +152,8 @@ public boolean isFrontFaceFree() {
public void emitPollutionParticles() {
var pos = getBlockPos();
var facing = getFrontFacing();
Vector3d normal = new Vector3d(
facing.getStepX(), facing.getStepY(), facing.getStepZ());

IHazardParticleContainer container = GTCapabilityHelper.getHazardContainer(getLevel(),
pos.relative(facing), facing.getOpposite());
Expand All @@ -155,14 +163,19 @@ public void emitPollutionParticles() {
}

var center = pos.getCenter();

if (GTCEu.Mods.isSableLoaded()) {
center = SableUtils.transformPositionAndNormal(center, normal);
}

var offset = .75f;
var xPos = (float) (center.x + facing.getStepX() * offset + (GTValues.RNG.nextFloat() - .5f) * .35f);
var yPos = (float) (center.y + facing.getStepY() * offset + (GTValues.RNG.nextFloat() - .5f) * .35f);
var zPos = (float) (center.z + facing.getStepZ() * offset + (GTValues.RNG.nextFloat() - .5f) * .35f);
var xPos = (float) (center.x + normal.x * offset + (GTValues.RNG.nextFloat() - .5f) * .35f);
var yPos = (float) (center.y + normal.y * offset + (GTValues.RNG.nextFloat() - .5f) * .35f);
var zPos = (float) (center.z + normal.z * offset + (GTValues.RNG.nextFloat() - .5f) * .35f);

var ySpd = facing.getStepY() + (GTValues.RNG.nextFloat() - .15f) * .5f;
var xSpd = facing.getStepX() + (GTValues.RNG.nextFloat() - .5f) * .5f;
var zSpd = facing.getStepZ() + (GTValues.RNG.nextFloat() - .5f) * .5f;
var ySpd = normal.y + (GTValues.RNG.nextFloat() - .15f) * .5f;
var xSpd = normal.x + (GTValues.RNG.nextFloat() - .5f) * .5f;
var zSpd = normal.z + (GTValues.RNG.nextFloat() - .5f) * .5f;

getLevel().addParticle(GTParticleTypes.MUFFLER_PARTICLE.get(),
xPos, yPos, zPos, xSpd, ySpd, zSpd);
Expand All @@ -179,4 +192,18 @@ public void buildMainUI(ParentWidget<?> mainWidget, PosGuiData guiData, PanelSyn
.child(createSquareSlotGroupFromInventory(inventory, "muffler_inventory", syncManager).margin(10)
.center());
}

private static class SableUtils {

public static Vec3 transformPositionAndNormal(Vec3 pos, Vector3d normal) {
ClientSubLevelAccess clientSubLevelAccess = SableCompanion.INSTANCE.getContainingClient(pos);
if (clientSubLevelAccess != null) {
// if in a sublevel, we should transform our center and normal to match the sublevel's pose
clientSubLevelAccess.renderPose().transformNormal(normal);
return JOMLConversion
.toMojang(clientSubLevelAccess.renderPose().transformPosition(JOMLConversion.toJOML(pos)));
}
return pos;
}
}
}
Loading