Skip to content

Commit

Permalink
formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skiprocks999 committed Jan 23, 2025
1 parent b14dec7 commit 1ec379b
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 123 deletions.
2 changes: 1 addition & 1 deletion runs/client/usercache.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"name":"Dev","uuid":"380df991-f603-344c-a090-369bad2a924a","expiresOn":"2025-02-14 16:53:57 -0600"}]
[{"name":"Dev","uuid":"380df991-f603-344c-a090-369bad2a924a","expiresOn":"2025-02-19 16:54:57 -0600"}]
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import electrodynamics.api.multiblock.subnodebased.Subnode;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;
import java.util.HashMap;

public interface IMultiblockParentBlock {

boolean hasMultiBlock();
Expand All @@ -18,4 +22,40 @@ default boolean isValidMultiblockPlacement(BlockState state, LevelReader worldIn
}
return true;
}

public static class SubnodeWrapper {

public static final SubnodeWrapper EMPTY = new SubnodeWrapper(new Subnode[0]);
private HashMap<Direction, Subnode[]> subnodeMap = new HashMap<>();
private Subnode[] omni = null;

private SubnodeWrapper(Subnode[] omni) {
this.omni = omni;
}

private SubnodeWrapper(Subnode[] north, Subnode[] east, Subnode[] south, Subnode[] west) {
subnodeMap.put(Direction.NORTH, north);
subnodeMap.put(Direction.EAST, east);
subnodeMap.put(Direction.SOUTH, south);
subnodeMap.put(Direction.WEST, west);
}

public Subnode[] getSubnodes(@Nullable Direction dir) {
if(omni != null) {
return omni;
}
return subnodeMap.getOrDefault(dir, new Subnode[0]);
}

public static SubnodeWrapper createOmni(Subnode[] omni) {
return new SubnodeWrapper(omni);
}

public static SubnodeWrapper createDirectional(Subnode[] north, Subnode[] east, Subnode[] south, Subnode[] west) {
return new SubnodeWrapper(north, east, south, west);
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface IMultiblockParentTile {

default void onNodeReplaced(Level world, BlockPos pos, boolean update) {

Subnode[] subnodes = getSubNodes();
Subnode[] subnodes = getSubNodes().getSubnodes(getFacingDirection());

Subnode subnode;

Expand Down Expand Up @@ -79,7 +79,7 @@ default void onNodePlaced(Level world, BlockPos pos, BlockState state, LivingEnt
onNodeReplaced(world, pos, true);
}

Subnode[] getSubNodes();
IMultiblockParentBlock.SubnodeWrapper getSubNodes();

default void onSubnodeNeighborChange(TileMultiSubnode subnode, BlockPos subnodeChangingNeighbor, boolean blockStateTrigger) {

Expand All @@ -103,9 +103,7 @@ default int getSubdnodeComparatorSignal(TileMultiSubnode subnode) {

void onSubnodeDestroyed(TileMultiSubnode subnode);

default Direction getFacingDirection() {
return Direction.NORTH;
}
Direction getFacingDirection();

default int getDirectSignal(TileMultiSubnode subnode, Direction dir) {
return 0;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/electrodynamics/api/tile/IMachine.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package electrodynamics.api.tile;

import electrodynamics.api.multiblock.subnodebased.Subnode;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentBlock;
import electrodynamics.common.block.voxelshapes.VoxelShapeProvider;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -20,8 +21,8 @@ public interface IMachine {

public boolean isPlayerStorable();

public default Subnode[] getSubnodes() {
return new Subnode[]{};
public default IMultiblockParentBlock.SubnodeWrapper getSubnodes() {
return IMultiblockParentBlock.SubnodeWrapper.EMPTY;
}

public VoxelShapeProvider getVoxelShapeProvider();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/electrodynamics/api/tile/MachineProperties.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package electrodynamics.api.tile;

import electrodynamics.api.multiblock.subnodebased.Subnode;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentBlock;
import electrodynamics.common.block.voxelshapes.VoxelShapeProvider;
import net.minecraft.world.level.block.RenderShape;

Expand All @@ -12,7 +13,7 @@ public class MachineProperties {
public RenderShape renderShape = RenderShape.MODEL;
public boolean propegatesLightDown = false;
public boolean isPlayerStorable = false;
public Subnode[] subnodes = new Subnode[0];
public IMultiblockParentBlock.SubnodeWrapper wrapper = IMultiblockParentBlock.SubnodeWrapper.EMPTY;
public VoxelShapeProvider provider = VoxelShapeProvider.DEFAULT;

public static final MachineProperties DEFAULT = new MachineProperties();
Expand Down Expand Up @@ -41,9 +42,9 @@ public MachineProperties setPlayerStorable() {
return this;
}

public MachineProperties setSubnodes(Subnode[] subnodes) {
public MachineProperties setSubnodes(IMultiblockParentBlock.SubnodeWrapper wrapper) {
isMultiblock = true;
this.subnodes = subnodes;
this.wrapper = wrapper;
return this;
}

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/electrodynamics/common/block/BlockMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import com.mojang.serialization.MapCodec;

import electrodynamics.api.multiblock.subnodebased.Subnode;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentBlock;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentTile;
import electrodynamics.api.tile.IMachine;
import electrodynamics.common.block.states.ElectrodynamicsBlockStates;
import electrodynamics.common.block.subtype.SubtypeMachine;
import electrodynamics.common.tile.machines.quarry.TileQuarry;
import electrodynamics.prefab.block.GenericMachineBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -25,11 +24,8 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition.Builder;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

public class BlockMachine extends GenericMachineBlock implements IMultiblockParentBlock {
public static final VoxelShape[] STANDARD_CUBE = new VoxelShape[]{Shapes.block(), Shapes.block(), Shapes.block(), Shapes.block(), Shapes.block(), Shapes.block()};

private final IMachine machine;

Expand All @@ -54,7 +50,7 @@ public boolean propagatesSkylightDown(BlockState pState, BlockGetter pLevel, Blo
public boolean canSurvive(BlockState state, LevelReader worldIn, BlockPos pos) {

if(machine.isMultiblock()) {
return isValidMultiblockPlacement(state, worldIn, pos, machine.getSubnodes());
return isValidMultiblockPlacement(state, worldIn, pos, machine.getSubnodes().getSubnodes(state.hasProperty(ElectrodynamicsBlockStates.FACING) ? state.getValue(ElectrodynamicsBlockStates.FACING) : Direction.NORTH));
}
return super.canSurvive(state, worldIn, pos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import electrodynamics.api.ISubtype;
import electrodynamics.api.multiblock.subnodebased.Subnode;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentBlock;
import electrodynamics.api.tile.IMachine;
import electrodynamics.api.tile.MachineProperties;
import electrodynamics.common.block.voxelshapes.ElectrodynamicsVoxelShapes;
Expand Down Expand Up @@ -93,13 +94,13 @@ public enum SubtypeMachine implements ISubtype, IMachine {
downgradetransformer(true, TileDowngradeTransformer::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.DOWNGRADE_TRANSFORMER)),
upgradetransformer(true, TileUpgradeTransformer::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.UPGRADE_TRANSFORMER)),
solarpanel(true, TileSolarPanel::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.SOLAR_PANEL)),
advancedsolarpanel(true, TileAdvancedSolarPanel::new, MachineProperties.builder().setSubnodes(Subnodes.SUBNODES_ADVANCEDSOLARPANEL).setShapeProvider(ElectrodynamicsVoxelShapes.ADVANCED_SOLAR_PANEL)),
advancedsolarpanel(true, TileAdvancedSolarPanel::new, MachineProperties.builder().setSubnodes(Subnodes.ADVANCEDSOLARPANEL).setShapeProvider(ElectrodynamicsVoxelShapes.ADVANCED_SOLAR_PANEL)),
electricpump(true, TileElectricPump::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.ELECTRIC_PUMP)),
thermoelectricgenerator(true, TileThermoelectricGenerator::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.THERMOELECTRIC_GENERATOR)),
fermentationplant(true, TileFermentationPlant::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.FERMENTATION_PLANT)),
combustionchamber(true, TileCombustionChamber::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.COMBUSTION_CHAMBER)),
hydroelectricgenerator(true, TileHydroelectricGenerator::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.HYDROELECTRIC_GENERATOR)),
windmill(true, TileWindmill::new, MachineProperties.builder().setSubnodes(Subnodes.SUBNODES_WINDMILL).setShapeProvider(ElectrodynamicsVoxelShapes.WINDMILL)),
windmill(true, TileWindmill::new, MachineProperties.builder().setSubnodes(Subnodes.WINDMILL).setShapeProvider(ElectrodynamicsVoxelShapes.WINDMILL)),
mineralwasher(true, TileMineralWasher::new),
chemicalmixer(true, TileChemicalMixer::new, MachineProperties.builder().setRenderShape(RenderShape.ENTITYBLOCK_ANIMATED)),
chemicalcrystallizer(true, TileChemicalCrystallizer::new, MachineProperties.builder().setShapeProvider(ElectrodynamicsVoxelShapes.CHEMICAL_CRYSTALIZER)),
Expand Down Expand Up @@ -201,8 +202,8 @@ public boolean isPlayerStorable() {
}

@Override
public Subnode[] getSubnodes() {
return properties.subnodes;
public IMultiblockParentBlock.SubnodeWrapper getSubnodes() {
return properties.wrapper;
}

@Override
Expand All @@ -222,27 +223,33 @@ public boolean showInItemGroup() {

public static class Subnodes {

public static final Subnode[] SUBNODES_WINDMILL = {new Subnode(
public static final IMultiblockParentBlock.SubnodeWrapper WINDMILL = IMultiblockParentBlock.SubnodeWrapper.createOmni(
//
new BlockPos(0, 1, 0),
//
new VoxelShape[]{
//
Shapes.block(),
//
Shapes.block(),
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(5, 10, 3, 11, 16, 13)),
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(5, 10, 3, 11, 16, 13)),
new Subnode[]{
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(3, 10, 5, 13, 16, 11)),
new Subnode(
//
new BlockPos(0, 1, 0),
//
new VoxelShape[]{
//
Shapes.block(),
//
Shapes.block(),
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(5, 10, 3, 11, 16, 13)),
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(5, 10, 3, 11, 16, 13)),
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(3, 10, 5, 13, 16, 11)),
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(3, 10, 5, 13, 16, 11))
})
//
Shapes.or(Block.box(5, 0, 5, 11, 16, 11), Block.box(3, 10, 5, 13, 16, 11))
})
};

public static final Subnode[] SUBNODES_ADVANCEDSOLARPANEL = make(() -> {
}
//
);
public static final IMultiblockParentBlock.SubnodeWrapper ADVANCEDSOLARPANEL = IMultiblockParentBlock.SubnodeWrapper.createOmni(make(() -> {

Subnode[] subnodes = new Subnode[9];

Expand All @@ -269,7 +276,7 @@ public static class Subnodes {

return subnodes;

});
}));


public static Subnode[] make(Supplier<Subnode[]> maker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public VoxelShape getShape() {

if (level.getBlockEntity(parentPos.get()) instanceof IMultiblockParentTile node) {

return shapeCache = node.getSubNodes()[nodeIndex.get()].getShape(node.getFacingDirection());
return shapeCache = node.getSubNodes().getSubnodes(node.getFacingDirection())[nodeIndex.get()].getShape(node.getFacingDirection());

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package electrodynamics.common.tile.electricitygrid.generators;

import electrodynamics.api.multiblock.subnodebased.Subnode;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentBlock;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentTile;
import electrodynamics.common.block.subtype.SubtypeMachine;
import electrodynamics.common.inventory.container.tile.ContainerSolarPanel;
Expand Down Expand Up @@ -44,8 +44,8 @@ public TransferPack getProduced() {
}

@Override
public Subnode[] getSubNodes() {
return SubtypeMachine.Subnodes.SUBNODES_ADVANCEDSOLARPANEL;
public IMultiblockParentBlock.SubnodeWrapper getSubNodes() {
return SubtypeMachine.Subnodes.ADVANCEDSOLARPANEL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package electrodynamics.common.tile.electricitygrid.generators;

import electrodynamics.api.multiblock.subnodebased.Subnode;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentBlock;
import electrodynamics.api.multiblock.subnodebased.parent.IMultiblockParentTile;
import electrodynamics.common.block.subtype.SubtypeMachine;
import electrodynamics.common.inventory.container.tile.ContainerWindmill;
Expand Down Expand Up @@ -110,8 +110,8 @@ public boolean shouldPlaySound() {
}

@Override
public Subnode[] getSubNodes() {
return SubtypeMachine.Subnodes.SUBNODES_WINDMILL;
public IMultiblockParentBlock.SubnodeWrapper getSubNodes() {
return SubtypeMachine.Subnodes.WINDMILL;
}

@Override
Expand Down
Loading

0 comments on commit 1ec379b

Please sign in to comment.