|
| 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 | +} |
0 commit comments