This commit is contained in:
James Seibel
2024-07-02 17:08:55 -05:00
parent 55cb4595bd
commit 3b4a0ff4bc
4 changed files with 72 additions and 15 deletions
@@ -191,7 +191,7 @@ public abstract class AbstractDhLevel implements IDhLevel
{
if (this.beaconBeamRepo != null)
{
return this.beaconBeamRepo.getAllBeamsForSectionPos(pos);
return this.beaconBeamRepo.getAllBeamsForPos(pos);
}
else
{
@@ -221,7 +221,7 @@ public abstract class AbstractDhLevel implements IDhLevel
}
// get existing beams
List<BeaconBeamDTO> existingBeamList = this.beaconBeamRepo.getAllBeamsForSectionPos(pos);
List<BeaconBeamDTO> existingBeamList = this.beaconBeamRepo.getAllBeamsForPos(chunkPos);
HashMap<DhBlockPos, BeaconBeamDTO> existingBeamByPos = new HashMap<>(existingBeamList.size());
for (int i = 0; i < existingBeamList.size(); i++)
{
@@ -296,7 +296,7 @@ public abstract class AbstractDhLevel implements IDhLevel
if (this.beaconBeamRepo != null)
{
// get beams in pos
List<BeaconBeamDTO> existingBeamList = this.beaconBeamRepo.getAllBeamsForSectionPos(pos);
List<BeaconBeamDTO> existingBeamList = this.beaconBeamRepo.getAllBeamsForPos(pos);
for (int i = 0; i < existingBeamList.size(); i++)
{
BeaconBeamDTO beam = existingBeamList.get(i);
@@ -334,7 +334,7 @@ public abstract class AbstractDhLevel implements IDhLevel
if (this.beaconBeamRepo != null)
{
// get beams in pos
List<BeaconBeamDTO> existingBeamList = this.beaconBeamRepo.getAllBeamsForSectionPos(pos);
List<BeaconBeamDTO> existingBeamList = this.beaconBeamRepo.getAllBeamsForPos(pos);
for (int i = 0; i < existingBeamList.size(); i++)
{
BeaconBeamDTO beam = existingBeamList.get(i);
@@ -74,6 +74,7 @@ import java.util.stream.Stream;
*/
public class GenericObjectRenderer implements IDhApiCustomRenderRegister
{
// TODO should be level specific, not global
@Deprecated
public static GenericObjectRenderer INSTANCE = new GenericObjectRenderer();
@@ -21,10 +21,10 @@ package com.seibel.distanthorizons.core.sql.repo;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
import com.seibel.distanthorizons.core.util.LodUtil;
import org.apache.logging.log4j.Logger;
import java.awt.*;
@@ -145,20 +145,43 @@ public class BeaconBeamRepo extends AbstractDhRepo<DhBlockPos, BeaconBeamDTO>
// additional methods //
//====================//
public List<BeaconBeamDTO> getAllBeamsForSectionPos(long pos)
public List<BeaconBeamDTO> getAllBeamsForPos(DhChunkPos chunkPos)
{
int minBlockX = chunkPos.getMinBlockX();
int minBlockZ = chunkPos.getMinBlockZ();
int maxBlockX = minBlockX + LodUtil.CHUNK_WIDTH;
int maxBlockZ = minBlockZ + LodUtil.CHUNK_WIDTH;
return this.getAllBeamsInBlockPosRange(
minBlockX, minBlockZ,
maxBlockX, maxBlockZ
);
}
public List<BeaconBeamDTO> getAllBeamsForPos(long pos)
{
int minBlockX = DhSectionPos.getMinCornerBlockX(pos);
int minBlockZ = DhSectionPos.getMinCornerBlockZ(pos);
int maxBlockX = minBlockX + DhSectionPos.getBlockWidth(pos);
int maxBlockZ = minBlockZ + DhSectionPos.getBlockWidth(pos);
return this.getAllBeamsInBlockPosRange(
minBlockX, minBlockZ,
maxBlockX, maxBlockZ
);
}
public List<BeaconBeamDTO> getAllBeamsInBlockPosRange(
int minBlockX, int minBlockZ,
int maxBlockX, int maxBlockZ
)
{
List<Map<String, Object>> objectMapList = this.queryDictionary(
"SELECT * " +
"FROM "+this.getTableName()+" " +
"WHERE " +
"BlockPosX >= "+minBlockX+" AND BlockPosX <= "+maxBlockX+" " +
"AND BlockPosZ >= "+minBlockZ+" AND BlockPosX <= "+maxBlockZ);
"FROM "+this.getTableName()+" " +
"WHERE " +
minBlockX+" <= BlockPosX AND BlockPosX <= "+maxBlockX+" AND " +
minBlockZ+" <= BlockPosZ AND BlockPosZ <= "+maxBlockZ);
ArrayList<BeaconBeamDTO> beamList = new ArrayList<>();
for (Map<String, Object> objectMap : objectMapList)
@@ -255,15 +255,48 @@ public interface IChunkWrapper extends IBindable
for (int i = 0; i < blockPosList.size(); i++)
{
DhBlockPos pos = blockPosList.get(i);
IBlockStateWrapper block = this.getBlockState(pos.convertToChunkRelativePos());
DhBlockPos relPos = pos.convertToChunkRelativePos();
IBlockStateWrapper block = this.getBlockState(relPos);
if (block.getSerialString().toLowerCase().contains("minecraft:beacon"))
{
BeaconBeamDTO beam = new BeaconBeamDTO(blockPosList.get(i), Color.WHITE);
beaconPosList.add(beam);
if (isBeaconActive(relPos.x, relPos.y, relPos.z, this))
{
BeaconBeamDTO beam = new BeaconBeamDTO(blockPosList.get(i), Color.WHITE);
beaconPosList.add(beam);
}
}
}
return beaconPosList;
}
static boolean isBeaconActive(int relBlockX, int y, int relBlockZ, IChunkWrapper chunkWrapper)
{
for (int x = -1; x<= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
if ((relBlockX + x < 0 || relBlockX + x >= LodUtil.CHUNK_WIDTH)
|| (relBlockZ + z < 0 || relBlockZ + z >= LodUtil.CHUNK_WIDTH))
{
// if the beacon is on the border of a chunk and all other blocks are there, assume it's complete
//TODO! Check adjacent chunk, if possible
continue;
}
String blockId = chunkWrapper.getBlockState(relBlockX + x, y -1, relBlockZ + z).getSerialString();
if (!(blockId.contains("diamond_block")
|| blockId.contains("iron_block")
|| blockId.contains("emerald_block")
|| blockId.contains("netherite_block")
|| blockId.contains("gold_block")))
{
return false;
}
}
}
return true;
}
}