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

Dynamic heating coils #3951

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5da02d0
Dynamic heating coil textures
RecursivePineapple Feb 14, 2025
118b9dd
spotless
RecursivePineapple Feb 14, 2025
3da0279
Merge branch 'master' into fancy-coils
RecursivePineapple Feb 14, 2025
7ec4d6a
Simplify shader material system
RecursivePineapple Feb 15, 2025
286b7d7
Cleanup
RecursivePineapple Feb 18, 2025
aed5dc9
Fix lease double-frees
RecursivePineapple Feb 18, 2025
8206895
Add activeCoils() to all multis
RecursivePineapple Feb 18, 2025
ba80d44
Make trinium less eye-searing
RecursivePineapple Feb 18, 2025
169c5f5
temp deps
RecursivePineapple Feb 18, 2025
a986c88
Disable iris interop temporarily
RecursivePineapple Feb 21, 2025
2546fa1
spotless
RecursivePineapple Feb 21, 2025
f653127
Revert temp deps
RecursivePineapple Feb 21, 2025
50792ef
Merge branch 'master' into fancy-coils
RecursivePineapple Feb 21, 2025
f4c92d2
Remove mavenLocal()
RecursivePineapple Feb 21, 2025
720a87b
Merge branch 'master' into fancy-coils
Dream-Master Feb 22, 2025
9f53ab4
Merge branch 'master' into fancy-coils
Dream-Master Feb 27, 2025
44c5345
Merge branch 'master' into fancy-coils
Dream-Master Mar 2, 2025
02107af
Fix multi smelter & LCR
RecursivePineapple Mar 4, 2025
e256e72
Merge branch 'master' into fancy-coils
RecursivePineapple Mar 5, 2025
988aed2
Fix desync issues when powerfailing
RecursivePineapple Mar 5, 2025
132b4a3
Fix coil autoplace
RecursivePineapple Mar 5, 2025
860407e
Merge branch 'master' into fancy-coils
Dream-Master Mar 7, 2025
4df60fa
Merge branch 'master' into fancy-coils
Dream-Master Mar 9, 2025
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 @@ -21,6 +21,7 @@
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
import static gregtech.api.util.GTStructureUtility.activeCoils;
import static gregtech.api.util.GTStructureUtility.buildHatchAdder;
import static gregtech.api.util.GTStructureUtility.ofCoil;

Expand Down Expand Up @@ -82,7 +83,9 @@ public class MTEMegaBlastFurnace extends MegaMultiBlockBase<MTEMegaBlastFurnace>
.addElement('m', Muffler.newAny(CASING_INDEX, 2))
.addElement(
'C',
withChannel("coil", ofCoil(MTEMegaBlastFurnace::setCoilLevel, MTEMegaBlastFurnace::getCoilLevel)))
withChannel(
"coil",
activeCoils(ofCoil(MTEMegaBlastFurnace::setCoilLevel, MTEMegaBlastFurnace::getCoilLevel))))
.addElement(
'g',
withChannel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
import static gregtech.api.util.GTStructureUtility.activeCoils;
import static gregtech.api.util.GTStructureUtility.buildHatchAdder;
import static gregtech.api.util.GTStructureUtility.ofCoil;
import static gregtech.api.util.GTUtility.validMTEList;
Expand Down Expand Up @@ -94,7 +95,9 @@ public class MTEMegaOilCracker extends MegaMultiBlockBase<MTEMegaOilCracker> imp
" g c c c c g ", " g c c c c g ", "pgggggggggggp", " p p " },
{ "ppmmmm~mmmmpp", "ppppppppppppp", "ppppppppppppp", "ppppppppppppp", "ppppppppppppp",
"ppppppppppppp", "ppppppppppppp", "ppppppppppppp", "ppmmmmmmmmmpp" }, }))
.addElement('c', withChannel("coil", ofCoil(MTEMegaOilCracker::setCoilLevel, MTEMegaOilCracker::getCoilLevel)))
.addElement(
'c',
withChannel("coil", activeCoils(ofCoil(MTEMegaOilCracker::setCoilLevel, MTEMegaOilCracker::getCoilLevel))))

