Optimize beacon detection

This commit is contained in:
James Seibel
2024-07-08 20:20:48 -05:00
parent 29ef95387c
commit f144a9ebc1
3 changed files with 27 additions and 25 deletions
@@ -21,6 +21,9 @@ package com.seibel.distanthorizons.core.wrapperInterfaces.block;
import com.seibel.distanthorizons.api.interfaces.block.IDhApiBlockStateWrapper;
import java.util.Arrays;
import java.util.List;
/** A Minecraft version independent way of handling Blocks. */
public interface IBlockStateWrapper extends IDhApiBlockStateWrapper
{
@@ -31,6 +34,15 @@ public interface IBlockStateWrapper extends IDhApiBlockStateWrapper
int FULLY_TRANSPARENT = 0;
int FULLY_OPAQUE = 16;
/** should be all lowercase */
List<String> BEACON_BASE_BLOCK_NAME_LIST = Arrays.asList(
"iron_block",
"gold_block",
"diamond_block",
"emerald_block",
"netherite_block"
);
/** contains the indices used by Iris to determine how different block types should be rendered */
class IrisBlockMaterial
{
@@ -77,4 +89,7 @@ public interface IBlockStateWrapper extends IDhApiBlockStateWrapper
byte getIrisBlockMaterialId();
boolean isBeaconBlock();
boolean isBeaconBaseBlock();
}
@@ -41,15 +41,6 @@ public interface IChunkWrapper extends IBindable
/** useful for debugging, but can slow down chunk operations quite a bit due to being called every time. */
boolean RUN_RELATIVE_POS_INDEX_VALIDATION = ModInfo.IS_DEV_BUILD;
/** should be all lowercase */
List<String> BEACON_BASE_BLOCK_NAME_LIST = Arrays.asList(
"iron_block",
"gold_block",
"diamond_block",
"emerald_block",
"netherite_block"
);
DhChunkPos getChunkPos();
@@ -271,8 +262,9 @@ public interface IChunkWrapper extends IBindable
DhBlockPos pos = blockPosList.get(i);
DhBlockPos relPos = pos.convertToChunkRelativePos();
IBlockStateWrapper block = this.getBlockState(relPos);
if (block.getSerialString().toLowerCase().contains("minecraft:beacon"))
if (block.isBeaconBlock())
{
if (isBeaconActive(pos, adjacentChunkHolder))
{
@@ -299,21 +291,9 @@ public interface IChunkWrapper extends IBindable
IChunkWrapper chunk = chunkHolder.getByBlockPos(beaconPos.x + x, beaconPos.z + z);
if (chunk != null)
{
String blockSerial = chunk.getBlockState(baseRelPos.x, baseRelPos.y, baseRelPos.z).getSerialString();
boolean baseBlockFound = false;
for (int i = 0; i < BEACON_BASE_BLOCK_NAME_LIST.size(); i++)
{
String baseBlockName = BEACON_BASE_BLOCK_NAME_LIST.get(i);
if (blockSerial.contains(baseBlockName))
{
baseBlockFound = true;
break;
}
}
if (!baseBlockFound)
{
IBlockStateWrapper block = chunk.getBlockState(baseRelPos.x, baseRelPos.y, baseRelPos.z);
if (!block.isBeaconBaseBlock())
{
return false;
}
@@ -104,4 +104,11 @@ public class LightingTestBlockStateWrapper implements IBlockStateWrapper
@Override
public byte getIrisBlockMaterialId() { throw new UnsupportedOperationException("Not Implemented"); }
@Override
public boolean isBeaconBlock() { throw new UnsupportedOperationException("Not Implemented"); }
@Override
public boolean isBeaconBaseBlock() { throw new UnsupportedOperationException("Not Implemented"); }
}