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

GTParticle/bloom effect refactor and cleanup #2073

Merged
merged 20 commits into from
Nov 26, 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
8 changes: 5 additions & 3 deletions src/main/java/gregtech/api/block/VariantActiveBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ protected boolean canSilkHarvest() {
return false;
}

@Nonnull
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.CUTOUT;
}

@Override
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) {
public boolean canRenderInLayer(@Nonnull IBlockState state, @Nonnull BlockRenderLayer layer) {
return layer == getRenderLayer() ||
layer == (isBloomEnabled(getState(state)) ? BloomEffectUtil.getRealBloomLayer() : BlockRenderLayer.CUTOUT);
layer == BloomEffectUtil.getEffectiveBloomLayer(isBloomEnabled(getState(state)));
}

@Nonnull
Expand All @@ -123,8 +124,9 @@ protected BlockStateContainer createBlockState() {
return new ExtendedBlockState(this, new IProperty[]{VARIANT, ACTIVE_DEPRECATED}, new IUnlistedProperty[]{ACTIVE});
}

@Nonnull
@Override
public IExtendedBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
public IExtendedBlockState getExtendedState(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos) {
IExtendedBlockState ext = ((IExtendedBlockState) state)
.withProperty(ACTIVE, Minecraft.getMinecraft().world != null &&
isBlockActive(Minecraft.getMinecraft().world.provider.getDimension(), pos));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/cover/Cover.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void renderCover(@NotNull CCRenderState renderState, @NotNull Matrix4 translatio

@SideOnly(Side.CLIENT)
default boolean canRenderInLayer(@NotNull BlockRenderLayer renderLayer) {
return renderLayer == BlockRenderLayer.CUTOUT_MIPPED || renderLayer == BloomEffectUtil.getRealBloomLayer();
return renderLayer == BlockRenderLayer.CUTOUT_MIPPED || renderLayer == BloomEffectUtil.getEffectiveBloomLayer();
}

@SideOnly(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
@SideOnly(Side.CLIENT)
public boolean canRenderInLayer(BlockRenderLayer renderLayer) {
return renderLayer == BlockRenderLayer.CUTOUT_MIPPED ||
renderLayer == BloomEffectUtil.getRealBloomLayer() ||
renderLayer == BloomEffectUtil.getEffectiveBloomLayer() ||
(renderLayer == BlockRenderLayer.TRANSLUCENT && !getWorld().getBlockState(getPos()).getValue(BlockMachine.OPAQUE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,30 +444,28 @@ public void setCustomName(String customName) {
if (!getName().equals(customName)) {
this.customName = customName;
if (world.isRemote) {
if (hasCustomName()) {
if (nameTagParticle == null) {
nameTagParticle = new GTNameTagParticle(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, getName());
nameTagParticle.setOnUpdate(p -> {
if (isInvalid() || !world.isBlockLoaded(pos, false)) {
p.setExpired();
}
});
GTParticleManager.INSTANCE.addEffect(nameTagParticle);
} else {
nameTagParticle.name = getName();
}
} else {
if (nameTagParticle != null) {
nameTagParticle.setExpired();
nameTagParticle = null;
}
}
updateNameTagParticle();
} else {
markAsDirty();
}
}
}

@SideOnly(Side.CLIENT)
private void updateNameTagParticle(){
if (hasCustomName()) {
if (nameTagParticle == null) {
nameTagParticle = new GTNameTagParticle(this, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5);
GTParticleManager.INSTANCE.addEffect(nameTagParticle);
}
} else {
if (nameTagParticle != null) {
nameTagParticle.setExpired();
nameTagParticle = null;
}
}
}

@Nonnull
@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void updateScreenOnFrame() {
public final void maximizeWidget(Consumer<AnimaWidgetGroup> callback) {
this.scale = 0;
setVisible(true);
interpolator = new Interpolator(0, 1, 10, Eases.EaseLinear,
interpolator = new Interpolator(0, 1, 10, Eases.LINEAR,
value-> scale = value.floatValue(),
value-> {
interpolator = null;
Expand All @@ -51,7 +51,7 @@ public final void maximizeWidget(Consumer<AnimaWidgetGroup> callback) {
@SideOnly(Side.CLIENT)
public final void minimizeWidget(Consumer<AnimaWidgetGroup> callback) {
this.scale = 1;
interpolator = new Interpolator(1, 0, 10, Eases.EaseLinear,
interpolator = new Interpolator(1, 0, 10, Eases.LINEAR,
value-> scale = value.floatValue(),
value-> {
setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void removeComponents() {
public void hideMenu() {
if (!isHide && interpolator == null) {
int y = getSelfPosition().y;
interpolator = new Interpolator(getSelfPosition().x, getSelfPosition().x - getSize().width, 6, Eases.EaseLinear,
interpolator = new Interpolator(getSelfPosition().x, getSelfPosition().x - getSize().width, 6, Eases.LINEAR,
value-> setSelfPosition(new Position(value.intValue(), y)),
value-> {
setVisible(false);
Expand All @@ -144,7 +144,7 @@ public void showMenu() {
if (isHide && interpolator == null) {
setVisible(true);
int y = getSelfPosition().y;
interpolator = new Interpolator(getSelfPosition().x, getSelfPosition().x + getSize().width, 6, Eases.EaseLinear,
interpolator = new Interpolator(getSelfPosition().x, getSelfPosition().x + getSize().width, 6, Eases.LINEAR,
value-> setSelfPosition(new Position(value.intValue(), y)),
value-> {
interpolator = null;
Expand Down
59 changes: 41 additions & 18 deletions src/main/java/gregtech/api/util/interpolate/Eases.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
package gregtech.api.util.interpolate;

public enum Eases implements IEase{
EaseLinear(input-> input),
EaseQuadIn(input-> input * input),
EaseQuadInOut(input->{
if((input /= 0.5f) < 1) {
return 0.5f * input * input;
}
return -0.5f * ((--input) * (input - 2) - 1);
}),
EaseQuadOut(input->-input * (input - 2));
import org.jetbrains.annotations.ApiStatus;

public enum Eases implements IEase {
LINEAR {
@Override
public float getInterpolation(float t) {
return t;
}
},
QUAD_IN {
@Override
public float getInterpolation(float t) {
return t * t;
}
},
QUAD_IN_OUT {
@Override
public float getInterpolation(float t) {
if (t <= 0.5f) return 2f * t * t;
t = -2f * t + 2f;
return 1f - t * t * 0.5f;
}
},
QUAD_OUT {
@Override
public float getInterpolation(float t) {
return -t * (t - 2);
}
};

IEase ease;
// Deprecated names below - will be removed on future update

Eases(IEase ease){
this.ease = ease;
}
@Override
public float getInterpolation(float t) {
return ease.getInterpolation(t);
}
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
public static final Eases EaseLinear = LINEAR;
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
public static final Eases EaseQuadIn = QUAD_IN;
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
public static final Eases EaseQuadInOut = QUAD_IN_OUT;
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
public static final Eases EaseQuadOut = QUAD_OUT;
}
12 changes: 12 additions & 0 deletions src/main/java/gregtech/api/util/interpolate/IEase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package gregtech.api.util.interpolate;

/**
* Object representation of an easing function.<p/>
* Easing functions describe numerical change rate of values, on a timescale of {@code 0 ~ 1}.
* @see Eases
*/
@FunctionalInterface
public interface IEase {
/**
* Get change rate of values on specific time {@code t}.
*
* @param t Specific time to sample the rate. Value in a range of {@code 0 ~ 1} is expected.
* @return Numerical value interpolated by the easing function. The returned value has range of {@code 0 ~ 1}.
*/
float getInterpolation(float t);
}
17 changes: 9 additions & 8 deletions src/main/java/gregtech/asm/hooks/CTMHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@ public class CTMHooks {

public static ThreadLocal<Boolean> ENABLE = new ThreadLocal<>();

public static boolean checkLayerWithOptiFine(boolean flag, byte layers, BlockRenderLayer layer) {
public static boolean checkLayerWithOptiFine(boolean canRenderInLayer, byte layers, BlockRenderLayer layer) {
if (Shaders.isOptiFineShaderPackLoaded()) {
if (flag) {
if (layer == BloomEffectUtil.BLOOM) return false;
} else if (((layers >> BloomEffectUtil.BLOOM.ordinal()) & 1) == 1 && layer == BloomEffectUtil.getRealBloomLayer()) {
if (canRenderInLayer) {
if (layer == BloomEffectUtil.getBloomLayer()) return false;
} else if ((layers >> BloomEffectUtil.getBloomLayer().ordinal() & 1) == 1 &&
layer == BloomEffectUtil.getEffectiveBloomLayer()) {
return true;
}
}
return flag;
return canRenderInLayer;
}

public static List<BakedQuad> getQuadsWithOptiFine(List<BakedQuad> ret, BlockRenderLayer layer, IBakedModel bakedModel, IBlockState state, EnumFacing side, long rand) {
if (Shaders.isOptiFineShaderPackLoaded() && CTMHooks.ENABLE.get() == null) {
if (layer == BloomEffectUtil.BLOOM) {
if (layer == BloomEffectUtil.getBloomLayer()) {
return Collections.emptyList();
} else if (layer == BloomEffectUtil.getRealBloomLayer()) {
} else if (layer == BloomEffectUtil.getEffectiveBloomLayer()) {
CTMHooks.ENABLE.set(true);
List<BakedQuad> result = new ArrayList<>(ret);
ForgeHooksClient.setRenderLayer(BloomEffectUtil.BLOOM);
ForgeHooksClient.setRenderLayer(BloomEffectUtil.getBloomLayer());
result.addAll(bakedModel.getQuads(state, side, rand));
ForgeHooksClient.setRenderLayer(layer);
CTMHooks.ENABLE.set(null);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/asm/hooks/CTMModHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public class CTMModHooks {
}

public static boolean canRenderInLayer(IModelCTM model, IBlockState state, BlockRenderLayer layer) {
boolean flag = model.canRenderInLayer(state, layer);
boolean canRenderInLayer = model.canRenderInLayer(state, layer);
if (model instanceof ModelCTM && layers != null) {
try {
return CTMHooks.checkLayerWithOptiFine(flag, layers.getByte(model), layer);
return CTMHooks.checkLayerWithOptiFine(canRenderInLayer, layers.getByte(model), layer);
} catch (Exception ignored) {
layers = null;
GTLog.logger.error("CTMModHooks Field error");
}
}
return flag;
return canRenderInLayer;
}
}
7 changes: 3 additions & 4 deletions src/main/java/gregtech/asm/hooks/LittleTilesHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class BloomLayeredRenderBoxCache extends LayeredRenderBoxCache {
private List<LittleRenderBox> translucent = null;

public List<LittleRenderBox> get(BlockRenderLayer layer) {
if (layer == BloomEffectUtil.BLOOM) {
if (layer == BloomEffectUtil.getBloomLayer()) {
return bloom;
}
switch (layer) {
Expand All @@ -41,7 +41,7 @@ public List<LittleRenderBox> get(BlockRenderLayer layer) {
}

public void set(List<LittleRenderBox> cubes, BlockRenderLayer layer) {
if (layer == BloomEffectUtil.BLOOM) {
if (layer == BloomEffectUtil.getBloomLayer()) {
bloom = cubes;
}
switch (layer) {
Expand Down Expand Up @@ -76,14 +76,13 @@ public void sort() {
if (!OptifineHelper.isActive())
return;

for (Iterator<LittleRenderBox> iterator = solid.iterator(); iterator.hasNext();) {
for (Iterator<LittleRenderBox> iterator = solid.iterator(); iterator.hasNext(); ) {
LittleRenderBox littleRenderingCube = iterator.next();
if (littleRenderingCube.needsResorting) {
cutout_mipped.add(littleRenderingCube);
iterator.remove();
}
}
}

}
}
5 changes: 3 additions & 2 deletions src/main/java/gregtech/client/event/ClientEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@Mod.EventBusSubscriber(Side.CLIENT)
public class ClientEventHandler {

@SuppressWarnings("ConstantValue")
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onDrawBlockHighlight(DrawBlockHighlightEvent event) {
if (event.getTarget().getBlockPos() == null) {
Expand Down Expand Up @@ -83,8 +84,8 @@ public static void onRenderWorldLast(RenderWorldLastEvent event) {
@SubscribeEvent
public static void onRenderGameOverlayPre(RenderGameOverlayEvent.Pre event) {
TerminalARRenderer.renderGameOverlayEvent(event);
if (ConfigHolder.misc.debug && event instanceof RenderGameOverlayEvent.Text) {
GTParticleManager.debugOverlay((RenderGameOverlayEvent.Text) event);
if (ConfigHolder.misc.debug && event instanceof RenderGameOverlayEvent.Text text) {
GTParticleManager.debugOverlay(text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacin
// If bloom is disabled (either by model specific bloom config or the presence of O**ifine shaders)
// it is rendered on CUTOUT layer instead.
if (getBloomConfig()) {
return MinecraftForgeClient.getRenderLayer() == BloomEffectUtil.BLOOM ?
return MinecraftForgeClient.getRenderLayer() == BloomEffectUtil.getBloomLayer() ?
getBloomQuads(m, state, side, rand) :
m.getQuads(state, side, rand);
} else {
if (MinecraftForgeClient.getRenderLayer() == BloomEffectUtil.BLOOM) {
if (MinecraftForgeClient.getRenderLayer() == BloomEffectUtil.getBloomLayer()) {
return Collections.emptyList();
} else if (MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.CUTOUT) {
List<BakedQuad> quads = new ArrayList<>(m.getQuads(state, side, rand));
ForgeHooksClient.setRenderLayer(BloomEffectUtil.BLOOM);
ForgeHooksClient.setRenderLayer(BloomEffectUtil.getBloomLayer());
quads.addAll(getBloomQuads(m, state, side, rand));
ForgeHooksClient.setRenderLayer(BlockRenderLayer.CUTOUT);
return quads;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacin
return quads;
} else if (layer == BlockRenderLayer.CUTOUT_MIPPED) {
return getBaseModel().getQuads(null, side, 0);
} else if (layer == BloomEffectUtil.getRealBloomLayer()) {
} else if (layer == BloomEffectUtil.getEffectiveBloomLayer()) {
return getOverlayQuads(side, rand);
} else {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public IModel getVanillaParent() {
}

public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) {
boolean flag = (layers < 0 && state.getBlock().getRenderLayer() == layer) || ((layers >> layer.ordinal()) & 1) == 1;
return CTMHooks.checkLayerWithOptiFine(flag, layers, layer);
boolean canRenderInLayer = (layers < 0 && state.getBlock().getRenderLayer() == layer) || ((layers >> layer.ordinal()) & 1) == 1;
return CTMHooks.checkLayerWithOptiFine(canRenderInLayer, layers, layer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacin
return getFilteredQuads(true, true, state, side, rand);
} else if (layer == BlockRenderLayer.SOLID) {
return getFilteredQuads(false, true, state, side, rand);
} else if (layer == BloomEffectUtil.BLOOM || layer == BlockRenderLayer.CUTOUT) {
} else if (layer == BloomEffectUtil.getBloomLayer() || layer == BlockRenderLayer.CUTOUT) {
return getFilteredQuads(true, false, state, side, rand);
} else {
return Collections.emptyList();
Expand Down
Loading