.addElement('p', ofBlock(GregTechAPI.sBlockCasings4, 1))
.addElement(
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/enums/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum Mods {
AdvancedSolarPanel(Names.ADVANCED_SOLAR_PANEL),
AdventureBackpack(Names.ADVENTURE_BACKPACK),
AkashicTome(Names.AKASHIC_TOME),
Angelica(Names.ANGELICA),
AppleCore(Names.APPLE_CORE),
AppliedEnergistics2(Names.APPLIED_ENERGISTICS2),
ArchitectureCraft(Names.ARCHITECTURE_CRAFT),
Expand Down Expand Up @@ -196,6 +197,7 @@ public static class Names {
public static final String ADVANCED_SOLAR_PANEL = "AdvancedSolarPanel";
public static final String ADVENTURE_BACKPACK = "adventurebackpack";
public static final String AKASHIC_TOME = "akashictome";
public static final String ANGELICA = "angelica";
public static final String APPLE_CORE = "AppleCore";
public static final String APPLIED_ENERGISTICS2 = "appliedenergistics2";
public static final String ARCHITECTURE_CRAFT = "ArchitectureCraft";
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/gregtech/api/enums/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,26 +405,55 @@ public enum BlockIcons implements IIconContainer, Runnable {
MACHINE_CASING_ENGINE_INTAKE,
MACHINE_CASING_EXTREME_ENGINE_INTAKE, // changed color in a terrible way
MACHINE_CASING_CHEMICALLY_INERT,
MACHINE_COIL_CUPRONICKEL,

MACHINE_CASING_DENSEBRICKS,
MACHINE_CASING_BRICKEDBLASTFURNACE_ACTIVE,
MACHINE_CASING_BRICKEDBLASTFURNACE_ACTIVE_GLOW,
MACHINE_CASING_BRICKEDBLASTFURNACE_INACTIVE,

MACHINE_COIL_CUPRONICKEL,
MACHINE_COIL_CUPRONICKEL_BACKGROUND,
MACHINE_COIL_CUPRONICKEL_FOREGROUND,
MACHINE_COIL_KANTHAL,
MACHINE_COIL_KANTHAL_BACKGROUND,
MACHINE_COIL_KANTHAL_FOREGROUND,
MACHINE_COIL_NICHROME,
MACHINE_COIL_NICHROME_BACKGROUND,
MACHINE_COIL_NICHROME_FOREGROUND,
MACHINE_COIL_TUNGSTENSTEEL,
MACHINE_COIL_TUNGSTENSTEEL_BACKGROUND,
MACHINE_COIL_TUNGSTENSTEEL_FOREGROUND,
MACHINE_COIL_HSSG,
MACHINE_COIL_HSSG_BACKGROUND,
MACHINE_COIL_HSSG_FOREGROUND,
MACHINE_COIL_NAQUADAH,
MACHINE_COIL_NAQUADAH_BACKGROUND,
MACHINE_COIL_NAQUADAH_FOREGROUND,
MACHINE_COIL_NAQUADAHALLOY,
MACHINE_COIL_NAQUADAHALLOY_BACKGROUND,
MACHINE_COIL_NAQUADAHALLOY_FOREGROUND,
MACHINE_COIL_ELECTRUMFLUX,
MACHINE_COIL_ELECTRUMFLUX_BACKGROUND,
MACHINE_COIL_ELECTRUMFLUX_FOREGROUND,
MACHINE_COIL_AWAKENEDDRACONIUM,
MACHINE_COIL_AWAKENEDDRACONIUM_BACKGROUND,
MACHINE_COIL_AWAKENEDDRACONIUM_FOREGROUND,
MACHINE_COIL_HSSS,
MACHINE_COIL_HSSS_BACKGROUND,
MACHINE_COIL_HSSS_FOREGROUND,
MACHINE_COIL_TRINIUM,
MACHINE_COIL_TRINIUM_BACKGROUND,
MACHINE_COIL_TRINIUM_FOREGROUND,
MACHINE_COIL_INFINITY,
MACHINE_COIL_INFINITY_BACKGROUND,
MACHINE_COIL_INFINITY_FOREGROUND,
MACHINE_COIL_HYPOGEN,
MACHINE_COIL_HYPOGEN_BACKGROUND,
MACHINE_COIL_HYPOGEN_FOREGROUND,
MACHINE_COIL_ETERNAL,
MACHINE_COIL_ETERNAL_BACKGROUND,
MACHINE_COIL_ETERNAL_FOREGROUND,

BOILER_SOLAR,
BOILER_FRONT,
BOILER_FRONT_GLOW,
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/gregtech/api/interfaces/IBlockWithTextures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gregtech.api.interfaces;

import javax.annotation.Nullable;

public interface IBlockWithTextures {

/**
* @return Texture[forge direction ordinal][layer]
*/
@Nullable
ITexture[][] getTextures(int metadata);
}
6 changes: 0 additions & 6 deletions src/main/java/gregtech/api/interfaces/IHeatingCoil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package gregtech.api.interfaces;

import java.util.function.Consumer;

import net.minecraft.item.ItemStack;

import gregtech.api.enums.HeatingCoilLevel;
Expand All @@ -13,8 +11,4 @@ public interface IHeatingCoil {
default HeatingCoilLevel getCoilHeat(ItemStack stack) {
return getCoilHeat(stack.getItemDamage());
}

void setOnCoilCheck(Consumer<IHeatingCoil> callback);

Consumer<IHeatingCoil> getOnCoilCheck();
}
16 changes: 16 additions & 0 deletions src/main/java/gregtech/api/interfaces/ITextureBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,20 @@ public interface ITextureBuilder {
* @return {@link ITextureBuilder} for chaining
*/
ITextureBuilder glow();

/**
* Uses the given block/meta as the shader material. No effect shaders are off or not supported.
*
* @return {@link ITextureBuilder} for chaining
*/
ITextureBuilder material(Block block, int meta);

/**
* Uses the given block as the shader material. No effect shaders are off or not supported.
*
* @return {@link ITextureBuilder} for chaining
*/
default ITextureBuilder material(Block block) {
return material(block, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import com.gtnewhorizons.modularui.api.NumberFormatMUI;
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.drawable.UITexture;
Expand Down Expand Up @@ -110,6 +111,7 @@
import gregtech.api.util.shutdown.ShutDownReasonRegistry;
import gregtech.client.GTSoundLoop;
import gregtech.common.config.MachineStats;
import gregtech.common.data.GTCoilTracker;
import gregtech.common.gui.modularui.widget.CheckRecipeResultSyncer;
import gregtech.common.gui.modularui.widget.ShutDownReasonSyncer;
import gregtech.common.items.MetaGeneratedTool01;
Expand All @@ -125,6 +127,7 @@
import gregtech.common.tileentities.machines.MTEHatchOutputME;
import gregtech.common.tileentities.machines.multi.MTELargeTurbine;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.MTEHatchSteamBusInput;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import mcp.mobius.waila.api.IWailaConfigHandler;
Expand Down Expand Up @@ -177,6 +180,14 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity
public ArrayList<MTEHatchMuffler> mMufflerHatches = new ArrayList<>();
public ArrayList<MTEHatchEnergy> mEnergyHatches = new ArrayList<>();
public ArrayList<MTEHatchMaintenance> mMaintenanceHatches = new ArrayList<>();

/**
* The list of coils in this multi's structure.
* Use {@link gregtech.api.util.GTStructureUtility#activeCoils(IStructureElement)} to add them automatically.
*/
public LongArrayList mCoils = new LongArrayList();
private GTCoilTracker.MultiCoilLease coilLease = null;

protected List<MTEHatch> mExoticEnergyHatches = new ArrayList<>();
protected final ProcessingLogic processingLogic;
@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -462,6 +473,12 @@ public void clearHatches() {
mMaintenanceHatches.clear();
mDualInputHatches.clear();
mSmartInputHatches.clear();

mCoils.clear();
if (coilLease != null) {
GTCoilTracker.deactivate(coilLease);
coilLease = null;
}
}

public boolean checkStructure(boolean aForceReset) {
Expand Down Expand Up @@ -545,6 +562,8 @@ public void setErrorDisplayID(int errorID) {
this.errorDisplayID = errorID;
}

private boolean wereCoilsActive = false;

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (aBaseMetaTileEntity.isServerSide()) {
Expand Down Expand Up @@ -580,9 +599,20 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
| (mSolderingTool ? 0 : 16)
| (mCrowbar ? 0 : 32)
| (mMachine ? 0 : 64));

aBaseMetaTileEntity.setActive(mMaxProgresstime > 0);
boolean active = aBaseMetaTileEntity.isActive() && mPollution > 0;
setMufflers(active);
setMufflers(aBaseMetaTileEntity.isActive() && mPollution > 0);

boolean isActive = mMaxProgresstime > 0;

if ((!mMachine || !isActive) && coilLease != null) {
GTCoilTracker.deactivate(coilLease);
coilLease = null;
}

if (mMachine && !mCoils.isEmpty() && isActive && coilLease == null) {
coilLease = GTCoilTracker.activate(this, mCoils);
}
} else {
if (!aBaseMetaTileEntity.hasMufflerUpgrade()) {
doActivitySound(getActivitySoundLoop());
Expand Down Expand Up @@ -2284,6 +2314,11 @@ public void onRemoval() {
super.onRemoval();
// Deactivate mufflers
setMufflers(false);

if (coilLease != null) {
GTCoilTracker.deactivate(coilLease);
coilLease = null;
}
}

public List<MTEHatch> getExoticEnergyHatches() {
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/gregtech/api/net/GTCoilStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package gregtech.api.net;

import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import com.google.common.io.ByteArrayDataInput;
import com.gtnewhorizon.gtnhlib.util.CoordinatePacker;

import gregtech.api.GregTechAPI;
import gregtech.common.blocks.BlockCasings5;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongCollection;

public class GTCoilStatus extends GTPacket {

public int worldId;
public boolean isActive;
public LongCollection coils;

public GTCoilStatus() {}

public GTCoilStatus(int worldId, boolean isActive, LongCollection coils) {
this.worldId = worldId;
this.isActive = isActive;
this.coils = coils;
}

@Override
public byte getPacketID() {
return GTPacketTypes.COIL_STATUS.id;
}

@Override
public void encode(ByteBuf buffer) {
buffer.writeInt(worldId);
buffer.writeBoolean(isActive);

buffer.writeInt(coils.size());

for (long l : coils) {
buffer.writeLong(l);
}
}

@Override
public GTPacket decode(ByteArrayDataInput buffer) {
GTCoilStatus packet = new GTCoilStatus();

packet.worldId = buffer.readInt();
packet.isActive = buffer.readBoolean();

int count = buffer.readInt();

packet.coils = new LongArrayList(count);

for (int i = 0; i < count; i++) {
packet.coils.add(buffer.readLong());
}

return packet;
}

@Override
public void process(IBlockAccess blockAccess) {
if (!(blockAccess instanceof World world)) return;
if (world.provider.dimensionId != worldId) return;

for (long coil : coils) {
int x = CoordinatePacker.unpackX(coil);
int y = CoordinatePacker.unpackY(coil);
int z = CoordinatePacker.unpackZ(coil);

if (world.getBlock(x, y, z) == GregTechAPI.sBlockCasings5) {
int meta = world.getBlockMetadata(x, y, z);

meta %= BlockCasings5.ACTIVE_OFFSET;
if (isActive) meta += BlockCasings5.ACTIVE_OFFSET;

world.setBlockMetadataWithNotify(x, y, z, meta, 2);
}
}
}
}
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/net/GTPacketTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum GTPacketTypes {
EIC(27, new PacketEIC()),
CREATE_TILE_ENTITY(28, new GTPacketCreateTE()),
NODE_INFO(29, new GTPacketNodeInfo()),
COIL_STATUS(30, new GTCoilStatus()),
// merge conflict prevention comment, keep a trailing comma above
;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/net/IGT_NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface IGT_NetworkHandler {
void sendToServer(GTPacket aPacket);

void sendPacketToAllPlayersInRange(World aWorld, GTPacket aPacket, int aX, int aZ);

void sendToWorld(World world, GTPacket packet);
}
Loading