Skip to content

Commit

Permalink
Overhaul radio tower to accept energy and a control signal for loadin…
Browse files Browse the repository at this point in the history
…g frequencies
  • Loading branch information
BluSunrize committed Jul 22, 2024
1 parent a6ed8cc commit 261800a
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import blusunrize.immersiveengineering.api.multiblocks.blocks.env.IMultiblockLevel;
import blusunrize.immersiveengineering.api.multiblocks.blocks.logic.IMultiblockLogic;
import blusunrize.immersiveengineering.api.multiblocks.blocks.logic.IMultiblockState;
import blusunrize.immersiveengineering.api.multiblocks.blocks.util.CapabilityPosition;
import blusunrize.immersiveengineering.api.multiblocks.blocks.util.RelativeBlockFace;
import blusunrize.immersiveengineering.api.multiblocks.blocks.util.ShapeType;
import blusunrize.immersiveengineering.api.wires.redstone.CapabilityRedstoneNetwork;
import blusunrize.immersiveengineering.api.wires.redstone.CapabilityRedstoneNetwork.RedstoneBundleConnection;
Expand All @@ -36,6 +38,7 @@
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.capabilities.Capabilities.EnergyStorage;

import java.util.Arrays;
import java.util.List;
Expand All @@ -49,7 +52,9 @@ public class RadioTowerLogic
public static final int FREQUENCY_MAX = 384;
public static final int ENERGY_CAPACITY = 64000;

public static final BlockPos REDSTONE_POS = new BlockPos(2, 1, 5);
private static final CapabilityPosition ENERGY_INPUT = new CapabilityPosition(1, 1, 5, RelativeBlockFace.UP);
private static final CapabilityPosition IO_CONNECTION = new CapabilityPosition(2, 1, 5, RelativeBlockFace.UP);
private static final CapabilityPosition CONTROL_CONNECTION = new CapabilityPosition(3, 1, 5, RelativeBlockFace.UP);
public static final BlockPos BROADCAST_POS = new BlockPos(2, 13, 2);

@Override
Expand Down Expand Up @@ -116,7 +121,9 @@ public State createInitialState(IInitialMultiblockContext<State> capabilitySourc
@Override
public void registerCapabilities(CapabilityRegistrar<State> register)
{
register.registerAtBlockPos(CapabilityRedstoneNetwork.REDSTONE_BUNDLE_CONNECTION, REDSTONE_POS, state -> state.bundleConnection);
register.registerAt(EnergyStorage.BLOCK, ENERGY_INPUT, state -> state.energy);
register.registerAt(CapabilityRedstoneNetwork.REDSTONE_BUNDLE_CONNECTION, IO_CONNECTION, state -> state.bundleConnection);
register.registerAt(CapabilityRedstoneNetwork.REDSTONE_BUNDLE_CONNECTION, CONTROL_CONNECTION, state -> state.controlConnection);
}

@Override
Expand All @@ -135,6 +142,7 @@ public static class State implements IMultiblockState, IWirelessRedstoneComponen
{
public final AveragingEnergyStorage energy = new AveragingEnergyStorage(ENERGY_CAPACITY);
private final RedstoneBundleConnection bundleConnection;
private final RedstoneBundleConnection controlConnection;
public int frequency = 142;
public int[] savedFrequencies = new int[16];
public int rangeInChunks = -1;
Expand All @@ -146,13 +154,6 @@ public static class State implements IMultiblockState, IWirelessRedstoneComponen

public State(IInitialMultiblockContext<State> ctx)
{
// this.mifHandler = () -> new MachineCheckImplementation[]{
// new MachineCheckImplementation<>((BooleanSupplier)() -> this.active, MachineInterfaceHandler.BASIC_ACTIVE),
// new MachineCheckImplementation<>(insertionHandler, MachineInterfaceHandler.BASIC_ITEM_IN),
// new MachineCheckImplementation<>(extractionHandler, MachineInterfaceHandler.BASIC_ITEM_OUT),
// new MachineCheckImplementation<>(fluidHandler, MachineInterfaceHandler.BASIC_FLUID_OUT),
// new MachineCheckImplementation<>(energy, MachineInterfaceHandler.BASIC_ENERGY),
// };
bundleConnection = new RedstoneBundleConnection()
{
@Override
Expand All @@ -172,6 +173,23 @@ public void updateInput(byte[] signals, Direction side)
signals[i] = (byte)Math.max(signals[i], receivedSignals[i]);
}
};
controlConnection = new RedstoneBundleConnection()
{
@Override
public void onChange(byte[] externalInputs, Direction side)
{
int maxSignal = 0;
int maxIdx = -1;
for(int i = 0; i < externalInputs.length; i++)
if(externalInputs[i] > maxSignal)
{
maxSignal = externalInputs[i];
maxIdx = i;
}
if(maxIdx >= 0)
frequency = savedFrequencies[maxIdx];
}
};
// initial fill
Arrays.fill(savedFrequencies, frequency);
}
Expand Down

0 comments on commit 261800a

Please sign in to comment.