Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak muffler effect API #2286

Merged
merged 2 commits into from
Dec 16, 2023
Merged
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 @@ -275,7 +275,7 @@ public boolean isMufflerFaceFree() {
}

/**
* @deprecated Use {@link gregtech.client.particle.VanillaParticleEffects#MUFFLER_SMOKE} instead.
* @deprecated Override {@link #getMufflerParticle()} instead.
*/
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
@Deprecated
Expand All @@ -284,6 +284,11 @@ public void runMufflerEffect(float xPos, float yPos, float zPos, float xSpd, flo
getWorld().spawnParticle(EnumParticleTypes.SMOKE_LARGE, xPos, yPos, zPos, xSpd, ySpd, zSpd);
}

@SideOnly(Side.CLIENT)
public @NotNull EnumParticleTypes getMufflerParticle() {
return EnumParticleTypes.SMOKE_LARGE;
}

/**
* Sets the recovery items of this multiblock
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@ public enum VanillaParticleEffects implements IMachineParticleEffect {
mte.getWorld().spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x, y, z, 0, 0, 0);
}),

MUFFLER_SMOKE(mte -> {
if (mte.getWorld() == null || mte.getPos() == null) return;

BlockPos pos = mte.getPos();
EnumFacing facing = mte.getFrontFacing();
float xPos = facing.getXOffset() * 0.76F + pos.getX() + 0.25F;
float yPos = facing.getYOffset() * 0.76F + pos.getY() + 0.25F;
float zPos = facing.getZOffset() * 0.76F + pos.getZ() + 0.25F;

float ySpd = facing.getYOffset() * 0.1F + 0.2F + 0.1F * GTValues.RNG.nextFloat();
float xSpd;
float zSpd;

if (facing.getYOffset() == -1) {
float temp = GTValues.RNG.nextFloat() * 2 * (float) Math.PI;
xSpd = (float) Math.sin(temp) * 0.1F;
zSpd = (float) Math.cos(temp) * 0.1F;
} else {
xSpd = facing.getXOffset() * (0.1F + 0.2F * GTValues.RNG.nextFloat());
zSpd = facing.getZOffset() * (0.1F + 0.2F * GTValues.RNG.nextFloat());
}

xPos += GTValues.RNG.nextFloat() * 0.5F;
yPos += GTValues.RNG.nextFloat() * 0.5F;
zPos += GTValues.RNG.nextFloat() * 0.5F;

mte.getWorld().spawnParticle(EnumParticleTypes.SMOKE_LARGE, xPos, yPos, zPos, xSpd, ySpd, zSpd);
}),

PBF_SMOKE(mte -> {
if (mte.getWorld() == null || mte.getPos() == null) return;

Expand Down Expand Up @@ -167,12 +138,12 @@ public void runEffect(@NotNull MetaTileEntity metaTileEntity) {
}

@SideOnly(Side.CLIENT)
public static void defaultFrontEffect(MetaTileEntity mte, EnumParticleTypes... particles) {
public static void defaultFrontEffect(@NotNull MetaTileEntity mte, EnumParticleTypes... particles) {
defaultFrontEffect(mte, 0.0F, particles);
}

@SideOnly(Side.CLIENT)
public static void defaultFrontEffect(MetaTileEntity mte, float yOffset, EnumParticleTypes... particles) {
public static void defaultFrontEffect(@NotNull MetaTileEntity mte, float yOffset, EnumParticleTypes... particles) {
if (particles == null || particles.length == 0) return;
if (mte.getWorld() == null || mte.getPos() == null) return;

Expand Down Expand Up @@ -201,4 +172,34 @@ public static void defaultFrontEffect(MetaTileEntity mte, float yOffset, EnumPar
mte.getWorld().spawnParticle(particle, x, y, z, 0, 0, 0);
}
}

@SideOnly(Side.CLIENT)
public static void mufflerEffect(@NotNull MetaTileEntity mte, @NotNull EnumParticleTypes particle) {
if (mte.getWorld() == null || mte.getPos() == null) return;

BlockPos pos = mte.getPos();
EnumFacing facing = mte.getFrontFacing();
float xPos = facing.getXOffset() * 0.76F + pos.getX() + 0.25F;
float yPos = facing.getYOffset() * 0.76F + pos.getY() + 0.25F;
float zPos = facing.getZOffset() * 0.76F + pos.getZ() + 0.25F;

float ySpd = facing.getYOffset() * 0.1F + 0.2F + 0.1F * GTValues.RNG.nextFloat();
float xSpd;
float zSpd;

if (facing.getYOffset() == -1) {
float temp = GTValues.RNG.nextFloat() * 2 * (float) Math.PI;
xSpd = (float) Math.sin(temp) * 0.1F;
zSpd = (float) Math.cos(temp) * 0.1F;
} else {
xSpd = facing.getXOffset() * (0.1F + 0.2F * GTValues.RNG.nextFloat());
zSpd = facing.getZOffset() * (0.1F + 0.2F * GTValues.RNG.nextFloat());
}

xPos += GTValues.RNG.nextFloat() * 0.5F;
yPos += GTValues.RNG.nextFloat() * 0.5F;
zPos += GTValues.RNG.nextFloat() * 0.5F;

mte.getWorld().spawnParticle(particle, xPos, yPos, zPos, xSpd, ySpd, zSpd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase;
import gregtech.api.util.GTTransferUtils;
import gregtech.api.util.GTUtility;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void update() {

if (getWorld().isRemote && getController() instanceof MultiblockWithDisplayBase controller &&
controller.isActive()) {
VanillaParticleEffects.MUFFLER_SMOKE.runEffect(this);
VanillaParticleEffects.mufflerEffect(this, controller.getMufflerParticle());
}
}

Expand Down Expand Up @@ -112,12 +113,15 @@ private boolean checkFrontFaceFree() {
return blockState.getBlock().isAir(blockState, getWorld(), frontPos) || GTUtility.isBlockSnow(blockState);
}

/** @deprecated Use {@link VanillaParticleEffects#MUFFLER_SMOKE} instead. */
/** @deprecated No longer needed. Multiblock controller sets the particle type. */
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
@SideOnly(Side.CLIENT)
public void pollutionParticles() {
VanillaParticleEffects.MUFFLER_SMOKE.runEffect(this);
MultiblockControllerBase controller = getController();
if (controller instanceof MultiblockWithDisplayBase displayBase) {
VanillaParticleEffects.mufflerEffect(this, displayBase.getMufflerParticle());
}
}

@Override
Expand Down