coolant improvements
This commit is contained in:
parent
7072a25ac4
commit
8089051c00
|
@ -2,13 +2,18 @@ package uk.gemwire.engage;
|
|||
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import uk.gemwire.engage.block.coolant.CoolantBaseBlock;
|
||||
import uk.gemwire.engage.registries.Blocks;
|
||||
import uk.gemwire.engage.registries.Fluids;
|
||||
import uk.gemwire.engage.registries.Items;
|
||||
import uk.gemwire.engage.registries.Worldgen;
|
||||
import uk.gemwire.engage.registries.fluid.FluidDeferredRegister;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Engage adds four varieties of Warp Core for power generation, based on:
|
||||
* - The Defiant
|
||||
|
@ -62,5 +67,11 @@ public class Engage {
|
|||
Fluids.FLUIDS_REGISTRY.register(bus);
|
||||
Worldgen.CARVER_REGISTRY.register(bus);
|
||||
Worldgen.BIOME_MODIFIER_SERIALIZERS.register(bus);
|
||||
|
||||
bus.addListener(this::commonSetup);
|
||||
}
|
||||
|
||||
public void commonSetup(FMLCommonSetupEvent e) {
|
||||
e.enqueueWork(() -> CoolantBaseBlock.VALID_COOLANT_BLOCKS = Set.of(Blocks.COMPRESSOR_BLOCK.block().get(), Blocks.COPPER_TUBE_BLOCK.block().get(), Blocks.COOLANT_METERING_BLOCK.block().get(), Blocks.COOLANT_HEAT_SPREADER_BLOCK.block().get()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.*;
|
|||
public class CoolantBaseBlock extends Block {
|
||||
static Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
static Set<Block> VALID_COOLANT_BLOCKS = Set.of(Blocks.COMPRESSOR_BLOCK.block().get(), Blocks.COPPER_TUBE_BLOCK.block().get(), Blocks.COOLANT_HEAT_SPREADER_BLOCK.block().get(), Blocks.COOLANT_METERING_BLOCK.block().get());
|
||||
public static Set<Block> VALID_COOLANT_BLOCKS;
|
||||
|
||||
public CoolantBaseBlock(Properties p_49795_) {
|
||||
super(p_49795_);
|
||||
|
@ -29,14 +29,14 @@ public class CoolantBaseBlock extends Block {
|
|||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
searchForValidNetwork(new BlockPos.MutableBlockPos(pos.getX(), pos.getY(), pos.getZ()), level);
|
||||
//searchForValidNetwork(new BlockPos.MutableBlockPos(pos.getX(), pos.getY(), pos.getZ()), level);
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
LOGGER.info("Discovery took " + (endTime - startTime) + "ms");
|
||||
}
|
||||
|
||||
private Set<Transition> getValidTransitionsFrom(NetworkState state, Level level) {
|
||||
Set<Transition> dirs = new HashSet<>();
|
||||
private Queue<Transition> getValidTransitionsFrom(NetworkState state, Level level) {
|
||||
Queue<Transition> dirs = new ArrayDeque<>();
|
||||
for (Direction dir : Direction.values()) {
|
||||
if (state.lastTransition != null && dir == state.lastTransition) continue;
|
||||
BlockPos newPos = state.currentPos.relative(dir);
|
||||
|
@ -75,7 +75,7 @@ public class CoolantBaseBlock extends Block {
|
|||
|
||||
while(!queue.isEmpty()) {
|
||||
// The search loop
|
||||
search(queue.element(), level, queue);
|
||||
search(level, queue);
|
||||
|
||||
// Try to finalise stuff - we gotta have everything in our network.
|
||||
// First, check that the last remaining direction takes us into a block we've already visited (the closed loop)
|
||||
|
@ -93,37 +93,40 @@ public class CoolantBaseBlock extends Block {
|
|||
}
|
||||
}
|
||||
}
|
||||
queue.poll();
|
||||
}
|
||||
|
||||
LOGGER.info("Valid coolant loop!");
|
||||
return true;
|
||||
}
|
||||
|
||||
void search(StateTransitions st, Level level, Queue<StateTransitions> queue) {
|
||||
while (st.transitions.size() > 1) {
|
||||
void search(Level level, Queue<StateTransitions> queue) {
|
||||
StateTransitions currentState = queue.peek();
|
||||
while (currentState.transitions.size() > 1) {
|
||||
// Traverse the new block
|
||||
Transition transition = st.transitions.iterator().next();
|
||||
st.state.lastTransition = transition.dir();
|
||||
st.state.currentPos = transition.pos();
|
||||
Transition transition = currentState.transitions.iterator().next();
|
||||
currentState.state.lastTransition = transition.dir();
|
||||
currentState.state.currentPos = transition.pos();
|
||||
|
||||
Block reachedBlock = transition.state().getBlock();
|
||||
|
||||
LOGGER.info("Traversing through " + st.state.lastTransition + " to " + st.state.currentPos + ", which is a " + getBlockName(reachedBlock));
|
||||
st.state.visited.add(st.state.currentPos);
|
||||
LOGGER.info("Traversing through " + currentState.state.lastTransition + " to " + currentState.state.currentPos + ", which is a " + getBlockName(reachedBlock));
|
||||
currentState.state.visited.add(currentState.state.currentPos);
|
||||
|
||||
// If we reached a metering block for the first time
|
||||
if (reachedBlock == Blocks.COOLANT_METERING_BLOCK.block().get()) {
|
||||
st.state.metering();
|
||||
currentState.state.metering();
|
||||
// The compressor has its own things to check..
|
||||
} else if (reachedBlock == Blocks.COMPRESSOR_BLOCK.block().get()) {
|
||||
st.state.compressor();
|
||||
currentState.state.compressor();
|
||||
// Heat spreaders may have many, so we just flip the flag to be true if we're just getting to one now.
|
||||
} else if (reachedBlock == Blocks.COOLANT_HEAT_SPREADER_BLOCK.block().get()) {
|
||||
if (!st.state.spreader) st.state.spreader = true;
|
||||
if (!currentState.state.spreader) currentState.state.spreader = true;
|
||||
}
|
||||
|
||||
Set<Transition> newTransitions = getValidTransitionsFrom(st.state, level);
|
||||
queue.add(new StateTransitions(st.state.copy(), newTransitions));
|
||||
Queue<Transition> newTransitions = getValidTransitionsFrom(currentState.state, level);
|
||||
queue.add(new StateTransitions(currentState.state.copy(), newTransitions));
|
||||
currentState = queue.peek();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,5 +190,5 @@ public class CoolantBaseBlock extends Block {
|
|||
}
|
||||
}
|
||||
|
||||
record StateTransitions(NetworkState state, Set<Transition> transitions) {}
|
||||
record StateTransitions(NetworkState state, Queue<Transition> transitions) {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user