From 093ec730867325054c652692d4b5fa3690ac3d64 Mon Sep 17 00:00:00 2001 From: matwi Date: Tue, 3 Jun 2025 15:49:19 +0200 Subject: [PATCH 1/9] Computer craft integration --- build.gradle | 27 ++++-- gradle.properties | 1 + .../java/com/petrolpark/destroy/Destroy.java | 8 ++ .../destroy/chemistry/api/util/Holder.java | 4 +- .../DestroyPeripheralProvider.java | 53 +++++++++++ .../computercraft/apis/ChemistryApi.java | 34 +++++++ .../peripherals/VatControllerPeripheral.java | 89 +++++++++++++++++++ .../vat/VatControllerBlockEntity.java | 2 + .../core/event/DestroyCommonEvents.java | 12 +++ .../mixin/compat/cct/FluidMethodsMixin.java | 70 +++++++++++++++ src/main/resources/destroy.mixins.json | 1 + 11 files changed, 292 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java create mode 100644 src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java create mode 100644 src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/VatControllerPeripheral.java create mode 100644 src/main/java/com/petrolpark/destroy/mixin/compat/cct/FluidMethodsMixin.java diff --git a/build.gradle b/build.gradle index c34c3eeea..633dba79d 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ minecraft { arg '-mixin.config=petrolpark.mixins.json' arg '-mixin.config=destroy.mixins.json' arg '-mixin.config=flywheel.mixins.json' - jvmArgs += ['-XX:+AllowEnhancedClassRedefinition'] + //jvmArgs += ['-XX:+AllowEnhancedClassRedefinition'] property 'forge.logging.console.level', 'info' mods { destroy { @@ -77,7 +77,7 @@ minecraft { arg '-mixin.config=create.mixins.json' arg '-mixin.config=petrolpark.mixins.json' arg '-mixin.config=destroy.mixins.json' - jvmArgs += ['-XX:+AllowEnhancedClassRedefinition'] + //jvmArgs += ['-XX:+AllowEnhancedClassRedefinition'] property 'forge.logging.console.level', 'info' mods { destroy { @@ -127,9 +127,9 @@ repositories { } } - flatDir { + /*flatDir { dirs "../petrolpark_local_maven/petrolpark/petrolpark-${minecraft_version}/${petrolpark_library_version}" - } + }*/ maven { // Curios @@ -150,6 +150,12 @@ repositories { maven { // Blueprint url = "https://maven.jaackson.me" } + maven { //Computer Craft Tweaked + url "https://maven.squiddev.cc" + content { + includeGroup("cc.tweaked") + } + } } configurations { @@ -182,10 +188,10 @@ dependencies { implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${minecraft_version}:${flywheel_version}") // Registrate - implementation fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}") + compileOnly fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}") // Petrolpark Library (temporary) - implementation "com.petrolpark:petrolpark:${minecraft_version}-${petrolpark_library_version}" + implementation fg.deobf("maven.modrinth:petrolpark:${minecraft_version}-${petrolpark_library_version}:all") // JGraphT jarJar(implementation("org.jgrapht:jgrapht-core:1.5.1")) @@ -198,7 +204,9 @@ dependencies { // JEI compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}") compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}") - compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}-forge:${jei_version}") + implementation fg.deobf("mezz.jei:jei-${minecraft_version}-forge:${jei_version}") + + //runtimeOnly fg.deobf("mezz.jei:jei-${minecraft_version}-forge:${jei_version}") // Farmer's Delight compileOnly fg.deobf("curse.maven:farmers-delight-398521:${farmersdelight_version}") @@ -216,6 +224,11 @@ dependencies { // Embeddium compileOnly fg.deobf("maven.modrinth:embeddium:${embeddium_version}+mc${minecraft_version}") + + // Computer Craft + compileOnly("cc.tweaked:cc-tweaked-${minecraft_version}-core-api:${cct_version}") + compileOnly(fg.deobf("cc.tweaked:cc-tweaked-${minecraft_version}-forge-api:${cct_version}")) + implementation(fg.deobf("cc.tweaked:cc-tweaked-${minecraft_version}-forge:${cct_version}")) // ANNOTATION PROCESSORS diff --git a/gradle.properties b/gradle.properties index a0c10858f..40ab5781a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,3 +28,4 @@ spark_version = 4587309 cbc_version = 5.5.0+mc.1.20.1-forge curios_version = 5.9.1 embeddium_version = 0.3.30 +cct_version = 1.115.0 \ No newline at end of file diff --git a/src/main/java/com/petrolpark/destroy/Destroy.java b/src/main/java/com/petrolpark/destroy/Destroy.java index df4b86071..ab48af076 100644 --- a/src/main/java/com/petrolpark/destroy/Destroy.java +++ b/src/main/java/com/petrolpark/destroy/Destroy.java @@ -1,5 +1,8 @@ package com.petrolpark.destroy; +import com.petrolpark.destroy.compat.computercraft.apis.ChemistryApi; +import com.simibubi.create.compat.Mods; +import dan200.computercraft.api.ComputerCraftAPI; import org.slf4j.Logger; import com.mojang.logging.LogUtils; @@ -123,6 +126,11 @@ public Destroy() { // Optional compatibility mods. According to the Create main class doing the same thing, this isn't thread safe CompatMods.BIG_CANNONS.executeIfInstalled(() -> () -> CreateBigCannons.init(modEventBus, forgeEventBus)); CompatMods.CURIOS.executeIfInstalled(() -> () -> DestroyCurios.init(modEventBus, forgeEventBus)); + Mods.COMPUTERCRAFT.executeIfInstalled(() -> () -> { + ComputerCraftAPI.registerAPIFactory(computer -> { + return new ChemistryApi(); + }); + }); }; // Initiation Events diff --git a/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java b/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java index f6340348a..7d5e8abef 100644 --- a/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java +++ b/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java @@ -6,9 +6,9 @@ * @since Destroy 0.1.2 * @author petrolpark */ -public final class Holder { +public class Holder { - protected V held; + private V held; public static Holder hold(V object) { return new Holder<>(object); diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java new file mode 100644 index 000000000..81682b9d9 --- /dev/null +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java @@ -0,0 +1,53 @@ +package com.petrolpark.destroy.compat.computercraft; + +import com.petrolpark.destroy.Destroy; +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.common.capabilities.CapabilityToken; +import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.event.AttachCapabilitiesEvent; + +import javax.annotation.Nullable; +import java.util.function.Function; + +// From the cc:tweaked documentation +// A {@link ICapabilityProvider} that lazily creates an {@link IPeripheral} when required. +public final class DestroyPeripheralProvider implements ICapabilityProvider { + public static final Capability CAPABILITY_PERIPHERAL = CapabilityManager.get(new CapabilityToken<>() { + }); + private static final ResourceLocation PERIPHERAL = new ResourceLocation(Destroy.MOD_ID, "peripheral"); + + private final O blockEntity; + private final Function factory; + private @Nullable LazyOptional peripheral; + + public DestroyPeripheralProvider(O blockEntity, Function factory) { + this.blockEntity = blockEntity; + this.factory = factory; + } + + public static void attach(AttachCapabilitiesEvent event, O blockEntity, Function factory) { + var provider = new DestroyPeripheralProvider<>(blockEntity, factory); + event.addCapability(PERIPHERAL, provider); + event.addListener(provider::invalidate); + } + + public void invalidate() { + if (peripheral != null) peripheral.invalidate(); + peripheral = null; + } + + @Override + public LazyOptional getCapability(Capability capability, @Nullable Direction direction) { + if (capability != CAPABILITY_PERIPHERAL) return LazyOptional.empty(); + if (blockEntity.isRemoved()) return LazyOptional.empty(); + + var peripheral = this.peripheral; + return (peripheral == null ? (this.peripheral = LazyOptional.of(() -> factory.apply(blockEntity))) : peripheral).cast(); + } +} diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java new file mode 100644 index 000000000..a73553e9e --- /dev/null +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java @@ -0,0 +1,34 @@ +package com.petrolpark.destroy.compat.computercraft.apis; + +import com.petrolpark.destroy.chemistry.legacy.LegacySpecies; +import com.simibubi.create.compat.computercraft.implementation.CreateLuaTable; +import dan200.computercraft.api.lua.ILuaAPI; +import dan200.computercraft.api.lua.LuaFunction; +import org.jetbrains.annotations.Nullable; + +public class ChemistryApi implements ILuaAPI { + + @LuaFunction + public final CreateLuaTable getMoleculeInfos(String id) { + LegacySpecies molecule = LegacySpecies.getMolecule(id); + CreateLuaTable infos = new CreateLuaTable(); + + infos.putDouble("Mass", molecule.getMass()); + infos.putDouble("BoilingPoint", molecule.getBoilingPoint()); + infos.putDouble("Density", molecule.getDensity()); + infos.putDouble("Charge", molecule.getCharge()); + infos.putString("FROWNS", molecule.getFROWNSCode()); + + return infos; + } + + @Override + public String[] getNames() { + return new String[0]; + } + + @Override + public @Nullable String getModuleName() { + return "destroy.chemistry"; + } +} diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/VatControllerPeripheral.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/VatControllerPeripheral.java new file mode 100644 index 000000000..ad35b743c --- /dev/null +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/VatControllerPeripheral.java @@ -0,0 +1,89 @@ +package com.petrolpark.destroy.compat.computercraft.peripherals; + +import com.petrolpark.destroy.chemistry.legacy.LegacyMixture; +import com.petrolpark.destroy.chemistry.legacy.ReadOnlyMixture; +import com.petrolpark.destroy.chemistry.minecraft.MixtureFluid; +import com.petrolpark.destroy.core.chemistry.vat.VatControllerBlockEntity; +import com.simibubi.create.Create; +import com.simibubi.create.compat.computercraft.implementation.CreateLuaTable; +import com.simibubi.create.compat.computercraft.implementation.peripherals.SyncedPeripheral; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.lua.LuaTable; +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraftforge.fluids.FluidStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class VatControllerPeripheral implements IPeripheral { + + VatControllerBlockEntity vcbe; + + public VatControllerPeripheral(VatControllerBlockEntity vcbe) { + this.vcbe = vcbe; + } + + @LuaFunction(mainThread = true) + public final float getPressure() throws LuaException { + checkForVat(); + return this.vcbe.getPressure(); + } + + @LuaFunction(mainThread = true) + public final float getTemperature() throws LuaException { + checkForVat(); + return this.vcbe.getTemperature(); + } + + @LuaFunction(mainThread = true) + public final int getCapacity() throws LuaException { + checkForVat(); + return this.vcbe.getCapacity(); + } + + @LuaFunction(mainThread = true) + public final float getUVStrength() throws LuaException { + checkForVat(); + return this.vcbe.getUVPower(); + } + + @LuaFunction(mainThread = true) + public final float getFluidLevel() throws LuaException { + checkForVat(); + return this.vcbe.getFluidLevel(); + } + + @LuaFunction(mainThread = true) + public final CreateLuaTable getMixture() throws LuaException { + checkForVat(); + + CreateLuaTable contentsTable = new CreateLuaTable(); + ReadOnlyMixture mixture = this.vcbe.getCombinedReadOnlyMixture(); + + mixture.getContents(false).forEach((molecule) -> { + contentsTable.put(molecule.getFullID(), mixture.getConcentrationOf(molecule)); + }); + + return contentsTable; + } + + @Override + public String getType() { + return "vat_controller"; + } + + @Override + public boolean equals(@Nullable IPeripheral other) { + return other instanceof VatControllerPeripheral o && vcbe == o.vcbe; + } + + private void checkForVat() throws LuaException { + if (vcbe.getVatOptional().isEmpty()) + throw new LuaException("Could not execute function, vat is not assembled"); + } +} diff --git a/src/main/java/com/petrolpark/destroy/core/chemistry/vat/VatControllerBlockEntity.java b/src/main/java/com/petrolpark/destroy/core/chemistry/vat/VatControllerBlockEntity.java index 66b5f8b8f..70c98f790 100644 --- a/src/main/java/com/petrolpark/destroy/core/chemistry/vat/VatControllerBlockEntity.java +++ b/src/main/java/com/petrolpark/destroy/core/chemistry/vat/VatControllerBlockEntity.java @@ -627,6 +627,8 @@ public float getTemperature() { return cachedMixture.getTemperature(); }; + public float getUVPower() { return UVPower; } + /** * Get the pressure above room pressure of the gas in this Vat (in Pa). */ diff --git a/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java b/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java index 6b5926665..61fbb00e0 100644 --- a/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java +++ b/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java @@ -18,6 +18,8 @@ import com.petrolpark.destroy.client.DestroyLang; import com.petrolpark.destroy.DestroyTrades; import com.petrolpark.destroy.DestroyVillagers; +import com.petrolpark.destroy.compat.computercraft.DestroyPeripheralProvider; +import com.petrolpark.destroy.compat.computercraft.peripherals.VatControllerPeripheral; import com.petrolpark.destroy.config.DestroyAllConfigs; import com.petrolpark.destroy.content.oil.ChunkCrudeOil; import com.petrolpark.destroy.content.oil.CrudeOilCommand; @@ -39,9 +41,11 @@ import com.petrolpark.destroy.core.chemistry.storage.IMixtureStorageItem; import com.petrolpark.destroy.core.chemistry.storage.measuringcylinder.MeasuringCylinderBlock; import com.petrolpark.destroy.core.chemistry.storage.measuringcylinder.MeasuringCylinderBlockItem; +import com.petrolpark.destroy.core.chemistry.vat.VatControllerBlockEntity; import com.petrolpark.destroy.core.chemistry.vat.material.SyncVatMaterialsS2CPacket; import com.petrolpark.destroy.core.chemistry.vat.material.VatMaterial; import com.petrolpark.destroy.core.chemistry.vat.material.VatMaterialResourceListener; +import com.petrolpark.destroy.core.chemistry.vat.observation.colorimeter.ColorimeterBlockEntity; import com.petrolpark.destroy.core.debug.AttachedCheckCommand; import com.petrolpark.destroy.core.explosion.mixedexplosive.ExplosiveProperties; import com.petrolpark.destroy.core.extendedinventory.ExtendedInventory; @@ -96,6 +100,7 @@ import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; @@ -164,6 +169,13 @@ public static final void onAttachCapabilitiesEntity(AttachCapabilitiesEvent event) { + if ( event.getObject() instanceof VatControllerBlockEntity vcbe ) { + DestroyPeripheralProvider.attach(event, vcbe, VatControllerPeripheral::new); + } + }; + @SubscribeEvent public static final void onAttachCapabilitiesChunk(AttachCapabilitiesEvent event) { LevelChunk chunk = event.getObject(); diff --git a/src/main/java/com/petrolpark/destroy/mixin/compat/cct/FluidMethodsMixin.java b/src/main/java/com/petrolpark/destroy/mixin/compat/cct/FluidMethodsMixin.java new file mode 100644 index 000000000..3dc64c223 --- /dev/null +++ b/src/main/java/com/petrolpark/destroy/mixin/compat/cct/FluidMethodsMixin.java @@ -0,0 +1,70 @@ +package com.petrolpark.destroy.mixin.compat.cct; + +import com.petrolpark.destroy.chemistry.legacy.LegacyMixture; +import com.petrolpark.destroy.chemistry.minecraft.MixtureFluid; +import dan200.computercraft.api.detail.ForgeDetailRegistries; +import dan200.computercraft.shared.peripheral.generic.methods.FluidMethods; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + + +@Mixin(FluidMethods.class) +public class FluidMethodsMixin { + @Inject( + method = "tanks(Lnet/minecraftforge/fluids/capability/IFluidHandler;)Ljava/util/Map;", + at = @At( + value = "HEAD" + ), + cancellable = true, + remap = false + ) + private void inTanks(IFluidHandler fluids, CallbackInfoReturnable>> cir) { + Map> result = new HashMap(); + int size = fluids.getTanks(); + + for(int i = 0; i < size; ++i) { + FluidStack stack = fluids.getFluidInTank(i); + if (!stack.isEmpty()) { + Map details = ForgeDetailRegistries.FLUID_STACK.getBasicDetails(stack); + if (details.get("name").equals("destroy:mixture")) { + Map> contentsTable = new HashMap<>(); + CompoundTag data = new CompoundTag(); + + stack.writeToNBT(data); + ListTag contents = data + .getCompound("Tag") + .getCompound("Mixture") + .getList("Contents", 10); + + contents.forEach(tag -> { + Map molecule = new HashMap<>(); + CompoundTag moleculeTag = (CompoundTag) tag; + + molecule.put("id", moleculeTag.getString("Molecule")); + molecule.put("concentration", moleculeTag.getFloat("Concentration")); + contentsTable.put(contentsTable.size() + 1, molecule); + }); + + details.put("contents", contentsTable); + } + result.put(i + 1, details); + } + } + + cir.setReturnValue(result); + cir.cancel(); + } +} diff --git a/src/main/resources/destroy.mixins.json b/src/main/resources/destroy.mixins.json index ffe163b2f..af2355fc4 100644 --- a/src/main/resources/destroy.mixins.json +++ b/src/main/resources/destroy.mixins.json @@ -26,6 +26,7 @@ "compat.jei.DeployingCategoryMixin", "compat.jei.MixingCategoryMixin", "compat.jei.PackingCategoryMixin", + "compat.cct.FluidMethodsMixin", "AbstractContainerMenuMixin", "AirCurrentMixin", "BasinBlockEntityMixin", From eb8c8038f80822b78055d22db6b05fc8b421a4df Mon Sep 17 00:00:00 2001 From: matwi Date: Tue, 3 Jun 2025 15:53:43 +0200 Subject: [PATCH 2/9] Revert Holder to original code --- .../java/com/petrolpark/destroy/chemistry/api/util/Holder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java b/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java index 7d5e8abef..eb3bedfc8 100644 --- a/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java +++ b/src/main/java/com/petrolpark/destroy/chemistry/api/util/Holder.java @@ -6,7 +6,7 @@ * @since Destroy 0.1.2 * @author petrolpark */ -public class Holder { +public final class Holder { private V held; From 8386605a56a50aaf834504511f8b381a3c6101d3 Mon Sep 17 00:00:00 2001 From: matwi Date: Tue, 3 Jun 2025 16:17:24 +0200 Subject: [PATCH 3/9] Insignificant changes --- .../destroy/compat/computercraft/apis/ChemistryApi.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java index a73553e9e..231d15ba8 100644 --- a/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java @@ -13,10 +13,10 @@ public final CreateLuaTable getMoleculeInfos(String id) { LegacySpecies molecule = LegacySpecies.getMolecule(id); CreateLuaTable infos = new CreateLuaTable(); - infos.putDouble("Mass", molecule.getMass()); - infos.putDouble("BoilingPoint", molecule.getBoilingPoint()); - infos.putDouble("Density", molecule.getDensity()); - infos.putDouble("Charge", molecule.getCharge()); + infos.putDouble("mass", molecule.getMass()); + infos.putDouble("boilingPoint", molecule.getBoilingPoint()); + infos.putDouble("density", molecule.getDensity()); + infos.putDouble("charge", molecule.getCharge()); infos.putString("FROWNS", molecule.getFROWNSCode()); return infos; From c0176c4843e485f5876d809d6050026a1d6e81b7 Mon Sep 17 00:00:00 2001 From: matwi Date: Thu, 5 Jun 2025 16:22:51 +0200 Subject: [PATCH 4/9] Added the siphon peripheral... --- .../peripherals/SiphonPeripheral.java | 50 +++++++++++++++++++ .../core/event/DestroyCommonEvents.java | 5 ++ 2 files changed, 55 insertions(+) create mode 100644 src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java new file mode 100644 index 000000000..6fdadbe40 --- /dev/null +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java @@ -0,0 +1,50 @@ +package com.petrolpark.destroy.compat.computercraft.peripherals; + +import com.petrolpark.destroy.content.logistics.siphon.SiphonBlockEntity; +import com.simibubi.create.foundation.blockEntity.behaviour.fluid.SmartFluidTankBehaviour; +import dan200.computercraft.api.detail.ForgeDetailRegistries; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.HashMap; +import java.util.Map; + +public class SiphonPeripheral implements IPeripheral { + + SiphonBlockEntity sbe; + + public SiphonPeripheral(SiphonBlockEntity sbe) { + this.sbe = sbe; + } + + @LuaFunction(mainThread = true) + public final int getLeftToDrain() { + return sbe.leftToDrain; + } + + @LuaFunction(mainThread = true) + public final void drain(int amount) { + sbe.leftToDrain += amount; + sbe.notifyUpdate(); + } + + @Override + public String getType() { + return "siphon"; + } + + @Override + public boolean equals(@Nullable IPeripheral other) { + return other instanceof SiphonPeripheral o && sbe == o.sbe; + } +} diff --git a/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java b/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java index 61fbb00e0..4d9cd05fd 100644 --- a/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java +++ b/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java @@ -19,8 +19,10 @@ import com.petrolpark.destroy.DestroyTrades; import com.petrolpark.destroy.DestroyVillagers; import com.petrolpark.destroy.compat.computercraft.DestroyPeripheralProvider; +import com.petrolpark.destroy.compat.computercraft.peripherals.SiphonPeripheral; import com.petrolpark.destroy.compat.computercraft.peripherals.VatControllerPeripheral; import com.petrolpark.destroy.config.DestroyAllConfigs; +import com.petrolpark.destroy.content.logistics.siphon.SiphonBlockEntity; import com.petrolpark.destroy.content.oil.ChunkCrudeOil; import com.petrolpark.destroy.content.oil.CrudeOilCommand; import com.petrolpark.destroy.content.processing.glassblowing.BlowpipeItem; @@ -174,6 +176,9 @@ public static final void onAttachCapabilitiesBlockEntity(AttachCapabilitiesEvent if ( event.getObject() instanceof VatControllerBlockEntity vcbe ) { DestroyPeripheralProvider.attach(event, vcbe, VatControllerPeripheral::new); } + if ( event.getObject() instanceof SiphonBlockEntity sbe ) { + DestroyPeripheralProvider.attach(event, sbe, SiphonPeripheral::new); + } }; @SubscribeEvent From ad7b528b88b77cc5ee6aa3ab142125e8138af04b Mon Sep 17 00:00:00 2001 From: matwi Date: Sun, 8 Jun 2025 17:11:50 +0200 Subject: [PATCH 5/9] New function --- .../compat/computercraft/peripherals/SiphonPeripheral.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java index 6fdadbe40..a65875df0 100644 --- a/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/SiphonPeripheral.java @@ -32,6 +32,11 @@ public final int getLeftToDrain() { return sbe.leftToDrain; } + @LuaFunction(mainThread = true) + public final float getFluidLevel() { + return sbe.tank.getPrimaryTank().getRenderedFluid().getAmount(); + } + @LuaFunction(mainThread = true) public final void drain(int amount) { sbe.leftToDrain += amount; From 94eaa36ed620e58a790992fb20f458fa6ca7ef8e Mon Sep 17 00:00:00 2001 From: matwi Date: Tue, 10 Jun 2025 12:48:19 +0200 Subject: [PATCH 6/9] Added a better tanks function handling for the distillation tower --- .../peripherals/BubbleCapPeripheral.java | 82 +++++++++++++++++++ .../core/event/DestroyCommonEvents.java | 5 ++ 2 files changed, 87 insertions(+) create mode 100644 src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/BubbleCapPeripheral.java diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/BubbleCapPeripheral.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/BubbleCapPeripheral.java new file mode 100644 index 000000000..ddb01c769 --- /dev/null +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/peripherals/BubbleCapPeripheral.java @@ -0,0 +1,82 @@ +package com.petrolpark.destroy.compat.computercraft.peripherals; + +import com.petrolpark.destroy.content.processing.distillation.BubbleCapBlockEntity; +import com.petrolpark.destroy.content.processing.distillation.DistillationTower; +import dan200.computercraft.api.detail.ForgeDetailRegistries; +import dan200.computercraft.api.lua.LuaFunction; +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.world.level.Level; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +public class BubbleCapPeripheral implements IPeripheral { + + BubbleCapBlockEntity bcbe; + + public BubbleCapPeripheral(BubbleCapBlockEntity bcbe) { + this.bcbe = bcbe; + } + + @LuaFunction(mainThread = true) + public final Map> tanks() { + Level level = bcbe.getLevel(); + + DistillationTower tower = bcbe.getDistillationTower(); + BlockPos startPos = tower.getControllerPos(); + int height = tower.getHeight(); + + Map> result = new HashMap(); + + for (int i = 0; i < height; i++) { + BubbleCapBlockEntity be = ( BubbleCapBlockEntity ) level.getBlockEntity(startPos.offset(0, i, 0)); + result.put(i + 1, getTank(be.getTank())); + } + + return result; + } + + private Map getTank(IFluidHandler fluids) { + FluidStack stack = fluids.getFluidInTank(0); + + if (!stack.isEmpty()) { + Map details = ForgeDetailRegistries.FLUID_STACK.getBasicDetails(stack); + if (details.get("name").equals("destroy:mixture")) { + Map> contentsTable = new HashMap<>(); + CompoundTag data = new CompoundTag(); + stack.writeToNBT(data); + ListTag contents = data + .getCompound("Tag") + .getCompound("Mixture") + .getList("Contents", 10); + contents.forEach(tag -> { + Map molecule = new HashMap<>(); + CompoundTag moleculeTag = (CompoundTag) tag; + molecule.put("id", moleculeTag.getString("Molecule")); + molecule.put("concentration", moleculeTag.getFloat("Concentration")); + contentsTable.put(contentsTable.size() + 1, molecule); + }); + details.put("contents", contentsTable); + } + return details; + } + + return new HashMap(); + } + + @Override + public String getType() { + return "bubble_cap"; + } + + @Override + public boolean equals(@Nullable IPeripheral other) { + return other instanceof BubbleCapPeripheral o && bcbe == o.bcbe; + } +} diff --git a/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java b/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java index 4d9cd05fd..0bb66a645 100644 --- a/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java +++ b/src/main/java/com/petrolpark/destroy/core/event/DestroyCommonEvents.java @@ -19,12 +19,14 @@ import com.petrolpark.destroy.DestroyTrades; import com.petrolpark.destroy.DestroyVillagers; import com.petrolpark.destroy.compat.computercraft.DestroyPeripheralProvider; +import com.petrolpark.destroy.compat.computercraft.peripherals.BubbleCapPeripheral; import com.petrolpark.destroy.compat.computercraft.peripherals.SiphonPeripheral; import com.petrolpark.destroy.compat.computercraft.peripherals.VatControllerPeripheral; import com.petrolpark.destroy.config.DestroyAllConfigs; import com.petrolpark.destroy.content.logistics.siphon.SiphonBlockEntity; import com.petrolpark.destroy.content.oil.ChunkCrudeOil; import com.petrolpark.destroy.content.oil.CrudeOilCommand; +import com.petrolpark.destroy.content.processing.distillation.BubbleCapBlockEntity; import com.petrolpark.destroy.content.processing.glassblowing.BlowpipeItem; import com.petrolpark.destroy.content.processing.trypolithography.CircuitPatternsS2CPacket; import com.petrolpark.destroy.content.processing.trypolithography.RegenerateCircuitPatternCommand; @@ -179,6 +181,9 @@ public static final void onAttachCapabilitiesBlockEntity(AttachCapabilitiesEvent if ( event.getObject() instanceof SiphonBlockEntity sbe ) { DestroyPeripheralProvider.attach(event, sbe, SiphonPeripheral::new); } + if ( event.getObject() instanceof BubbleCapBlockEntity bcbe ) { + DestroyPeripheralProvider.attach(event, bcbe, BubbleCapPeripheral::new); + } }; @SubscribeEvent From 826c88f32dfc92a0916179984bf3e5a85e300146 Mon Sep 17 00:00:00 2001 From: matwi Date: Fri, 13 Jun 2025 15:06:28 +0200 Subject: [PATCH 7/9] New functions :) --- .../computercraft/apis/ChemistryApi.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java index 231d15ba8..89c9e9c26 100644 --- a/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/apis/ChemistryApi.java @@ -1,6 +1,10 @@ package com.petrolpark.destroy.compat.computercraft.apis; +import com.petrolpark.destroy.chemistry.legacy.LegacyReaction; import com.petrolpark.destroy.chemistry.legacy.LegacySpecies; +import com.petrolpark.destroy.chemistry.legacy.genericreaction.GenericReaction; +import com.petrolpark.destroy.chemistry.legacy.index.DestroyReactions; +import com.simibubi.create.Create; import com.simibubi.create.compat.computercraft.implementation.CreateLuaTable; import dan200.computercraft.api.lua.ILuaAPI; import dan200.computercraft.api.lua.LuaFunction; @@ -8,7 +12,7 @@ public class ChemistryApi implements ILuaAPI { - @LuaFunction + @LuaFunction(mainThread = true) public final CreateLuaTable getMoleculeInfos(String id) { LegacySpecies molecule = LegacySpecies.getMolecule(id); CreateLuaTable infos = new CreateLuaTable(); @@ -22,6 +26,44 @@ public final CreateLuaTable getMoleculeInfos(String id) { return infos; } + @LuaFunction(mainThread = true) + public final CreateLuaTable getReactionsFor(String id) { + CreateLuaTable resultTable = new CreateLuaTable(); + LegacySpecies molecule = LegacySpecies.getMolecule(id); + + LegacyReaction.REACTIONS.forEach((rId, reaction) -> { + if ( reaction.getProducts().contains(molecule)) { + resultTable.putDouble(rId, reaction.getProductMolarRatio(molecule)); + } + }); + + return resultTable; + } + + @LuaFunction(mainThread = true) + public final CreateLuaTable getReactantsFor(String reactionId) { + CreateLuaTable resultTable = new CreateLuaTable(); + LegacyReaction reaction = LegacyReaction.REACTIONS.get(reactionId); + + reaction.getReactants().forEach((reactant) -> { + resultTable.putDouble(reactant.getFullID(), reaction.getReactantMolarRatio(reactant)); + }); + + return resultTable; + } + + @LuaFunction(mainThread = true) + public final CreateLuaTable getProductsFor(String reactionId) { + CreateLuaTable resultTable = new CreateLuaTable(); + LegacyReaction reaction = LegacyReaction.REACTIONS.get(reactionId); + + reaction.getProducts().forEach((product) -> { + resultTable.putDouble(product.getFullID(), reaction.getReactantMolarRatio(product)); + }); + + return resultTable; + } + @Override public String[] getNames() { return new String[0]; From a7c96190e1db4015b438665c6f3eaf1a6f6f2bff Mon Sep 17 00:00:00 2001 From: matwi Date: Mon, 7 Jul 2025 15:51:30 +0200 Subject: [PATCH 8/9] Updated dependencies --- build.gradle | 8 ++++---- gradle.properties | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index dd2300759..37ad605c5 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,7 @@ minecraft { client { workingDirectory project.file('run') arg '-mixin.config=destroy.mixins.json' - jvmArgs += ['-XX:+AllowEnhancedClassRedefinition'] + //jvmArgs += ['-XX:+AllowEnhancedClassRedefinition'] property 'forge.logging.console.level', 'info' mods { destroy { @@ -126,9 +126,9 @@ repositories { } } - /*flatDir { + flatDir { dirs "../petrolpark_local_maven/petrolpark/petrolpark-${minecraft_version}/${petrolpark_library_version}" - }*/ + } flatDir { dirs "../petrolpark_local_maven/cbc-${minecraft_version}/" @@ -204,7 +204,7 @@ dependencies { compileOnly fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}") // Petrolpark Library (temporary) - implementation fg.deobf("maven.modrinth:petrolpark:${minecraft_version}-${petrolpark_library_version}:all") + implementation fg.deobf("com.petrolpark:petrolpark:${minecraft_version}-${petrolpark_library_version}") // JGraphT jarJar(implementation("org.jgrapht:jgrapht-core:[${jgrapht_version}]")) diff --git a/gradle.properties b/gradle.properties index e08ca4ed9..0ab40e735 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,4 +33,4 @@ cbc_version = 5.9.0+mc.1.20.1-forge rpl_version = 2.1.0+mc.1.20.1-forge curios_version = 5.12.1 embeddium_version = 0.3.30 -cct_version = 1.115.0 \ No newline at end of file +cct_version = 1.116.0 \ No newline at end of file From f72890adc02297e374bee08921470ad61ce04bb6 Mon Sep 17 00:00:00 2001 From: matwi Date: Mon, 18 Aug 2025 14:24:24 +0200 Subject: [PATCH 9/9] Commit --- .../destroy/compat/computercraft/DestroyPeripheralProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java b/src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java index 81682b9d9..481e6ed78 100644 --- a/src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java +++ b/src/main/java/com/petrolpark/destroy/compat/computercraft/DestroyPeripheralProvider.java @@ -20,7 +20,7 @@ public final class DestroyPeripheralProvider implements ICapabilityProvider { public static final Capability CAPABILITY_PERIPHERAL = CapabilityManager.get(new CapabilityToken<>() { }); - private static final ResourceLocation PERIPHERAL = new ResourceLocation(Destroy.MOD_ID, "peripheral"); + private static final ResourceLocation PERIPHERAL = ResourceLocation.fromNamespaceAndPath(Destroy.MOD_ID, "peripheral"); private final O blockEntity; private final Function factory;