Skip to content

Commit

Permalink
Tweak muffler effect API (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Dec 17, 2023
1 parent 025d469 commit d2d4420
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
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
63 changes: 32 additions & 31 deletions src/main/java/gregtech/client/particle/VanillaParticleEffects.java
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

0 comments on commit d2d4420

Please sign in to comment.