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/ResearchComplexHallwayPart....

103 lines
4.3 KiB
Java
Raw Normal View History

2020-07-19 19:12:39 +00:00
package com.thebrokenrail.energonrelics.structure.researchcomplex;
2020-07-20 21:03:17 +00:00
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
2020-07-19 19:12:39 +00:00
import com.thebrokenrail.energonrelics.structure.StructureContext;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
2020-07-20 21:03:17 +00:00
import net.minecraft.block.StairsBlock;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
2020-07-19 19:12:39 +00:00
2020-07-20 21:03:17 +00:00
import java.util.ArrayList;
2020-07-19 19:12:39 +00:00
import java.util.List;
public class ResearchComplexHallwayPart extends BaseResearchComplexPart {
2020-07-20 21:03:17 +00:00
private final boolean hasLight;
private int rightRoomPadding;
private int leftRoomPadding;
2020-07-22 01:23:33 +00:00
private static final float ROOM_CHANCE = 0.45f;
2020-07-20 21:03:17 +00:00
public ResearchComplexHallwayPart(ResearchComplexState state, List<Transformation> list, boolean hasLight, int rightRoomPadding, int leftRoomPadding) {
2020-07-19 19:12:39 +00:00
super(state, list);
2020-07-20 21:03:17 +00:00
this.hasLight = hasLight;
this.rightRoomPadding = rightRoomPadding;
this.leftRoomPadding = leftRoomPadding;
2020-07-19 19:12:39 +00:00
}
2020-07-22 01:23:33 +00:00
private static final int HEIGHT = 6;
2020-07-19 19:12:39 +00:00
2020-07-22 01:23:33 +00:00
private static final int DEPTH = 3;
2020-07-19 19:12:39 +00:00
@Override
protected void build(StructureContext context) {
BlockState bricks = Blocks.QUARTZ_BRICKS.getDefaultState();
2020-07-20 21:03:17 +00:00
if (!hasLight || getState().hasEnergy(HardcodedConfig.ENERGON_LIGHT_ENERGY_REQUIRED, getPosFromOrigin(new BlockPos(3, 5, 1)))) {
BlockState air = Blocks.AIR.getDefaultState();
BlockState stairs = Blocks.QUARTZ_STAIRS.getDefaultState();
BlockState westStairs = stairs.with(StairsBlock.FACING, Direction.WEST);
BlockState eastStairs = stairs.with(StairsBlock.FACING, Direction.EAST);
2020-07-22 01:23:33 +00:00
for (int y = 0; y < HEIGHT; y++) {
BlockState state = y == 0 || y == HEIGHT - 1 ? bricks : air;
if (y > 1 && y < HEIGHT - 2) {
rect(new BlockPos(1, y, 0), 5, 1, DEPTH, air);
rect(new BlockPos(0, y, 0), 1, 1, DEPTH, bricks);
rect(new BlockPos(6, y, 0), 1, 1, DEPTH, bricks);
2020-07-20 21:03:17 +00:00
} else {
2020-07-22 01:23:33 +00:00
rect(new BlockPos(2, y, 0), 3, 1, DEPTH, state);
2020-07-20 21:03:17 +00:00
}
2020-07-22 01:23:33 +00:00
if (y == 1 || y == HEIGHT - 2) {
if (y == HEIGHT - 2) {
2020-07-20 21:03:17 +00:00
eastStairs = eastStairs.with(StairsBlock.HALF, BlockHalf.TOP);
westStairs = westStairs.with(StairsBlock.HALF, BlockHalf.TOP);
}
2020-07-22 01:23:33 +00:00
rect(new BlockPos(1, y, 0), 1, 1, DEPTH, westStairs);
rect(new BlockPos(5, y, 0), 1, 1, DEPTH, eastStairs);
2020-07-20 21:03:17 +00:00
}
}
if (hasLight) {
2020-08-20 23:03:47 +00:00
set(new BlockPos(3, 5, 1), EnergonRelics.Blocks.ENERGON_LIGHT.getDefaultState());
2020-07-19 19:12:39 +00:00
}
2020-07-20 21:03:17 +00:00
if (leftRoomPadding == 0) {
if (getState().random.nextFloat() <= ROOM_CHANCE) {
AbstractResearchComplexRoomPart room = AbstractResearchComplexRoomPart.get(getState(), getRoomTransformation(true));
part(context, new BlockPos(5, 1, 1), room);
leftRoomPadding = room.getWidth();
}
} else {
leftRoomPadding = leftRoomPadding - 1;
}
if (rightRoomPadding == 0) {
if (getState().random.nextFloat() <= ROOM_CHANCE) {
AbstractResearchComplexRoomPart room = AbstractResearchComplexRoomPart.get(getState(), getRoomTransformation(false));
part(context, new BlockPos(1, 1, 1), room);
rightRoomPadding = room.getWidth();
}
} else {
rightRoomPadding = rightRoomPadding - 1;
}
2020-07-22 01:23:33 +00:00
part(context, new BlockPos(0, 0, DEPTH), new ResearchComplexHallwayPart(getState(), getTransformations(), !hasLight, rightRoomPadding, leftRoomPadding));
2020-07-20 21:03:17 +00:00
} else {
rect(new BlockPos(1, 1, 0), 5, 4, 1, bricks);
}
}
private List<Transformation> getRoomTransformation(boolean mirror) {
List<Transformation> list = new ArrayList<>();
if (mirror) {
2020-07-22 01:23:33 +00:00
list.add(MIRROR_DEPTH);
2020-07-19 19:12:39 +00:00
}
2020-07-20 21:03:17 +00:00
list.addAll(getTransformations());
list.add(com.thebrokenrail.energonrelics.structure.StructurePart.CLOCKWISE_90);
return list;
2020-07-19 19:12:39 +00:00
}
}