Water mixin optimization

This commit is contained in:
paulevsGitch 2021-01-24 03:12:24 +03:00
parent b5ca1df3d1
commit 50acd99495
4 changed files with 47 additions and 46 deletions

View file

@ -14,9 +14,6 @@ import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters; import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;

View file

@ -5,10 +5,6 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes; import net.minecraft.util.shape.VoxelShapes;

View file

@ -1,6 +1,5 @@
package ru.betterend.client; package ru.betterend.client;
import net.fabricmc.loader.api.FabricLoader;
import ru.betterend.config.Configs; import ru.betterend.config.Configs;
public class ClientOptions { public class ClientOptions {
@ -14,9 +13,6 @@ public class ClientOptions {
useFogDensity = Configs.CLENT_CONFIG.getBooleanRoot("useFogDensity", true); useFogDensity = Configs.CLENT_CONFIG.getBooleanRoot("useFogDensity", true);
blendBiomeMusic = Configs.CLENT_CONFIG.getBooleanRoot("blendBiomeMusic", true); blendBiomeMusic = Configs.CLENT_CONFIG.getBooleanRoot("blendBiomeMusic", true);
sulfurWaterColor = Configs.CLENT_CONFIG.getBooleanRoot("sulfurWaterColor", true); sulfurWaterColor = Configs.CLENT_CONFIG.getBooleanRoot("sulfurWaterColor", true);
if (sulfurWaterColor) {
sulfurWaterColor = !FabricLoader.getInstance().isModLoaded("sodium");
}
Configs.CLENT_CONFIG.saveChanges(); Configs.CLENT_CONFIG.saveChanges();
} }
@ -49,6 +45,6 @@ public class ClientOptions {
} }
public static void setSulfurWaterColor(boolean sulfurWaterColor) { public static void setSulfurWaterColor(boolean sulfurWaterColor) {
ClientOptions.sulfurWaterColor = sulfurWaterColor && !FabricLoader.getInstance().isModLoaded("sodium"); ClientOptions.sulfurWaterColor = sulfurWaterColor;
} }
} }

View file

@ -1,10 +1,13 @@
package ru.betterend.mixin.client; package ru.betterend.mixin.client;
import java.awt.Point;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.color.world.BiomeColors; import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable; import net.minecraft.util.math.BlockPos.Mutable;
@ -19,46 +22,55 @@ import ru.betterend.util.MHelper;
public class BiomeColorsMixin { public class BiomeColorsMixin {
private static final int POISON_COLOR = MHelper.color(92, 160, 78); private static final int POISON_COLOR = MHelper.color(92, 160, 78);
private static final int STREAM_COLOR = MHelper.color(105, 213, 244); private static final int STREAM_COLOR = MHelper.color(105, 213, 244);
private static final Mutable POS = new Mutable();
private static final Point[] OUTER_POINTS;
private static final Point[] INNER_POINTS;
private static final boolean CAN_RENDER;
@Inject(method = "getWaterColor", at = @At("RETURN"), cancellable = true) @Inject(method = "getWaterColor", at = @At("RETURN"), cancellable = true)
private static void be_getWaterColor(BlockRenderView world, BlockPos pos, CallbackInfoReturnable<Integer> info) { private static void be_getWaterColor(BlockRenderView world, BlockPos pos, CallbackInfoReturnable<Integer> info) {
if (ClientOptions.useSulfurWaterColor()) { if (CAN_RENDER && ClientOptions.useSulfurWaterColor()) {
int color = info.getReturnValue(); POS.setY(pos.getY());
for (Point offset: INNER_POINTS) {
boolean scanDeep = true; POS.setX(pos.getX() + offset.x);
Mutable mut = new Mutable(); POS.setZ(pos.getZ() + offset.y);
for (Direction d: BlocksHelper.HORIZONTAL) { if ((world.getBlockState(POS).isOf(EndBlocks.BRIMSTONE))) {
mut.set(pos).move(d); info.setReturnValue(POISON_COLOR);
if ((world.getBlockState(mut).isOf(EndBlocks.BRIMSTONE))) { info.cancel();
color = POISON_COLOR; return;
scanDeep = false;
break;
} }
} }
if (scanDeep) { for (Point offset: OUTER_POINTS) {
int x1 = pos.getX() - 2; POS.setX(pos.getX() + offset.x);
int z1 = pos.getZ() - 2; POS.setZ(pos.getZ() + offset.y);
if ((world.getBlockState(POS).isOf(EndBlocks.BRIMSTONE))) {
int x2 = pos.getX() + 3; info.setReturnValue(STREAM_COLOR);
int z2 = pos.getZ() + 3; info.cancel();
return;
mut.setY(pos.getY());
for (int x = x1; x < x2 && scanDeep; x++) {
mut.setX(x);
for (int z = z1; z < z2 && scanDeep; z++) {
mut.setZ(z);
if (Math.abs(pos.getX() - x) != 2 || Math.abs(pos.getZ() - z) != 2) {
if ((world.getBlockState(mut).isOf(EndBlocks.BRIMSTONE))) {
color = STREAM_COLOR;
scanDeep = false;
}
}
}
} }
} }
}
}
info.setReturnValue(color); static {
CAN_RENDER = !FabricLoader.getInstance().isModLoaded("sodium");
OUTER_POINTS = new Point[16];
for (int i = 0; i < 3; i++) {
int p = i - 1;
OUTER_POINTS[i] = new Point(p, -2);
OUTER_POINTS[i + 3] = new Point(p, 2);
OUTER_POINTS[i + 6] = new Point(-2, p);
OUTER_POINTS[i + 9] = new Point(2, p);
}
INNER_POINTS = new Point[4];
for (int i = 0; i < 4; i++) {
Direction dir = BlocksHelper.HORIZONTAL[i];
INNER_POINTS[i] = new Point(dir.getOffsetX(), dir.getOffsetZ());
dir = BlocksHelper.HORIZONTAL[(i + 1) & 3];
OUTER_POINTS[i + 12] = new Point(INNER_POINTS[i].x + dir.getOffsetX(), INNER_POINTS[i].y + dir.getOffsetZ());
} }
} }
} }