Skip to content

Commit 7aac858

Browse files
committed
Fully functional gas composting
1 parent d07ad76 commit 7aac858

File tree

5 files changed

+116
-6
lines changed

5 files changed

+116
-6
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
2+
13
plugins {
24
// Needed for Forge+Fabric
35
id "architectury-plugin" version "3.4.146"
@@ -137,9 +139,11 @@ allprojects {
137139
options.release = 17
138140
}
139141

140-
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile).configureEach {
142+
tasks.withType(KotlinJvmCompile).configureEach {
141143
kotlinOptions {
142144
jvmTarget = "17"
145+
freeCompilerArgs += "-Xjvm-default=all"
146+
143147
}
144148
}
145149

common/src/main/java/org/valkyrienskies/clockwork/mixin/MixinBacktankUtil.java renamed to common/src/main/java/org/valkyrienskies/clockwork/mixin/content/gas/MixinBacktankUtil.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
package org.valkyrienskies.clockwork.mixin;
1+
package org.valkyrienskies.clockwork.mixin.content.gas;
22

3-
import com.simibubi.create.AllEnchantments;
43
import com.simibubi.create.content.equipment.armor.BacktankUtil;
54
import net.minecraft.world.item.ItemStack;
6-
import net.minecraft.world.item.enchantment.EnchantmentHelper;
75
import org.spongepowered.asm.mixin.Mixin;
86
import org.spongepowered.asm.mixin.injection.At;
97
import org.spongepowered.asm.mixin.injection.Inject;
108
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
119
import org.valkyrienskies.clockwork.ClockworkItems;
12-
import org.valkyrienskies.clockwork.content.logistics.gas.backtank.GasBackTankItem;
1310

1411
@Mixin(BacktankUtil.class)
1512
public class MixinBacktankUtil {
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package org.valkyrienskies.clockwork.mixin.content.gas;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.Direction;
5+
import net.minecraft.resources.ResourceLocation;
6+
import net.minecraft.server.level.ServerLevel;
7+
import net.minecraft.world.level.BlockGetter;
8+
import net.minecraft.world.level.Level;
9+
import net.minecraft.world.level.block.Block;
10+
import net.minecraft.world.level.block.ComposterBlock;
11+
import net.minecraft.world.level.block.state.BlockState;
12+
import org.jetbrains.annotations.NotNull;
13+
import org.joml.Vector3d;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Unique;
16+
import org.spongepowered.asm.mixin.injection.At;
17+
import org.spongepowered.asm.mixin.injection.Inject;
18+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
19+
import org.valkyrienskies.clockwork.ClockworkMod;
20+
import org.valkyrienskies.clockwork.content.logistics.gas.INodeBlock;
21+
import org.valkyrienskies.clockwork.content.logistics.gas.duct.IDuct;
22+
import org.valkyrienskies.clockwork.util.Vector3dUtilsKt;
23+
import org.valkyrienskies.kelvin.KelvinMod;
24+
import org.valkyrienskies.kelvin.api.*;
25+
import org.valkyrienskies.kelvin.api.nodes.PipeDuctNode;
26+
import org.valkyrienskies.kelvin.api.nodes.TankDuctNode;
27+
import org.valkyrienskies.kelvin.impl.DuctNetworkServer;
28+
import org.valkyrienskies.kelvin.impl.GasTypeRegistry;
29+
import org.valkyrienskies.kelvin.util.KelvinExtensions;
30+
import org.valkyrienskies.mod.common.VSGameUtilsKt;
31+
32+
import java.util.HashSet;
33+
import java.util.Random;
34+
35+
@Mixin(ComposterBlock.class)
36+
public class MixinComposterBlock extends Block implements INodeBlock {
37+
38+
@Unique
39+
Double vs_clockwork$$maxPressure = 100000.0;
40+
41+
42+
public MixinComposterBlock(Properties properties) {
43+
super(properties);
44+
}
45+
46+
@Inject(method = "tick", at = @At("HEAD"))
47+
public void vs_clockwork$$tick(BlockState state, ServerLevel level, BlockPos pos, Random random, CallbackInfo ci) {
48+
if (state.getValue(ComposterBlock.LEVEL) == 7) {
49+
DuctNetwork kelvin = ClockworkMod.getKelvin();
50+
ResourceLocation location = VSGameUtilsKt.getResourceKey(VSGameUtilsKt.getDimensionId(level)).location();
51+
DuctNodePos ductNodePos = new DuctNodePos(pos.getX(), pos.getY(), pos.getZ(), location);
52+
53+
double pressure = kelvin.getPressureAt(ductNodePos);
54+
55+
GasType gas = GasTypeRegistry.INSTANCE.getGasType(KelvinMod.MOD_ID,"methane");
56+
57+
if (pressure <= vs_clockwork$$maxPressure && gas != null) {
58+
kelvin.modGasMassOfTemperature(ductNodePos, gas, 10, 305);
59+
}
60+
}
61+
}
62+
63+
64+
@NotNull
65+
@Override
66+
public DuctNode createNode(@NotNull DuctNodePos pos) {
67+
return new PipeDuctNode(pos, NodeBehaviorType.PIPE, new HashSet<>(),0.05, 16375049.0, 1478.0);
68+
}
69+
70+
@Override
71+
public boolean canConnectTo(@NotNull BlockPos self, @NotNull BlockPos other, @NotNull Direction direction, @NotNull BlockGetter level) {
72+
return self.distSqr(other) <= 1.0 && direction != Direction.UP;
73+
}
74+
75+
@Override
76+
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
77+
nodeRemove(pState, pLevel, pPos, pState, pIsMoving);
78+
super.onRemove(pState, pLevel, pPos, pState, pIsMoving);
79+
}
80+
81+
@Override
82+
public void onPlace(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
83+
nodePlace(pState,pLevel,pPos,pState,pIsMoving);
84+
super.onPlace(pState, pLevel, pPos, pState, pIsMoving);
85+
86+
}
87+
88+
@Override
89+
public void nodePlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) {
90+
if (!level.isClientSide()) {
91+
if (state.isAir() || !(state.getBlock() instanceof INodeBlock)) {
92+
return;
93+
}
94+
ClockworkMod.getKelvin().addNode(KelvinExtensions.INSTANCE.toDuctNodePos(pos, level.dimension().location()), createNode(KelvinExtensions.INSTANCE.toDuctNodePos(pos, level.dimension().location())));
95+
}
96+
}
97+
98+
@Override
99+
public void nodeRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
100+
if (!level.isClientSide()) {
101+
if (newState.isAir() || !(newState.getBlock() instanceof INodeBlock)) {
102+
ClockworkMod.getKelvin().removeNode(KelvinExtensions.INSTANCE.toDuctNodePos(pos, level.dimension().location()));
103+
}
104+
}
105+
}
106+
107+
}

common/src/main/kotlin/org/valkyrienskies/clockwork/ClockworkMod.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ object ClockworkMod {
9797

9898
}
9999

100+
@JvmStatic
100101
fun getKelvin(): DuctNetworkServer {
101102
return KelvinMod.getKelvin() as DuctNetworkServer
102103
}

common/src/main/resources/vs_clockwork-common.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"compatibilityLevel": "JAVA_17",
55
"mixins": [
66
"MixinAbstractContraptionEntity",
7-
"MixinBacktankUtil",
87
"MixinBlockStateInfoProvider",
98
"MixinEntity",
109
"MixinLivingEntity",
@@ -15,6 +14,8 @@
1514
"accessors.IMixinClockworkContraption",
1615
"accessors.IMixinPistonContraption",
1716
"content.fan.MixinEncasedFanTileEntity",
17+
"content.gas.MixinBacktankUtil",
18+
"content.gas.MixinComposterBlock",
1819
"content.universal_joint.MixinRotationPropagator",
1920
"content.wing.MixinAbstractCauldronBlock"
2021
],

0 commit comments

Comments
 (0)