Skip to content

Commit

Permalink
Remove fusion ring effect on structure invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tictim authored and serenibyss committed Dec 3, 2023
1 parent 437e512 commit 40fa47d
Showing 1 changed file with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.DoubleSupplier;

public class MetaTileEntityFusionReactor extends RecipeMapMultiblockController
implements IFastRenderMetaTileEntity, IBloomEffect {

protected static final int NO_COLOR = 0;

private final int tier;
private EnergyContainerList inputEnergyContainers;
private long heat = 0; // defined in TileEntityFusionReactor but serialized in FusionRecipeLogic
@Nullable
private Integer color;
private int fusionRingColor = NO_COLOR;
private final FusionProgressSupplier progressBarSupplier;

@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -227,6 +227,21 @@ private IBlockState getCoilState() {
return MetaBlocks.FUSION_CASING.getState(BlockFusionCasing.CasingType.FUSION_COIL);
}

protected int getFusionRingColor() {
return this.fusionRingColor;
}

protected boolean hasFusionRingColor() {
return this.fusionRingColor != NO_COLOR;
}

protected void setFusionRingColor(int fusionRingColor) {
if (this.fusionRingColor != fusionRingColor) {
this.fusionRingColor = fusionRingColor;
writeCustomData(GregtechDataCodes.UPDATE_COLOR, buf -> buf.writeVarInt(fusionRingColor));
}
}

@Override
protected void formStructure(PatternMatchContext context) {
long energyStored = this.energyContainer.getEnergyStored();
Expand All @@ -248,6 +263,7 @@ public String getName() {
};
this.inputEnergyContainers = new EnergyContainerList(Lists.newArrayList());
this.heat = 0;
this.setFusionRingColor(NO_COLOR);
}

@Override
Expand Down Expand Up @@ -280,50 +296,35 @@ protected void updateFormedValid() {
if (energyAdded > 0) this.inputEnergyContainers.removeEnergy(energyAdded);
}
super.updateFormedValid();
if (recipeMapWorkable.isWorking() && color == null) {
if (recipeMapWorkable.isWorking() && fusionRingColor == NO_COLOR) {
if (recipeMapWorkable.getPreviousRecipe() != null &&
!recipeMapWorkable.getPreviousRecipe().getFluidOutputs().isEmpty()) {
int newColor = 0xFF000000 |
recipeMapWorkable.getPreviousRecipe().getFluidOutputs().get(0).getFluid().getColor();
if (!Objects.equals(color, newColor)) {
color = newColor;
writeCustomData(GregtechDataCodes.UPDATE_COLOR, this::writeColor);
}
setFusionRingColor(0xFF000000 |
recipeMapWorkable.getPreviousRecipe().getFluidOutputs().get(0).getFluid().getColor());
}
} else if (!recipeMapWorkable.isWorking() && isStructureFormed() && color != null) {
color = null;
writeCustomData(GregtechDataCodes.UPDATE_COLOR, this::writeColor);
} else if (!recipeMapWorkable.isWorking() && isStructureFormed()) {
setFusionRingColor(NO_COLOR);
}
}

@Override
public void writeInitialSyncData(PacketBuffer buf) {
super.writeInitialSyncData(buf);
writeColor(buf);
buf.writeVarInt(this.fusionRingColor);
}

@Override
public void receiveInitialSyncData(PacketBuffer buf) {
super.receiveInitialSyncData(buf);
readColor(buf);
this.fusionRingColor = buf.readVarInt();
}

@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
super.receiveCustomData(dataId, buf);
if (dataId == GregtechDataCodes.UPDATE_COLOR) {
readColor(buf);
}
}

private void readColor(PacketBuffer buf) {
color = buf.readBoolean() ? buf.readVarInt() : null;
}

private void writeColor(PacketBuffer buf) {
buf.writeBoolean(color != null);
if (color != null) {
buf.writeVarInt(color);
this.fusionRingColor = buf.readVarInt();
} else {
super.receiveCustomData(dataId, buf);
}
}

Expand Down Expand Up @@ -655,7 +656,7 @@ protected void setActive(boolean active) {
@Override
@SideOnly(Side.CLIENT)
public void renderMetaTileEntity(double x, double y, double z, float partialTicks) {
if (this.color != null && !this.registeredBloomRenderTicket) {
if (this.hasFusionRingColor() && !this.registeredBloomRenderTicket) {
this.registeredBloomRenderTicket = true;
BloomEffectUtil.registerBloomRender(FusionBloomSetup.INSTANCE, getBloomType(), this, this);
}
Expand All @@ -664,9 +665,8 @@ public void renderMetaTileEntity(double x, double y, double z, float partialTick
@Override
@SideOnly(Side.CLIENT)
public void renderBloomEffect(@NotNull BufferBuilder buffer, @NotNull EffectRenderContext context) {
Integer c = color;
if (c == null) return;
int color = RenderUtil.interpolateColor(c, -1, Eases.QUAD_IN.getInterpolation(
if (!this.hasFusionRingColor()) return;
int color = RenderUtil.interpolateColor(this.getFusionRingColor(), -1, Eases.QUAD_IN.getInterpolation(
Math.abs((Math.abs(getOffsetTimer() % 50) + context.partialTicks()) - 25) / 25));
float a = (float) (color >> 24 & 255) / 255.0F;
float r = (float) (color >> 16 & 255) / 255.0F;
Expand All @@ -688,7 +688,7 @@ public void renderBloomEffect(@NotNull BufferBuilder buffer, @NotNull EffectRend
@Override
@SideOnly(Side.CLIENT)
public boolean shouldRenderBloomEffect(@NotNull EffectRenderContext context) {
return this.color != null;
return this.hasFusionRingColor();
}

@Override
Expand Down

0 comments on commit 40fa47d

Please sign in to comment.