skybox: cut target replacement feature, to be implemented later

This commit is contained in:
logarithm
2019-12-02 16:07:53 +02:00
parent 233fd5653e
commit b20759b1d2
4 changed files with 15 additions and 133 deletions

View File

@@ -86,43 +86,6 @@ class Skybox
private final int y2;
private final int stride;
private boolean override;
public void setOverrideEnabled(boolean value)
{
override = value;
}
private int overrideTargetColor;
private int overrideReplacementColor;
public void setOverrideColors(int before, int after)
{
int cr, cg, cb;
byte cco, tmp, ccg, cy;
cr = before >> 16 & 0xFF;
cg = before >> 8 & 0xFF;
cb = before & 0xFF;
// Convert to YCoCg24
cco = (byte) (cb - cr);
tmp = (byte) (cr + (cco >> 1));
ccg = (byte) (tmp - cg);
cy = (byte) (cg + (ccg >> 1));
overrideTargetColor = (cy & 0xFF) << 16 | (cco & 0xFF) << 8 | (ccg & 0xFF);
cr = after >> 16 & 0xFF;
cg = after >> 8 & 0xFF;
cb = after & 0xFF;
// Convert to YCoCg24
cco = (byte) (cb - cr);
tmp = (byte) (cr + (cco >> 1));
ccg = (byte) (tmp - cg);
cy = (byte) (cg + (ccg >> 1));
overrideReplacementColor = (cy & 0xFF) << 16 | (cco & 0xFF) << 8 | (ccg & 0xFF);
}
public Skybox(InputStream is, String filename) throws IOException
{
this(new InputStreamReader(is), filename);
@@ -403,33 +366,6 @@ class Skybox
return cv;
}
private int chunkDataWithOverride(int cx, int cy, int plane, ChunkMapper chunkMapper)
{
int cv = chunkData(cx, cy, plane, chunkMapper);
if (override && cv == ((0xFF000000 & cv) | overrideTargetColor))
cv = ((0xFF000000 & cv) | overrideReplacementColor);
return cv;
}
public Color getCentralColorForPoint(int px, int py, int plane, ChunkMapper chunkMapper)
{
int ycocg = chunkData(px / 8, py / 8, plane, chunkMapper);
byte y = (byte) (ycocg >>> 16 & 0xFF);
byte co = (byte) (ycocg >>> 8);
byte cg = (byte) ycocg;
// convert back to rgb from YCoCg24
int g = (y - (cg >> 1)) & 0xFF;
int tmp = (g + cg) & 0xFF;
int r = (tmp - (co >> 1)) & 0xFF;
int b = (r + co) & 0xFF;
return new Color(r, g, b);
}
/**
* Calculates the RGB color for a specific world coordinate. Arguments are floats for sub-tile accuracy.
*
@@ -447,7 +383,7 @@ class Skybox
int cx = (int) x;
int cy = (int) y;
int centerChunkData = chunkDataWithOverride(px / 8, py / 8, plane, chunkMapper);
int centerChunkData = chunkData(px / 8, py / 8, plane, chunkMapper);
if (centerChunkData == -1)
{
// No data in the center chunk?
@@ -468,7 +404,7 @@ class Skybox
{
for (int ucy = ymin; ucy <= ymax; ucy++)
{
int val = chunkDataWithOverride(ucx, ucy, plane, chunkMapper);
int val = chunkData(ucx, ucy, plane, chunkMapper);
if (val == -1)
{
continue;

View File

@@ -61,7 +61,6 @@ public class SkyboxPlugin extends Plugin
public void startUp() throws IOException
{
skybox = new Skybox(SkyboxPlugin.class.getResourceAsStream("skybox.txt"), "skybox.txt");
skybox.setOverrideColors(config.colorToOverride().getRGB(), config.customColor().getRGB());
}
@Override
@@ -77,29 +76,6 @@ public class SkyboxPlugin extends Plugin
return configManager.getConfig(SkyboxPluginConfig.class);
}
@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (config.pickColorToOverride())
{
Player player = client.getLocalPlayer();
if (player != null)
{
Color c = skybox.getCentralColorForPoint(
player.getWorldLocation().getX(),
player.getWorldLocation().getY(),
client.getPlane(),
client.isInInstancedRegion() ? this::mapChunk : null);
config.setColorToOverride(c);
}
config.setOverrideMode(SkyOverrideMode.ONE);
config.setPickColorToOverride(false);
}
skybox.setOverrideColors(config.colorToOverride().getRGB(), config.customColor().getRGB());
skybox.setOverrideEnabled(config.overrideMode() == SkyOverrideMode.ONE);
}
private int mapChunk(int cx, int cy, int plane)
{
cx -= client.getBaseX() / 8;
@@ -129,6 +105,16 @@ public class SkyboxPlugin extends Plugin
return;
}
if (
config.overrideMode() == SkyOverrideMode.ALL ||
(config.overrideMode() == SkyOverrideMode.OVERWORLD && client.getLocalPlayer().getWorldLocation().getY() < 4200)
)
{
client.setSkyboxColor(config.customColor().getRGB());
return;
}
int px, py;
if (client.getOculusOrbState() == 1)
{
@@ -149,10 +135,7 @@ public class SkyboxPlugin extends Plugin
int baseX = client.getBaseX();
int baseY = client.getBaseY();
if (config.overrideMode() == SkyOverrideMode.ALL || (config.overrideMode() == SkyOverrideMode.OVERWORLD && baseY < 4200))
client.setSkyboxColor(config.customColor().getRGB());
else
client.setSkyboxColor(skybox.getColorForPoint(
client.setSkyboxColor(skybox.getColorForPoint(
baseX + ((px + spx) / 128.f),
baseY + ((py + spy) / 128.f),
baseX + (px / 128),

View File

@@ -38,7 +38,7 @@ public interface SkyboxPluginConfig extends Config
@ConfigItem(
keyName = "customColor",
name = "Custom sky color",
description = "Set a color here to use it with the options below",
description = "Set a color here to use for the sky",
position = 1
)
default Color customColor()
@@ -49,47 +49,11 @@ public interface SkyboxPluginConfig extends Config
@ConfigItem(
keyName = "skyOverrideMode",
name = "Mode",
description = "Replace the sky color in regions of a certain target color, the overworld, or everywhere",
description = "Replace the sky color in just the overworld, or everywhere",
position = 2
)
default SkyOverrideMode overrideMode()
{
return SkyOverrideMode.NONE;
}
@ConfigItem(
keyName = "skyOverrideMode", name = "", description = ""
)
void setOverrideMode(SkyOverrideMode value);
@ConfigItem(
keyName = "pickColorToOverride",
name = "Set current sky as target",
description = "Sets target color to current chunk's sky color when switched on",
warning = "Are you sure that you want to set the target color to the current sky color and forget the previous one?",
position = 3
)
default boolean pickColorToOverride()
{
return false;
}
@ConfigItem(
keyName = "pickColorToOverride", name = "", description = ""
)
void setPickColorToOverride(boolean value);
@ConfigItem(
keyName = "colorToOverride",
name = "Target color",
description = "Changing this manually is not recommended, but copying the value for tweaking is useful. Note that the value will not update when you enable the picker, until you re-enter the config panel.",
hidden = true,
position = 4
)
default Color colorToOverride()
{
return Color.BLACK;
}
@ConfigItem(
keyName = "colorToOverride", name = "", description = ""
)
void setColorToOverride(Color value);
}

View File

@@ -33,7 +33,6 @@ import lombok.RequiredArgsConstructor;
public enum SkyOverrideMode
{
NONE("None"),
ONE("Replace target sky color"),
OVERWORLD("Overworld"),
ALL("Everywhere");