This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/structure/researchcomplex/ResearchComplexStartPart.java

116 lines
5.2 KiB
Java

package com.thebrokenrail.energonrelics.structure.researchcomplex;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.entity.reactor.ReactorControllerBlockEntity;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import com.thebrokenrail.energonrelics.structure.StructureContext;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.LeverBlock;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.StairShape;
import net.minecraft.block.enums.WallMountLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import java.util.List;
public class ResearchComplexStartPart extends BaseResearchComplexPart {
public ResearchComplexStartPart(ResearchComplexState state, List<Transformation> list) {
super(state, list);
}
private void setBlockOrAir(BlockPos pos, BlockState state) {
if (pos.getY() == 1 || pos.getY() == 4) {
set(pos, state);
} else {
BlockState air = Blocks.AIR.getDefaultState();
set(pos, air);
}
}
private void buildBase(int yOffset) {
BlockState bricks = Blocks.QUARTZ_BRICKS.getDefaultState();
BlockState air = Blocks.AIR.getDefaultState();
BlockState state = yOffset == 0 || yOffset == 5 ? bricks : air;
rect(new BlockPos(0, yOffset, 0), 2, 1, 6, state);
rect(new BlockPos(0, yOffset, 0), 6, 1, 2, state);
set(new BlockPos(2, yOffset, 3), state);
set(new BlockPos(3, yOffset, 2), state);
set(new BlockPos(2, yOffset, 2), state);
if (yOffset != 0 && yOffset != 5) {
BlockState stairs = Blocks.QUARTZ_STAIRS.getDefaultState();
BlockHalf half = yOffset == 1 ? BlockHalf.BOTTOM : BlockHalf.TOP;
stairs = stairs.with(StairsBlock.HALF, half);
BlockState eastStairs = stairs.with(StairsBlock.FACING, Direction.EAST);
BlockState southStairs = stairs.with(StairsBlock.FACING, Direction.SOUTH);
BlockState outerLeftStairs = southStairs.with(StairsBlock.SHAPE, StairShape.OUTER_LEFT);
BlockState innerLeftStairs = southStairs.with(StairsBlock.SHAPE, StairShape.INNER_LEFT);
BlockState innerRightStairs = eastStairs.with(StairsBlock.SHAPE, StairShape.INNER_RIGHT);
BlockState outerRightStairs = eastStairs.with(StairsBlock.SHAPE, StairShape.OUTER_RIGHT);
setBlockOrAir(new BlockPos(2, yOffset, 5), eastStairs);
setBlockOrAir(new BlockPos(2, yOffset, 4), outerLeftStairs);
setBlockOrAir(new BlockPos(3, yOffset, 4), innerRightStairs);
setBlockOrAir(new BlockPos(3, yOffset, 3), outerLeftStairs);
setBlockOrAir(new BlockPos(4, yOffset, 3), innerLeftStairs);
setBlockOrAir(new BlockPos(4, yOffset, 2), outerRightStairs);
setBlockOrAir(new BlockPos(5, yOffset, 2), southStairs);
if (yOffset != 1 && yOffset != 4) {
set(new BlockPos(3, yOffset, 5), bricks);
set(new BlockPos(4, yOffset, 4), bricks);
set(new BlockPos(5, yOffset, 3), bricks);
}
}
if (yOffset == 5) {
set(new BlockPos(2, yOffset, 2), EnergonRelics.Blocks.ENERGON_LIGHT.getDefaultState());
}
}
private void buildReactor() {
set(new BlockPos(0, 1, 0), EnergonRelics.Blocks.THERMAL_CASING.getDefaultState());
set(new BlockPos(1, 2, 0), EnergonRelics.Blocks.THERMAL_CASING.getDefaultState());
set(new BlockPos(0, 2, 0), EnergonRelics.Blocks.REACTOR_CORE.getDefaultState());
set(new BlockPos(-1, 2, 0), EnergonRelics.Blocks.THERMAL_CASING.getDefaultState());
set(new BlockPos(0, 3, 0), EnergonRelics.Blocks.REACTOR_INPUT.getDefaultState());
set(new BlockPos(0, 2, -1), EnergonRelics.Blocks.REACTOR_CONTROLLER.getDefaultState());
set(new BlockPos(0, 1, -1), Blocks.LEVER.getDefaultState().with(LeverBlock.FACE, WallMountLocation.FLOOR));
set(new BlockPos(0, 2, 1), EnergonRelics.Blocks.THERMAL_GLASS.getDefaultState());
}
@Override
protected void build(StructureContext context) {
if (getState().hasEnergy(HardcodedConfig.ENERGON_LIGHT_ENERGY_REQUIRED * 4, new BlockPos(0, 2, 0))) {
rotate(() -> {
for (int i = 0; i < 6; i++) {
buildBase(i);
}
part(context, new BlockPos(-3, 0, 6), new ResearchComplexHallwayPart(getState(), getTransformations(), true, 1, 1));
});
buildReactor();
}
}
@Override
protected void handleBlockPlace(World world, BlockPos pos, BlockState state) {
super.handleBlockPlace(world, pos, state);
if (state.getBlock() == EnergonRelics.Blocks.REACTOR_CONTROLLER) {
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof ReactorControllerBlockEntity) {
((ReactorControllerBlockEntity) entity).placeStack(EnergonRelics.Items.NETWORK_CHIP_ITEM.create(getState().getMainNetwork()), world);
}
}
}
}