Move all RebornCore client code into the client package.
Also Fix PowerSystem.locale being awful.
This commit is contained in:
parent
7c02024a2d
commit
03985f2aae
9 changed files with 79 additions and 85 deletions
|
@ -55,23 +55,16 @@ import reborncore.common.util.GenericWrenchHelper;
|
|||
import team.reborn.energy.api.EnergyStorage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class RebornCore implements ModInitializer {
|
||||
|
||||
public static final String MOD_NAME = "Reborn Core";
|
||||
public static final String MOD_ID = "reborncore";
|
||||
public static final String MOD_VERSION = "@MODVERSION@";
|
||||
public static final String WEB_URL = "https://files.modmuss50.me/";
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
public static File configDir;
|
||||
|
||||
public static boolean LOADED = false;
|
||||
|
||||
public RebornCore() {
|
||||
|
||||
}
|
||||
public static Locale locale = Locale.ROOT;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
@ -132,9 +125,6 @@ public class RebornCore implements ModInitializer {
|
|||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
LOGGER.info("Reborn core is done for now, now to let other mods have their turn...");
|
||||
LOADED = true;
|
||||
}
|
||||
|
||||
public static EnvType getSide() {
|
||||
|
|
|
@ -26,6 +26,7 @@ package reborncore;
|
|||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
|
@ -33,8 +34,8 @@ import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
|||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import reborncore.api.blockentity.UnloadHandler;
|
||||
import reborncore.client.*;
|
||||
import reborncore.common.fluid.RebornFluidRenderManager;
|
||||
import reborncore.common.network.ClientBoundPacketHandlers;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class RebornCoreClient implements ClientModInitializer {
|
||||
|
||||
|
@ -52,5 +53,10 @@ public class RebornCoreClient implements ClientModInitializer {
|
|||
ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register((blockEntity, world) -> {
|
||||
if (blockEntity instanceof UnloadHandler) ((UnloadHandler) blockEntity).onUnload();
|
||||
});
|
||||
|
||||
ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
|
||||
String strangeMcLang = client.getLanguageManager().getLanguage().getCode();
|
||||
RebornCore.locale = Locale.forLanguageTag(strangeMcLang.substring(0, 2));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.common.network;
|
||||
package reborncore.client;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
@ -44,12 +44,12 @@ import net.minecraft.world.World;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.client.ClientChunkManager;
|
||||
import reborncore.client.ItemStackRenderManager;
|
||||
import reborncore.common.blockentity.FluidConfiguration;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.blockentity.SlotConfiguration;
|
||||
import reborncore.common.chunkloading.ChunkLoaderManager;
|
||||
import reborncore.common.network.ExtendedPacketBuffer;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import reborncore.common.screen.BuiltScreenHandler;
|
||||
import reborncore.mixin.client.AccessorChatHud;
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package reborncore.common.fluid;
|
||||
package reborncore.client;
|
||||
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
|
@ -35,7 +35,9 @@ import net.minecraft.fluid.Fluid;
|
|||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import reborncore.client.RenderUtil;
|
||||
import reborncore.common.fluid.FluidSettings;
|
||||
import reborncore.common.fluid.RebornFluid;
|
||||
import reborncore.common.fluid.RebornFluidManager;
|
||||
import reborncore.common.util.TemporaryLazy;
|
||||
|
||||
import java.util.Collection;
|
|
@ -0,0 +1,55 @@
|
|||
package reborncore.client.multiblock;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayers;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.world.BlockView;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* Renders a hologram
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public
|
||||
record HologramRenderer(BlockRenderView view, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider,
|
||||
float scale) implements MultiblockWriter {
|
||||
private static final BlockPos OUT_OF_WORLD_POS = new BlockPos(0, 260, 0); // Bad hack; disables lighting
|
||||
|
||||
@Override
|
||||
public MultiblockWriter add(int x, int y, int z, BiPredicate<BlockView, BlockPos> predicate, BlockState state) {
|
||||
final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
matrix.push();
|
||||
matrix.translate(x, y, z);
|
||||
matrix.translate(0.5, 0.5, 0.5);
|
||||
matrix.scale(scale, scale, scale);
|
||||
|
||||
|
||||
if (state.getBlock() instanceof FluidBlock) {
|
||||
FluidState fluidState = ((FluidBlock) state.getBlock()).getFluidState(state);
|
||||
MinecraftClient.getInstance().getItemRenderer().renderItem(new ItemStack(fluidState.getFluid().getBucketItem()), ModelTransformation.Mode.FIXED, 15728880, OverlayTexture.DEFAULT_UV, matrix, vertexConsumerProvider, 0);
|
||||
} else {
|
||||
matrix.translate(-0.5, -0.5, -0.5);
|
||||
VertexConsumer consumer = vertexConsumerProvider.getBuffer(RenderLayers.getBlockLayer(state));
|
||||
blockRenderManager.renderBlock(state, OUT_OF_WORLD_POS, view, matrix, consumer, false, new Random());
|
||||
}
|
||||
|
||||
matrix.pop();
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -29,7 +29,6 @@ import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
|||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.blockentity.MultiblockWriter;
|
||||
|
||||
public class MultiblockRenderer<T extends MachineBaseBlockEntity> implements BlockEntityRenderer<T> {
|
||||
|
||||
|
@ -39,7 +38,7 @@ public class MultiblockRenderer<T extends MachineBaseBlockEntity> implements Blo
|
|||
@Override
|
||||
public void render(T blockEntity, float partialTicks, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, int overlay) {
|
||||
if (blockEntity.renderMultiblock) {
|
||||
blockEntity.writeMultiblock(new MultiblockWriter.HologramRenderer(blockEntity.getWorld(), matrixStack, vertexConsumerProvider, 0.4F).rotate(blockEntity.getFacing().getOpposite()));
|
||||
blockEntity.writeMultiblock(new HologramRenderer(blockEntity.getWorld(), matrixStack, vertexConsumerProvider, 0.4F).rotate(blockEntity.getFacing().getOpposite()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,27 +24,13 @@
|
|||
|
||||
package reborncore.common.blockentity;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayers;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.BlockRenderManager;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.world.BlockView;
|
||||
import reborncore.client.multiblock.HologramRenderer;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
|
@ -239,33 +225,4 @@ public interface MultiblockWriter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a hologram
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
record HologramRenderer(BlockRenderView view, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, float scale) implements MultiblockWriter {
|
||||
private static final BlockPos OUT_OF_WORLD_POS = new BlockPos(0, 260, 0); // Bad hack; disables lighting
|
||||
|
||||
@Override
|
||||
public MultiblockWriter add(int x, int y, int z, BiPredicate<BlockView, BlockPos> predicate, BlockState state) {
|
||||
final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
matrix.push();
|
||||
matrix.translate(x, y, z);
|
||||
matrix.translate(0.5, 0.5, 0.5);
|
||||
matrix.scale(scale, scale, scale);
|
||||
|
||||
|
||||
if (state.getBlock() instanceof FluidBlock) {
|
||||
FluidState fluidState = ((FluidBlock) state.getBlock()).getFluidState(state);
|
||||
MinecraftClient.getInstance().getItemRenderer().renderItem(new ItemStack(fluidState.getFluid().getBucketItem()), ModelTransformation.Mode.FIXED, 15728880, OverlayTexture.DEFAULT_UV, matrix, vertexConsumerProvider, 0);
|
||||
} else {
|
||||
matrix.translate(-0.5, -0.5, -0.5);
|
||||
VertexConsumer consumer = vertexConsumerProvider.getBuffer(RenderLayers.getBlockLayer(state));
|
||||
blockRenderManager.renderBlock(state, OUT_OF_WORLD_POS, view, matrix, consumer, false, new Random());
|
||||
}
|
||||
|
||||
matrix.pop();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ public class ExtendedPacketBuffer extends PacketByteBuf {
|
|||
super(wrapped);
|
||||
}
|
||||
|
||||
protected void writeObject(Object object) {
|
||||
public void writeObject(Object object) {
|
||||
ObjectBufferUtils.writeObject(object, this);
|
||||
}
|
||||
|
||||
protected Object readObject() {
|
||||
public Object readObject() {
|
||||
return ObjectBufferUtils.readObject(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,11 @@
|
|||
|
||||
package reborncore.common.powerSystem;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.common.RebornCoreConfig;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PowerSystem {
|
||||
|
@ -39,8 +36,6 @@ public class PowerSystem {
|
|||
|
||||
private static final char[] magnitude = new char[] { 'k', 'M', 'G', 'T' };
|
||||
|
||||
private static Locale locale = Locale.ROOT;
|
||||
|
||||
public static String getLocalizedPower(double power) {
|
||||
|
||||
return getRoundedString(power, selectedSystem.abbreviation, true);
|
||||
|
@ -67,8 +62,7 @@ public class PowerSystem {
|
|||
}
|
||||
|
||||
private static String getFullPower(double power, String units){
|
||||
checkLocale();
|
||||
DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(locale);
|
||||
DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(RebornCore.locale);
|
||||
return formatter.format(power) + " " + units;
|
||||
}
|
||||
|
||||
|
@ -111,8 +105,7 @@ public class PowerSystem {
|
|||
}
|
||||
|
||||
if (doFormat){
|
||||
checkLocale();
|
||||
DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(locale);
|
||||
DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(RebornCore.locale);
|
||||
ret += formatter.format(value);
|
||||
int idx = ret.lastIndexOf(formatter.getDecimalFormatSymbols().getDecimalSeparator());
|
||||
if (idx > 0){
|
||||
|
@ -161,14 +154,6 @@ public class PowerSystem {
|
|||
}
|
||||
}
|
||||
|
||||
private static void checkLocale() {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) { return; }
|
||||
MinecraftClient instance = MinecraftClient.getInstance();
|
||||
if (instance == null) { return; }
|
||||
String strangeMcLang = instance.getLanguageManager().getLanguage().getCode();
|
||||
locale = Locale.forLanguageTag(strangeMcLang.substring(0, 2));
|
||||
}
|
||||
|
||||
public enum EnergySystem {
|
||||
EU(0xFF800600, "E", 141, 151, 0xFF670000);
|
||||
|
||||
|
|
Loading…
Reference in a new issue