Skip to content
Open
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
21 changes: 17 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ minecraft {
server {
workingDirectory project.file('run/server')
arg '-mixin.config=destroy.mixins.json'
jvmArgs += ['-XX:+AllowEnhancedClassRedefinition']
//jvmArgs += ['-XX:+AllowEnhancedClassRedefinition']
property 'forge.logging.console.level', 'info'
mods {
destroy {
Expand Down Expand Up @@ -153,6 +153,12 @@ repositories {
maven { // MixinSquared
url = "https://maven.bawnorton.com/releases"
}
maven { //Computer Craft Tweaked
url "https://maven.squiddev.cc"
content {
includeGroup("cc.tweaked")
}
}
}

configurations {
Expand Down Expand Up @@ -191,10 +197,10 @@ dependencies {
implementation fg.deobf("dev.engine-room.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("com.petrolpark:petrolpark:${minecraft_version}-${petrolpark_library_version}")

// JGraphT
//jarJar(implementation("org.jgrapht:jgrapht-core:[${jgrapht_version}]"))
Expand All @@ -207,7 +213,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}")
Expand All @@ -223,6 +231,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

// MixinSquared's annotationProcessor MUST be registered BEFORE Mixin's one.
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ cbc_version = 5.9.1+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.116.0
8 changes: 8 additions & 0 deletions src/main/java/com/petrolpark/destroy/Destroy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -125,6 +128,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
public final class Holder<V> {

protected V held;
private V held;

public static <V> Holder<V> hold(V object) {
return new Holder<>(object);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<O extends BlockEntity> implements ICapabilityProvider {
public static final Capability<IPeripheral> CAPABILITY_PERIPHERAL = CapabilityManager.get(new CapabilityToken<>() {
});
private static final ResourceLocation PERIPHERAL = ResourceLocation.fromNamespaceAndPath(Destroy.MOD_ID, "peripheral");

private final O blockEntity;
private final Function<O, IPeripheral> factory;
private @Nullable LazyOptional<IPeripheral> peripheral;

public DestroyPeripheralProvider(O blockEntity, Function<O, IPeripheral> factory) {
this.blockEntity = blockEntity;
this.factory = factory;
}

public static <O extends BlockEntity> void attach(AttachCapabilitiesEvent<BlockEntity> event, O blockEntity, Function<O, IPeripheral> 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 <T> LazyOptional<T> getCapability(Capability<T> 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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;
import org.jetbrains.annotations.Nullable;

public class ChemistryApi implements ILuaAPI {

@LuaFunction(mainThread = true)
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;
}

@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];
}

@Override
public @Nullable String getModuleName() {
return "destroy.chemistry";
}
}
Original file line number Diff line number Diff line change
@@ -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<Integer, Map<String, ?>> tanks() {
Level level = bcbe.getLevel();

DistillationTower tower = bcbe.getDistillationTower();
BlockPos startPos = tower.getControllerPos();
int height = tower.getHeight();

Map<Integer, Map<String, ?>> 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<String, ?> getTank(IFluidHandler fluids) {
FluidStack stack = fluids.getFluidInTank(0);

if (!stack.isEmpty()) {
Map<String, Object> details = ForgeDetailRegistries.FLUID_STACK.getBasicDetails(stack);
if (details.get("name").equals("destroy:mixture")) {
Map<Integer, Map<String, ?>> contentsTable = new HashMap<>();
CompoundTag data = new CompoundTag();
stack.writeToNBT(data);
ListTag contents = data
.getCompound("Tag")
.getCompound("Mixture")
.getList("Contents", 10);
contents.forEach(tag -> {
Map<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 float getFluidLevel() {
return sbe.tank.getPrimaryTank().getRenderedFluid().getAmount();
}

@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;
}
}
Loading