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

131 lines
5.1 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(int x, int y, int z, BlockState stairs) {
if (y == 1 || y == 4) {
set(x, y, z, stairs);
} else {
BlockState air = Blocks.AIR.getDefaultState();
set(x, y, z, 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(4, yOffset, 0, 3, 1, getDepth(), state);
rect(0, yOffset, 4, getWidth(), 1, 3, state);
set(2, yOffset, 3, state);
set(3, yOffset, 2, state);
set(3, yOffset, 3, 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 westStairs = stairs.with(StairsBlock.FACING, Direction.WEST);
BlockState northStairs = stairs.with(StairsBlock.FACING, Direction.NORTH);
BlockState outerLeftStairs = northStairs.with(StairsBlock.SHAPE, StairShape.OUTER_LEFT);
BlockState innerLeftStairs = northStairs.with(StairsBlock.SHAPE, StairShape.INNER_LEFT);
BlockState innerRightStairs = westStairs.with(StairsBlock.SHAPE, StairShape.INNER_RIGHT);
BlockState outerRightStairs = westStairs.with(StairsBlock.SHAPE, StairShape.OUTER_RIGHT);
setBlockOrAir(3, yOffset, 0, westStairs);
setBlockOrAir(3, yOffset, 1, outerLeftStairs);
setBlockOrAir(2, yOffset, 1, innerRightStairs);
setBlockOrAir(2, yOffset, 2, outerLeftStairs);
setBlockOrAir(1, yOffset, 2, innerLeftStairs);
setBlockOrAir(1, yOffset, 3, outerRightStairs);
setBlockOrAir(0, yOffset, 3, northStairs);
if (yOffset != 1 && yOffset != 4) {
set(2, yOffset, 0, bricks);
set(1, yOffset, 1, bricks);
set(0, yOffset, 2, bricks);
}
}
if (yOffset == 5) {
set(3, yOffset, 3, EnergonRelics.ENERGON_LIGHT_BLOCK.getDefaultState());
}
}
private void buildReactor() {
set(5, 1, 5, EnergonRelics.THERMAL_CASING_BLOCK.getDefaultState());
set(6, 2, 5, EnergonRelics.THERMAL_CASING_BLOCK.getDefaultState());
set(5, 2, 5, EnergonRelics.REACTOR_CORE_BLOCK.getDefaultState());
set(4, 2, 5, EnergonRelics.THERMAL_CASING_BLOCK.getDefaultState());
set(5, 3, 5, EnergonRelics.REACTOR_INPUT_BLOCK.getDefaultState());
set(5, 2, 4, EnergonRelics.REACTOR_CONTROLLER_BLOCK.getDefaultState());
set(5, 1, 4, Blocks.LEVER.getDefaultState().with(LeverBlock.FACE, WallMountLocation.FLOOR));
set(5, 2, 6, EnergonRelics.THERMAL_GLASS_BLOCK.getDefaultState());
}
@Override
protected void build(StructureContext context) {
if (getState().hasEnergy(HardcodedConfig.ENERGON_LIGHT_ENERGY_REQUIRED * 4)) {
repeat(() -> {
for (int i = 0; i < 6; i++) {
buildBase(i);
}
part(context, 1, 0, getDepth(), new ResearchComplexHallwayPart(getState(), getTransformations()));
});
buildReactor();
}
}
@Override
protected int getWidth() {
return 10;
}
@Override
protected int getHeight() {
return 6;
}
@Override
protected int getDepth() {
return 10;
}
@Override
protected void handleBlockPlace(World world, BlockPos pos, BlockState state) {
super.handleBlockPlace(world, pos, state);
if (state.getBlock() == EnergonRelics.REACTOR_CONTROLLER_BLOCK) {
BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof ReactorControllerBlockEntity) {
((ReactorControllerBlockEntity) entity).placeStack(EnergonRelics.NETWORK_CHIP_ITEM.create(getState().getMainNetwork()));
}
}
}
}