Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@

//ToDo Well, idk if getRingBlocks() should be relative... Maybe return absolute positions too. But not sure
public abstract class StargateAbstractMergeHelper {

/**
* @return {@link List} of {@link BlockPos} pointing to ring blocks. Positions are relative
*/
@Nonnull
public abstract List<BlockPos> getRingBlocks();

/**
* @return {@link List} of {@link BlockPos} pointing to chevron blocks. Positions are relative
*/
@Nonnull
public abstract List<BlockPos> getChevronBlocks();

private BlockPos topBlock = null;
private BlockPos topBlock = null;

/**
* For Classic gate returns top chevron position (relative).
* For Orlin's gate returns top ring position (no chevrons).
*
*
* @return Gate's top block.
*/
public BlockPos getTopBlock() {
Expand All @@ -59,139 +59,147 @@ public BlockPos getTopBlock() {

return topBlock;
}

/**
* @return {@link List} of {@link BlockPos} pointing to absent blocks of variant given. Positions are absolute.
*/
@Nonnull
public List<BlockPos> getAbsentBlockPositions(IBlockAccess world, BlockPos basePos, EnumFacing facing, EnumMemberVariant variant) {
List<BlockPos> blocks = null;

switch (variant) {
case CHEVRON:
blocks = getChevronBlocks();
break;

case RING:
blocks = getRingBlocks();
break;
}

return blocks.stream()
.map(pos -> pos.rotate(FacingToRotation.get(facing)).add(basePos))
.filter(pos -> !matchMember(world.getBlockState(pos)))
.collect(Collectors.toList());
.map(pos -> pos.rotate(FacingToRotation.get(facing)).add(basePos))
.filter(pos -> !matchMember(world.getBlockState(pos)))
.collect(Collectors.toList());
}

@Nullable
public abstract EnumMemberVariant getMemberVariantFromItemStack(ItemStack stack);

/**
* @return Max box where to search for the base.
*/
public abstract AunisAxisAlignedBB getBaseSearchBox();

/**
* @param state State of the block for the check.
*
* @return True if the {@link IBlockState} represents the Base block, false otherwise.
*/
public abstract boolean matchBase(IBlockState state);

/**
* @param state State of the block for the check.
*
* @return True if the {@link IBlockState} represents the Member block, false otherwise.
*/
public abstract boolean matchMember(IBlockState state);

/**
* @return Member block.
*/
public abstract StargateAbstractMemberBlock getMemberBlock();

/**
* Method searches for a {@link StargateMilkyWayBaseBlock} within {@link this#BASE_SEARCH_BOX}
* and returns it's {@link TileEntity}.
*
*
* @param blockAccess Usually {@link World}.
* @param memberPos Starting position.
* @param facing Facing of the member blocks.
* @param memberPos Starting position.
* @param facing Facing of the member blocks.
*
* @return {@link StargateMilkyWayBaseTile} if found, {@code null} otherwise.
*/
@Nullable
public StargateAbstractBaseTile findBaseTile(IBlockAccess blockAccess, BlockPos memberPos, EnumFacing facing) {
AunisAxisAlignedBB globalBox = getBaseSearchBox().rotate(facing).offset(memberPos);

for (MutableBlockPos pos : BlockPos.getAllInBoxMutable(globalBox.getMinBlockPos(), globalBox.getMaxBlockPos())) {
if (matchBase(blockAccess.getBlockState(pos))) {
return (StargateAbstractBaseTile) blockAccess.getTileEntity(pos.toImmutable());
}
}

return null;
}

/**
* Check the given {@link BlockPos} for the {@link StargateMilkyWayMemberBlock},
* it's correct variant and facing.
*
*
* @param blockAccess Usually {@link World}.
* @param pos {@link BlockPos} to be checked.
* @param facing Expected {@link EnumFacing}.
* @param variant Expected {@link EnumMemberVariant}.
* @param pos {@link BlockPos} to be checked.
* @param facing Expected {@link EnumFacing}.
* @param variant Expected {@link EnumMemberVariant}.
*
* @return {@code true} if the block matches given parameters, {@code false} otherwise.
*/
protected abstract boolean checkMemberBlock(IBlockAccess blockAccess, BlockPos pos, EnumFacing facing, EnumMemberVariant variant);

/**
* Called on block placement. Checks the found base block
* for other Stargate blocks and returns the result.
*
*
* @param blockAccess Usually {@link World}.
* @param basePos Found {@link StargateMilkyWayBaseBlock}.
* @param baseFacing Current base facing.
* @param basePos Found {@link StargateMilkyWayBaseBlock}.
* @param baseFacing Current base facing.
*
* @return {@code true} if the structure matches, {@code false} otherwise.
*/
public boolean checkBlocks(IBlockAccess blockAccess, BlockPos basePos, EnumFacing baseFacing) {
if (AunisConfig.debugConfig.checkGateMerge) {
public boolean checkBlocks(IBlockAccess blockAccess, BlockPos basePos, EnumFacing baseFacing) {
if (AunisConfig.debugConfig.checkGateMerge) {
for (BlockPos pos : getRingBlocks()) {
if (!checkMemberBlock(blockAccess, pos.rotate(FacingToRotation.get(baseFacing)).add(basePos), baseFacing, EnumMemberVariant.RING))
return false;
}

for (BlockPos pos : getChevronBlocks()) {
if (!checkMemberBlock(blockAccess, pos.rotate(FacingToRotation.get(baseFacing)).add(basePos), baseFacing, EnumMemberVariant.CHEVRON))
return false;
}
}

return true;
}

/**
* Updates merge status of the given block. Block is internally
* checked by {@link this#MEMBER_MATCHER}.
*
* @param world {@link World} instance.
* @param checkPos Position of the currently checked {@link StargateMilkyWayMemberBlock}.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of the base block
*
* @param world {@link World} instance.
* @param checkPos Position of the currently checked {@link StargateMilkyWayMemberBlock}.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of the base block
* @param shouldBeMerged {@code true} if the structure is merging, false otherwise.
*/
protected abstract void updateMemberMergeStatus(World world, BlockPos checkPos, BlockPos basePos, EnumFacing baseFacing, boolean shouldBeMerged);

/**
* Updates merge status of the Stargate.
*
* @param world {@link World} instance.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of {@link StargateMilkyWayBaseBlock}.
*
* @param world {@link World} instance.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of {@link StargateMilkyWayBaseBlock}.
* @param shouldBeMerged {@code true} if the structure is merging, false otherwise.
*/
public void updateMembersMergeStatus(World world, BlockPos basePos, EnumFacing baseFacing, boolean shouldBeMerged) {
for (BlockPos pos : getRingBlocks())
updateMemberMergeStatus(world, pos, basePos, baseFacing, shouldBeMerged);

for (BlockPos pos : getChevronBlocks())
updateMemberMergeStatus(world, pos, basePos, baseFacing, shouldBeMerged);
}

public void updateMembersBasePos(IBlockAccess blockAccess, BlockPos basePos, EnumFacing baseFacing) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,72 +16,73 @@
import net.minecraft.world.World;

public abstract class StargateClassicMergeHelper extends StargateAbstractMergeHelper {

protected boolean checkMemberBlock(IBlockAccess blockAccess, BlockPos pos, EnumFacing facing, EnumMemberVariant variant) {
IBlockState state = blockAccess.getBlockState(pos);

return matchMember(state) &&
state.getValue(AunisProps.FACING_HORIZONTAL) == facing &&
state.getValue(AunisProps.MEMBER_VARIANT) == variant;
state.getValue(AunisProps.FACING_HORIZONTAL) == facing &&
state.getValue(AunisProps.MEMBER_VARIANT) == variant;
}

protected void updateMemberMergeStatus(World world, BlockPos checkPos, BlockPos basePos, EnumFacing baseFacing, boolean shouldBeMerged) {
checkPos = checkPos.rotate(FacingToRotation.get(baseFacing)).add(basePos);
IBlockState state = world.getBlockState(checkPos);
if (matchMember(state)) {

if (matchMember(state)) {
StargateClassicMemberTile memberTile = (StargateClassicMemberTile) world.getTileEntity(checkPos);

if ((shouldBeMerged && !memberTile.isMerged()) || (memberTile.isMerged() && memberTile.getBasePos().equals(basePos))) {

ItemStack camoStack = memberTile.getCamoItemStack();
if (camoStack != null) {
InventoryHelper.spawnItemStack(world, checkPos.getX(), checkPos.getY(), checkPos.getZ(), camoStack);
}

if (memberTile.getCamoState() != null) {
memberTile.setCamoState(null);
}

// This also sets merge status
memberTile.setBasePos(shouldBeMerged ? basePos : null);

world.setBlockState(checkPos, state.withProperty(AunisProps.RENDER_BLOCK, !shouldBeMerged), 3);
}
}
}

/**
* Updates the {@link StargateMilkyWayBaseBlock} position of the
* {@link StargateMilkyWayMemberTile}.
*
*
* @param blockAccess Usually {@link World}.
* @param pos Position of the currently updated {@link StargateMilkyWayMemberBlock}.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of {@link StargateMilkyWayBaseBlock}.
* @param pos Position of the currently updated {@link StargateMilkyWayMemberBlock}.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of {@link StargateMilkyWayBaseBlock}.
*/
private void updateMemberBasePos(IBlockAccess blockAccess, BlockPos pos, BlockPos basePos, EnumFacing baseFacing) {
IBlockState state = blockAccess.getBlockState(pos);

if (matchMember(state)) {
if (matchMember(state)) {
StargateClassicMemberTile memberTile = (StargateClassicMemberTile) blockAccess.getTileEntity(pos);

memberTile.setBasePos(basePos);
}
}

/**
* Updates all {@link StargateMilkyWayMemberTile} to contain
* correct {@link StargateMilkyWayBaseBlock} position.
*
*
* @param blockAccess Usually {@link World}.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of {@link StargateMilkyWayBaseBlock}.
* @param basePos Position of {@link StargateMilkyWayBaseBlock} the tiles should be linked to.
* @param baseFacing Facing of {@link StargateMilkyWayBaseBlock}.
*/
@Override
public void updateMembersBasePos(IBlockAccess blockAccess, BlockPos basePos, EnumFacing baseFacing) {
for (BlockPos pos : getRingBlocks())
updateMemberBasePos(blockAccess, pos.rotate(FacingToRotation.get(baseFacing)).add(basePos), basePos, baseFacing);

for (BlockPos pos : getChevronBlocks())
updateMemberBasePos(blockAccess, pos.rotate(FacingToRotation.get(baseFacing)).add(basePos), basePos, baseFacing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ public StargatePos getStargate(StargateAddress address) {
}

public void addStargate(StargateAddress gateAddress, StargatePos stargatePos) {
if (gateAddress == null) return;
getMapFromAddress(gateAddress).put(gateAddress, stargatePos);

markDirty();
}

public void removeStargate(StargateAddress gateAddress) {
if (gateAddress == null) return;
getMapFromAddress(gateAddress).remove(gateAddress);

markDirty();
Expand Down
Loading