Update everything latest & fix some issues & new accesswideners

This commit is contained in:
Ran
2021-12-01 01:02:20 +06:00
parent 9f6e9f791c
commit c9f6a753ec
34 changed files with 1013 additions and 818 deletions
@@ -31,7 +31,7 @@ import me.shedaniel.autoconfig.annotation.ConfigEntry;
/**
* This handles any configuration the user has access to.
* @author coolGi2007
* @version 11-23-2021
* @version 11-29-2021
*/
@me.shedaniel.autoconfig.annotation.Config(name = ModInfo.ID)
public class Config implements ConfigData
@@ -54,10 +54,6 @@ public class Config implements ConfigData
// Since the original config system uses forge stuff, that means we have to rewrite the whole config system
// TODO: Stop using autoconfig and use manual config for cloth config
@ConfigEntry.Gui.Excluded
//@ConfigEntry.Category("lod.debug")
public int ConfigVersion = 1;
@ConfigEntry.Gui.CollapsibleObject
public Client client = new Client();
@@ -117,7 +113,11 @@ public class Config implements ConfigData
@ConfigEntry.Category("lod.Graphics.FogQualityOption")
@ConfigEntry.Gui.Tooltip
public static FogDrawOverride fogDrawOverride = IFogQuality.FOG_DRAW_OVERRIDE_DEFAULT;
public static FogDrawMode fogDrawMode = IFogQuality.FOG_DRAW_MODE_DEFAULT;
@ConfigEntry.Category("lod.Graphics.FogQualityOption")
@ConfigEntry.Gui.Tooltip
public static FogColorMode fogColorMode = IFogQuality.FOG_COLOR_MODE_DEFAULT;
@ConfigEntry.Category("lod.Graphics.FogQualityOption")
@ConfigEntry.Gui.Tooltip
@@ -146,6 +146,11 @@ public class Config implements ConfigData
@ConfigEntry.Gui.Tooltip
public static GpuUploadMethod gpuUploadMethod = IAdvancedGraphics.GPU_UPLOAD_METHOD_DEFAULT;
@ConfigEntry.Category("lod.Graphics.AdvancedGraphicsOption")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(min = 0, max = 5000)
public static int gpuUploadTimeoutInMilleseconds = IAdvancedGraphics.GPU_UPLOAD_TIMEOUT_IN_MILLISECONDS_DEFAULT.defaultValue;
@ConfigEntry.Category("lod.Graphics.AdvancedGraphicsOption")
@ConfigEntry.Gui.Tooltip
public static boolean useExtendedNearClipPlane = IAdvancedGraphics.USE_EXTENDED_NEAR_CLIP_PLANE_DEFAULT;
@@ -27,7 +27,6 @@ import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraftforge.common.WorldWorkerManager;
/**
* Initialize and setup the Mod. <br>
@@ -51,30 +50,19 @@ public class Main implements ClientModInitializer
// Do if implements ClientModInitializer
// This loads the mod before minecraft loads which causes a lot of issues
@Override
public void onInitializeClient() {
// no.
}
// This loads the mod after minecraft loads which doesn't causes a lot of issues
public static void init() {
if (instance != null) return;
instance = new Main();
DependencySetup.createInitialBindings();
DependencySetup.createInitialBindings();
ClientApi.LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
initializeForge();
// Check if this works
client_proxy = new ClientProxy();
client_proxy.registerEvents();
}
/**
* This method makes forge classes work instead of just sitting there
* @author Ran
*/
public static void initializeForge() {
ServerTickEvents.START_SERVER_TICK.register((server) -> WorldWorkerManager.tick(true));
ServerTickEvents.END_SERVER_TICK.register((server) -> WorldWorkerManager.tick(false));
}
}
@@ -8,6 +8,10 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* Loads the mod after minecraft loads.
* @author Ran
*/
@Mixin(value = Minecraft.class)
public class MixinMinecraft {
@Inject(method = "<init>", at = @At("TAIL"))
@@ -0,0 +1,44 @@
package com.seibel.lod.fabric.mixins;
import com.seibel.lod.core.ModInfo;
import com.seibel.lod.fabric.Config;
import com.seibel.lod.fabric.wrappers.config.TexturedButtonWidget;
import me.shedaniel.autoconfig.AutoConfig;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screens.OptionsScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Objects;
@Mixin(OptionsScreen.class)
public class MixinOptionsScreen extends Screen {
// Get the texture for the button
private static final ResourceLocation ICON_TEXTURE = new ResourceLocation(ModInfo.ID,"textures/gui/button.png");
protected MixinOptionsScreen(Component title) {
super(title);
}
@Inject(at = @At("HEAD"),method = "init")
private void lodconfig$init(CallbackInfo ci) {
this.addRenderableWidget(new TexturedButtonWidget(
// Where the button is on the screen
this.width / 2 - 180, this.height / 6 - 12,
// Width and height of the button
20, 20,
// Offset
0, 0,
// Some textuary stuff
20, ICON_TEXTURE, 20, 40,
// Create the button and tell it where to go
(buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(AutoConfig.getConfigScreen(Config.class, this).get()),
// Add a title to the screen
new TranslatableComponent("text.autoconfig." + ModInfo.ID + ".title")));
}
}
@@ -48,6 +48,7 @@ import net.minecraft.client.renderer.RenderType;
@Mixin(LevelRenderer.class)
public class MixinWorldRenderer
{
/*
private static float previousPartialTicks = 0;
@Inject(at = @At("RETURN"), method = "renderClouds")
@@ -77,6 +78,32 @@ public class MixinWorldRenderer
Mat4f mcModelViewMatrix = McObjectConverter.Convert(matrixStackIn.last().pose());
ClientApi.INSTANCE.renderLods(mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
}
}
*/
private static float previousPartialTicks = 0;
@Inject(at = @At("RETURN"), method = "renderClouds(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/math/Matrix4f;FDDD)V")
private void renderClouds(PoseStack modelViewMatrixStack, Matrix4f projectionMatrix, float partialTicks, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, CallbackInfo callback)
{
// get the partial ticks since renderChunkLayer doesn't
// have access to them
previousPartialTicks = partialTicks;
}
// HEAD or RETURN
@Inject(at = @At("HEAD"), method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V")
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
{
// only render before solid blocks
if (renderType.equals(RenderType.solid()))
{
Mat4f mcModelViewMatrix = McObjectConverter.Convert(modelViewMatrixStack.last().pose());
Mat4f mcProjectionMatrix = McObjectConverter.Convert(projectionMatrix);
ClientApi.INSTANCE.renderLods(mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
}
}
@@ -8,13 +8,13 @@ import com.seibel.lod.core.wrapperInterfaces.block.IBlockColorSingletonWrapper;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftWrapper;
import com.seibel.lod.fabric.wrappers.block.BlockColorSingletonWrapper;
import com.seibel.lod.fabric.wrappers.config.LodConfigWrapperSingleton;
import com.seibel.lod.fabric.wrappers.block.BlockColorSingletonWrapper;
import com.seibel.lod.fabric.wrappers.minecraft.MinecraftRenderWrapper;
import com.seibel.lod.fabric.wrappers.minecraft.MinecraftWrapper;
/**
* Binds all necessary dependencies so we
* Binds all necessary dependencies, so we
* can access them in Core. <br>
* This needs to be called before any Core classes
* are loaded.
@@ -30,21 +30,12 @@ import net.minecraft.core.Direction;
/**
* This class converts to and from Minecraft objects (Ex: Matrix4f)
* and objects we created (Ex: Mat4f).
* Since we don't want to deal with a bunch of tiny changes
* every time Minecraft renames a variable in Matrix4f or something.
*
* @author James Seibel
* @version 11-11-2021
* @version 11-20-2021
*/
public class McObjectConverter
{
public McObjectConverter()
{
}
/** 4x4 float matrix converter */
public static Mat4f Convert(Matrix4f mcMatrix)
{
@@ -1,3 +1,22 @@
/*
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.fabric.wrappers;
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
@@ -1,3 +1,22 @@
/*
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.fabric.wrappers;
import net.minecraft.world.level.levelgen.Heightmap;
@@ -5,14 +24,12 @@ import net.minecraft.world.level.levelgen.Heightmap;
/**
* Stores any variables or code that
* may be shared between wrapper objects.
*
*
* @author James Seibel
* @version 11-20-2021
*/
public class WrapperUtil
{
/** If we ever need to use a heightmap for any reason, use this one. */
public static final Heightmap.Types DEFAULT_HEIGHTMAP = Heightmap.Types.WORLD_SURFACE_WG;
public static final Heightmap.Types DEFAULT_HEIGHTMAP = Heightmap.Types.WORLD_SURFACE_WG;
}
@@ -1,25 +1,46 @@
/*
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.fabric.wrappers.block;
import com.seibel.lod.core.wrapperInterfaces.block.IBlockColorSingletonWrapper;
import com.seibel.lod.core.wrapperInterfaces.block.IBlockColorWrapper;
import net.minecraft.world.level.block.Blocks;
/**
* This class wraps the minecraft Block class
* Contains methods that would have been static in BlockColorWrapper.
* Since interfaces can't create/implement static methods we have
* to split the object up in two.
*
* @author ??
* @author James Seibel
* @version 11-17-2021
*/
public class BlockColorSingletonWrapper implements IBlockColorSingletonWrapper
{
public static final BlockColorSingletonWrapper INSTANCE = new BlockColorSingletonWrapper();
/** return base color of water (grey value) */
@Override
public IBlockColorWrapper getWaterColor()
{
return BlockColorWrapper.getBlockColorWrapper(Blocks.WATER);
return BlockColorWrapper.getBlockColorWrapper(Blocks.WATER.defaultBlockState(), new BlockPosWrapper(0,0, 0));
}
}
@@ -7,80 +7,74 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.seibel.lod.core.util.ColorUtil;
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
import com.seibel.lod.core.wrapperInterfaces.block.IBlockColorWrapper;
import com.seibel.lod.fabric.wrappers.minecraft.MinecraftWrapper;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BushBlock;
import net.minecraft.world.level.block.FlowerBlock;
import net.minecraft.world.level.block.GrassBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.TallGrassBlock;
import net.minecraft.world.level.block.state.BlockState;
/**
* This class wraps the minecraft Block color class
*
* @author ??
* @version 11-17-2021
* @author James Seibel
* @version 11-21-2021
*/
public class BlockColorWrapper implements IBlockColorWrapper
{
//set of block which require tint
public static final ConcurrentMap<Block, BlockColorWrapper> blockColorWrapperMap = new ConcurrentHashMap<>();
public static final ConcurrentMap<Block, IBlockColorWrapper> blockColorWrapperMap = new ConcurrentHashMap<>();
// public static final ModelDataMap dataMap = new ModelDataMap.Builder().build();
public static final BlockPos blockPos = new BlockPos(0, 0, 0);
public static final Random random = new Random(0);
public static final AbstractBlockPosWrapper blockPos = new BlockPosWrapper(0,0,0);
public static Random random = new Random(0);
//public static BlockColourWrapper WATER_COLOR = getBlockColorWrapper(Blocks.WATER);
public static final Direction[] directions = new Direction[] { Direction.UP, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.NORTH, Direction.DOWN };
private final Block block;
private Block block;
private int color;
private boolean isColored;
private boolean toTint;
private boolean foliageTint;
private boolean folliageTint;
private boolean grassTint;
private boolean waterTint;
/**Constructor only require for the block instance we are wrapping**/
public BlockColorWrapper(Block block)
public BlockColorWrapper(BlockState blockState, AbstractBlockPosWrapper blockPosWrapper)
{
this.block = block;
this.block = blockState.getBlock();
this.color = 0;
this.isColored = true;
this.toTint = false;
this.foliageTint = false;
this.folliageTint = false;
this.grassTint = false;
this.waterTint = false;
setupColorAndTint();
/*StringBuilder s = new StringBuilder();
s.append(block + "\n"
+ Integer.toHexString(
Minecraft.getInstance().getBlockColors().createDefault().getColor(
block.defaultBlockState(),
(World) MinecraftWrapper.INSTANCE.getWrappedServerLevel().getLevel(),
blockPosWrapper.getBlockPos())) + "\n"
);
for(Property x : Minecraft.getInstance().getBlockColors().getColoringProperties(block))
s.append(x.getName() + " " + x.getPossibleValues() + '\n');
System.out.println(s);*/
//System.out.println(block + " color " + Integer.toHexString(color) + " to tint " + toTint + " folliageTint " + folliageTint + " grassTint " + grassTint + " waterTint " + waterTint);
setupColorAndTint(blockState,blockPosWrapper);
System.out.println(block + " color " + Integer.toHexString(color) + " to tint " + toTint + " folliageTint " + folliageTint + " grassTint " + grassTint + " waterTint " + waterTint);
}
/**
* this return a wrapper of the block in input
* @param block object of the block to wrap
* @param blockState of the block to wrap
*/
public static IBlockColorWrapper getBlockColorWrapper(Block block)
static public IBlockColorWrapper getBlockColorWrapper(BlockState blockState, AbstractBlockPosWrapper blockPosWrapper)
{
//first we check if the block has already been wrapped
if (blockColorWrapperMap.containsKey(block) && blockColorWrapperMap.get(block) != null)
return blockColorWrapperMap.get(block);
if (blockColorWrapperMap.containsKey(blockState.getBlock()) && blockColorWrapperMap.get(blockState.getBlock()) != null)
return blockColorWrapperMap.get(blockState.getBlock());
//if it hasn't been created yet, we create it and save it in the map
BlockColorWrapper blockWrapper = new BlockColorWrapper(block);
blockColorWrapperMap.put(block, blockWrapper);
IBlockColorWrapper blockWrapper = new BlockColorWrapper(blockState, blockPosWrapper);
blockColorWrapperMap.put(blockState.getBlock(), blockWrapper);
//we return the newly created wrapper
return blockWrapper;
@@ -90,10 +84,8 @@ public class BlockColorWrapper implements IBlockColorWrapper
* Generate the color of the given block from its texture
* and store it for later use.
*/
private void setupColorAndTint()
private void setupColorAndTint(BlockState blockState, AbstractBlockPosWrapper blockPosWrapper)
{
BlockState blockState = block.defaultBlockState();
BlockPosWrapper blockPosWrapper = new BlockPosWrapper();
MinecraftWrapper mc = MinecraftWrapper.INSTANCE;
TextureAtlasSprite texture;
List<BakedQuad> quads = null;
@@ -117,7 +109,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
if (isTinted)
this.toTint = true;
//now we get the first non empty face
//now we get the first non-empty face
for (Direction direction : directions)
{
// quads = mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, dataMap);
@@ -148,17 +140,17 @@ public class BlockColorWrapper implements IBlockColorWrapper
int colorMultiplier;
// generate the block's color
// for (int frameIndex = 0; frameIndex < texture.getFrameCount(); frameIndex++)
//for (int frameIndex = 0; frameIndex < texture.getFrameCount(); frameIndex++)
int frameIndex = 0; // TODO
{
// textures normally use u and v instead of x and y
for (int u = 0; u < texture.getWidth(); u++)
for (int u = 0; u < texture.getHeight(); u++)
{
for (int v = 0; v < texture.getHeight(); v++)
for (int v = 0; v < texture.getWidth(); v++)
{
tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, frameIndex, u, v);
if (ColorUtil.getAlpha(TextureAtlasSpriteWrapper.getPixelRGBA(texture, frameIndex, u, v)) == 0)
continue;
@@ -208,7 +200,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
// we check which kind of tint we need to apply
this.grassTint = grassInstance() && toTint;
this.foliageTint = leavesInstance() && toTint;
this.folliageTint = leavesInstance() && toTint;
this.waterTint = waterIstance() && toTint;
@@ -220,7 +212,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
{
return block instanceof GrassBlock
|| block instanceof BushBlock
|| block instanceof GrowingPlantBlock;
|| block instanceof TallGrassBlock;
}
/** determine if the given block should use the biome's foliage color */
@@ -250,7 +242,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
@Override
public int getColor()
{
return color;
return color;
}
//------------//
@@ -273,7 +265,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
@Override
public boolean hasFolliageTint()
{
return foliageTint;
return folliageTint;
}
@Override
@@ -7,14 +7,19 @@ import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
import net.minecraft.core.BlockPos;
/**
* @author James Seibel
* @version 11-21-2021
*/
public class BlockPosWrapper extends AbstractBlockPosWrapper
{
private final BlockPos.MutableBlockPos blockPos;
private BlockPos.MutableBlockPos blockPos;
public BlockPosWrapper()
{
this.blockPos = new BlockPos.MutableBlockPos(0, 0, 0);
this.blockPos = new BlockPos.MutableBlockPos(0,0,0);
}
public BlockPosWrapper(int x, int y, int z)
@@ -22,26 +27,33 @@ public class BlockPosWrapper extends AbstractBlockPosWrapper
this.blockPos = new BlockPos.MutableBlockPos(x, y, z);
}
@Override
public void set(int x, int y, int z)
{
blockPos.set(x, y, z);
}
@Override
public int getX()
{
return blockPos.getX();
}
@Override
public int getY()
{
return blockPos.getY();
}
@Override
public int getZ()
{
return blockPos.getZ();
}
@Override
public int get(LodDirection.Axis axis)
{
return axis.choose(getX(), getY(), getZ());
@@ -52,18 +64,17 @@ public class BlockPosWrapper extends AbstractBlockPosWrapper
return blockPos;
}
@Override
public boolean equals(Object o)
@Override public boolean equals(Object o)
{
return blockPos.equals(o);
}
@Override
public int hashCode()
@Override public int hashCode()
{
return Objects.hash(blockPos);
}
@Override
public BlockPosWrapper offset(int x, int y, int z)
{
blockPos.set(blockPos.getX() + x, blockPos.getY() + y, blockPos.getZ() + z);
@@ -19,10 +19,8 @@ import net.minecraft.world.phys.shapes.VoxelShape;
/**
* This class wraps Minecraft's Block class
*
* @author ??
* @version 11-18-2021
* @author James Seibel
* @version 11-21-2021
*/
public class BlockShapeWrapper implements IBlockShapeWrapper
{
@@ -31,7 +29,7 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
public static BlockShapeWrapper WATER_SHAPE = new BlockShapeWrapper();
private final Block block;
private boolean toAvoid;
private final boolean toAvoid;
private boolean nonFull;
private boolean noCollision;
@@ -42,8 +40,8 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
this.nonFull = false;
this.noCollision = false;
this.toAvoid = ofBlockToAvoid();
setupShapes((ChunkWrapper) chunkWrapper, (BlockPosWrapper) blockPosWrapper);
//System.out.println(block + " non full " + nonFull + " no collision " + noCollision + " to avoid " + toAvoid);
setupShapes(chunkWrapper, blockPosWrapper);
System.out.println(block + " non full " + nonFull + " no collision " + noCollision + " to avoid " + toAvoid);
}
private BlockShapeWrapper()
@@ -58,7 +56,7 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
* this return a wrapper of the block in input
* @param block Block object to wrap
*/
static public BlockShapeWrapper getBlockShapeWrapper(Block block, IChunkWrapper chunkWrapper, AbstractBlockPosWrapper blockPosWrapper)
static public BlockShapeWrapper getBlockShapeWrapper(Block block, ChunkWrapper chunkWrapper, AbstractBlockPosWrapper blockPosWrapper)
{
//first we check if the block has already been wrapped
if (blockShapeWrapperMap.containsKey(block) && blockShapeWrapperMap.get(block) != null)
@@ -73,13 +71,13 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
return blockWrapper;
}
private void setupShapes(ChunkWrapper chunkWrapper, BlockPosWrapper blockPosWrapper)
private void setupShapes(IChunkWrapper chunkWrapper, AbstractBlockPosWrapper blockPosWrapper)
{
ChunkAccess chunk = chunkWrapper.getChunk();
BlockPos blockPos = blockPosWrapper.getBlockPos();
ChunkAccess chunk = ((ChunkWrapper) chunkWrapper).getChunk();
BlockPos blockPos = ((BlockPosWrapper) blockPosWrapper).getBlockPos();
boolean noCollisionSetted = false;
boolean nonFullSetted = false;
if (!block.defaultBlockState().getFluidState().isEmpty()) // || block instanceof SixWayBlock)
if (!block.defaultBlockState().getFluidState().isEmpty())// || block instanceof SixWayBlock)
{
noCollisionSetted = true;
nonFullSetted = true;
@@ -116,8 +114,7 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
{
return block.equals(Blocks.AIR)
|| block.equals(Blocks.CAVE_AIR)
|| block.equals(Blocks.BARRIER)
|| block.equals(Blocks.VOID_AIR);
|| block.equals(Blocks.BARRIER);
}
//-----------------//
//Avoidance getters//
@@ -11,48 +11,47 @@ import net.minecraft.world.level.ChunkPos;
/**
* This class wraps minecraft's ChunkPos class
*
* @author James Seibel
* @version 11-18-2021
* @version 11-21-2021
*/
public class ChunkPosWrapper extends AbstractChunkPosWrapper
{
private final ChunkPos chunkPos;
private net.minecraft.world.level.ChunkPos chunkPos;
public ChunkPosWrapper(ChunkPos newChunkPos)
{
this.chunkPos = newChunkPos;
}
public ChunkPosWrapper(BlockPos blockPos)
{
this.chunkPos = new ChunkPos(blockPos);
}
public ChunkPosWrapper(AbstractChunkPosWrapper newChunkPos)
{
this.chunkPos = ((ChunkPosWrapper) newChunkPos).chunkPos;
}
public ChunkPosWrapper(AbstractBlockPosWrapper blockPos)
public ChunkPosWrapper()
{
this.chunkPos = new ChunkPos(((BlockPosWrapper) blockPos).getBlockPos());
}
public ChunkPosWrapper(int chunkX, int chunkZ)
{
this.chunkPos = new ChunkPos(chunkX, chunkZ);
this.chunkPos = new ChunkPos(0, 0);
}
public ChunkPosWrapper()
{
this.chunkPos = new ChunkPos(0, 0);
public ChunkPosWrapper(BlockPos blockPos)
{
this.chunkPos = new ChunkPos(blockPos);
}
public ChunkPosWrapper(AbstractChunkPosWrapper newChunkPos)
{
this.chunkPos = ((ChunkPosWrapper) newChunkPos).chunkPos;
}
public ChunkPosWrapper(AbstractBlockPosWrapper blockPos)
{
this.chunkPos = new ChunkPos(((BlockPosWrapper) blockPos).getBlockPos());
}
public ChunkPosWrapper(int chunkX, int chunkZ)
{
this.chunkPos = new ChunkPos(chunkX, chunkZ);
}
public ChunkPosWrapper(ChunkPos pos)
{
this.chunkPos = pos;
}
@Override
public int getX()
{
@@ -94,8 +93,6 @@ public class ChunkPosWrapper extends AbstractChunkPosWrapper
return chunkPos;
}
@Override
public boolean equals(Object o)
{
@@ -107,11 +104,12 @@ public class ChunkPosWrapper extends AbstractChunkPosWrapper
{
return Objects.hash(chunkPos);
}
@Override
public BlockPosWrapper getWorldPosition()
public AbstractBlockPosWrapper getWorldPosition()
{
BlockPos blockPos = chunkPos.getWorldPosition();
// the parameter here is the y position
BlockPos blockPos = chunkPos.getMiddleBlockPosition(0);
return new BlockPosWrapper(blockPos.getX(), blockPos.getY(), blockPos.getZ());
}
@@ -3,31 +3,33 @@ package com.seibel.lod.fabric.wrappers.chunk;
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
import com.seibel.lod.core.wrapperInterfaces.block.IBlockColorWrapper;
import com.seibel.lod.core.wrapperInterfaces.block.IBlockShapeWrapper;
import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper;
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.lod.fabric.wrappers.WrapperUtil;
import com.seibel.lod.fabric.wrappers.block.BlockColorWrapper;
import com.seibel.lod.fabric.wrappers.block.BlockPosWrapper;
import com.seibel.lod.fabric.wrappers.block.BlockShapeWrapper;
import com.seibel.lod.fabric.wrappers.world.BiomeWrapper;
import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.chunk.ChunkAccess;
/**
*
* @author ??
* @version 11-17-2021
* @author James Seibel
* @version 11-21-2021
*/
public class ChunkWrapper implements IChunkWrapper
{
private final ChunkAccess chunk;
private final ChunkPosWrapper chunkPos;
private ChunkAccess chunk;
private AbstractChunkPosWrapper chunkPos;
@Override
public int getHeight()
{
public int getHeight(){
return chunk.getMaxBuildHeight();
}
@@ -37,8 +39,14 @@ public class ChunkWrapper implements IChunkWrapper
BlockState blockState = chunk.getBlockState(((BlockPosWrapper) blockPos).getBlockPos());
//This type of block is always in water
return ((blockState.getBlock() instanceof LiquidBlockContainer) && !(blockState.getBlock() instanceof SimpleWaterloggedBlock))
|| (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED));
if((blockState.getBlock() instanceof LiquidBlock))// && !(blockState.getBlock() instanceof IWaterLoggable))
return true;
//This type of block could be in water
if(blockState.getOptionalValue(BlockStateProperties.WATERLOGGED).isPresent() && blockState.getOptionalValue(BlockStateProperties.WATERLOGGED).get())
return true;
return false;
}
@Override
@@ -48,7 +56,7 @@ public class ChunkWrapper implements IChunkWrapper
}
@Override
public BiomeWrapper getBiome(int xRel, int yAbs, int zRel)
public IBiomeWrapper getBiome(int xRel, int yAbs, int zRel)
{
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(xRel >> 2, yAbs >> 2, zRel >> 2));
}
@@ -56,7 +64,7 @@ public class ChunkWrapper implements IChunkWrapper
@Override
public IBlockColorWrapper getBlockColorWrapper(AbstractBlockPosWrapper blockPos)
{
return BlockColorWrapper.getBlockColorWrapper(chunk.getBlockState(((BlockPosWrapper) blockPos).getBlockPos()).getBlock());
return BlockColorWrapper.getBlockColorWrapper(chunk.getBlockState(((BlockPosWrapper) blockPos).getBlockPos()), blockPos);
}
@Override
@@ -71,36 +79,52 @@ public class ChunkWrapper implements IChunkWrapper
this.chunkPos = new ChunkPosWrapper(chunk.getPos());
}
public ChunkAccess getChunk()
{
public ChunkAccess getChunk(){
return chunk;
}
@Override
public ChunkPosWrapper getPos()
public AbstractChunkPosWrapper getPos()
{
return chunkPos;
}
@Override
public boolean isLightCorrect()
{
public boolean isLightCorrect(){
return chunk.isLightCorrect();
}
public boolean
isWaterLogged(BlockPosWrapper blockPos)
{
BlockState blockState = chunk.getBlockState(blockPos.getBlockPos());
// //This type of block is always in water
// if((blockState.getBlock() instanceof ILiquidContainer) && !(blockState.getBlock() instanceof IWaterLoggable))
// return true;
//This type of block could be in water
if(blockState.getOptionalValue(BlockStateProperties.WATERLOGGED).isPresent() && blockState.getOptionalValue(BlockStateProperties.WATERLOGGED).get())
return true;
return false;
}
public int getEmittedBrightness(BlockPosWrapper blockPos)
{
return chunk.getLightEmission(blockPos.getBlockPos());
}
@Override
public boolean isWaterLogged(AbstractBlockPosWrapper blockPos)
{
BlockState blockState = chunk.getBlockState(((BlockPosWrapper)blockPos).getBlockPos());
//This type of block is always in water
return ((blockState.getBlock() instanceof LiquidBlockContainer) && !(blockState.getBlock() instanceof SimpleWaterloggedBlock))
|| (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED));
// TODO Auto-generated method stub
return false;
}
@Override
public int getEmittedBrightness(AbstractBlockPosWrapper blockPos)
{
return chunk.getLightEmission(((BlockPosWrapper)blockPos).getBlockPos());
// TODO Auto-generated method stub
return 0;
}
}
@@ -8,49 +8,49 @@ import com.seibel.lod.fabric.Config;
/**
* This holds the config defaults and setters/getters
* that should be hooked into the host mod loader (Fabric, Forge, etc.).
*
*
* @author James Seibel
* @version 11-16-2021
*/
public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
public static final LodConfigWrapperSingleton INSTANCE = new LodConfigWrapperSingleton();
private static final Client client = new Client();
@Override
public IClient client()
{
return client;
}
public static class Client implements IClient
{
public final IGraphics graphics;
public final IWorldGenerator worldGenerator;
public final IAdvanced advanced;
@Override
public IGraphics graphics()
{
return graphics;
}
@Override
public IWorldGenerator worldGenerator()
{
return worldGenerator;
}
@Override
public IAdvanced advanced()
{
return advanced;
}
//================//
// Client Configs //
//================//
@@ -60,8 +60,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
worldGenerator = new WorldGenerator();
advanced = new Advanced();
}
//==================//
// Graphics Configs //
//==================//
@@ -70,8 +70,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
public final IQuality quality;
public final IFogQuality fogQuality;
public final IAdvancedGraphics advancedGraphics;
@Override
public IQuality quality()
@@ -90,16 +90,16 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
return advancedGraphics;
}
Graphics()
{
quality = new Quality();
advancedGraphics = new AdvancedGraphics();
fogQuality = new FogQuality();
}
public static class Quality implements IQuality
{
@Override
@@ -112,8 +112,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.QualityOption.drawResolution = newHorizontalResolution;
}
@Override
public int getLodChunkRenderDistance()
{
@@ -124,8 +124,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.QualityOption.lodChunkRenderDistance = newLodChunkRenderDistance;
}
@Override
public VerticalQuality getVerticalQuality()
{
@@ -136,8 +136,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.QualityOption.verticalQuality = newVerticalQuality;
}
@Override
public HorizontalScale getHorizontalScale()
{
@@ -148,8 +148,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.QualityOption.horizontalScale = newHorizontalScale;
}
@Override
public HorizontalQuality getHorizontalQuality()
{
@@ -161,8 +161,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
Config.Client.Graphics.QualityOption.horizontalQuality = newHorizontalQuality;
}
}
public static class FogQuality implements IFogQuality
{
@Override
@@ -175,20 +175,34 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.FogQualityOption.fogDistance = newFogDistance;
}
@Override
public FogDrawOverride getFogDrawOverride()
public FogDrawMode getFogDrawMode()
{
return Config.Client.Graphics.FogQualityOption.fogDrawOverride;
return Config.Client.Graphics.FogQualityOption.fogDrawMode;
}
@Override
public void setFogDrawOverride(FogDrawOverride newFogDrawOverride)
public void setFogDrawMode(FogDrawMode setFogDrawMode)
{
Config.Client.Graphics.FogQualityOption.fogDrawOverride = newFogDrawOverride;
Config.Client.Graphics.FogQualityOption.fogDrawMode = setFogDrawMode;
}
@Override
public FogColorMode getFogColorMode()
{
return Config.Client.Graphics.FogQualityOption.fogColorMode;
}
@Override
public void setFogColorMode(FogColorMode newFogColorMode)
{
Config.Client.Graphics.FogQualityOption.fogColorMode = newFogColorMode;
}
@Override
public boolean getDisableVanillaFog()
{
@@ -200,8 +214,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
Config.Client.Graphics.FogQualityOption.disableVanillaFog = newDisableVanillaFog;
}
}
public static class AdvancedGraphics implements IAdvancedGraphics
{
@Override
@@ -214,8 +228,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.AdvancedGraphicsOption.lodTemplate = newLodTemplate;
}
@Override
public boolean getDisableDirectionalCulling()
{
@@ -226,8 +240,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.AdvancedGraphicsOption.disableDirectionalCulling = newDisableDirectionalCulling;
}
@Override
public boolean getAlwaysDrawAtMaxQuality()
{
@@ -238,8 +252,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.AdvancedGraphicsOption.alwaysDrawAtMaxQuality = newAlwaysDrawAtMaxQuality;
}
@Override
public VanillaOverdraw getVanillaOverdraw()
{
@@ -250,8 +264,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.AdvancedGraphicsOption.vanillaOverdraw = newVanillaOverdraw;
}
@Override
public GpuUploadMethod getGpuUploadMethod()
{
@@ -262,8 +276,19 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.Graphics.AdvancedGraphicsOption.gpuUploadMethod = newDisableVanillaFog;
}
@Override
public int getGpuUploadTimeoutInMilliseconds()
{
return Config.Client.Graphics.AdvancedGraphicsOption.gpuUploadTimeoutInMilleseconds;
}
@Override
public void setGpuUploadTimeoutInMilliseconds(int newTimeoutInMilliseconds) {
Config.Client.Graphics.AdvancedGraphicsOption.gpuUploadTimeoutInMilleseconds = newTimeoutInMilliseconds;
}
@Override
public boolean getUseExtendedNearClipPlane()
{
@@ -276,10 +301,10 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
}
}
}
//========================//
// WorldGenerator Configs //
//========================//
@@ -295,8 +320,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.WorldGenerator.generationPriority = newGenerationPriority;
}
@Override
public DistanceGenerationMode getDistanceGenerationMode()
{
@@ -307,8 +332,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.WorldGenerator.distanceGenerationMode = newDistanceGenerationMode;
}
@Override
public boolean getAllowUnstableFeatureGeneration()
{
@@ -319,8 +344,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.WorldGenerator.allowUnstableFeatureGeneration = newAllowUnstableFeatureGeneration;
}
@Override
public BlocksToAvoid getBlocksToAvoid()
{
@@ -332,10 +357,10 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
Config.Client.WorldGenerator.blocksToAvoid = newBlockToAvoid;
}
}
//============================//
// AdvancedModOptions Configs //
//============================//
@@ -344,8 +369,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
public final IThreading threading;
public final IDebugging debugging;
public final IBuffers buffers;
@Override
public IThreading threading()
{
@@ -365,15 +390,15 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
return buffers;
}
public Advanced()
{
threading = new Threading();
debugging = new Debugging();
buffers = new Buffers();
}
public static class Threading implements IThreading
{
@Override
@@ -386,8 +411,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.AdvancedModOptions.Threading.numberOfWorldGenerationThreads = newNumberOfWorldGenerationThreads;
}
@Override
public int getNumberOfBufferBuilderThreads()
{
@@ -399,10 +424,10 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
Config.Client.AdvancedModOptions.Threading.numberOfBufferBuilderThreads = newNumberOfWorldBuilderThreads;
}
}
//===============//
// Debug Options //
//===============//
@@ -418,8 +443,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.AdvancedModOptions.Debugging.drawLods = newDrawLods;
}
@Override
public DebugMode getDebugMode()
{
@@ -430,8 +455,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
Config.Client.AdvancedModOptions.Debugging.debugMode = newDebugMode;
}
@Override
public boolean getDebugKeybindingsEnabled()
{
@@ -443,8 +468,8 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
Config.Client.AdvancedModOptions.Debugging.enableDebugKeybindings = newEnableDebugKeybindings;
}
}
public static class Buffers implements IBuffers
{
@Override
@@ -458,6 +483,6 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
Config.Client.AdvancedModOptions.Buffers.rebuildTimes = newBufferRebuildTimes;
}
}
}
}
}
}
}
@@ -0,0 +1,43 @@
package com.seibel.lod.fabric.wrappers.config;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.gui.components.ImageButton;
/**
* Creates a button with a texture on it
*/
public class TexturedButtonWidget extends ImageButton {
public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, ResourceLocation texture, OnPress pressAction) {
super(x, y, width, height, u, v, texture, pressAction);
}
public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction) {
super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction);
}
public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction, Component text) {
super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, text);
}
public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction, OnTooltip tooltipSupplier, Component text) {
super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, tooltipSupplier, text);
}
@Override
public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
int i = this.getYImage(this.isHovered());
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
this.blit(matrices, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
this.blit(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
super.renderButton(matrices, mouseX, mouseY, delta);
}
}
@@ -1,8 +1,10 @@
package com.seibel.lod.fabric.wrappers.minecraft;
import java.awt.*;
import java.util.HashSet;
import com.mojang.math.Vector3d;
import org.lwjgl.opengl.GL20;
import com.mojang.math.Vector3f;
import com.seibel.lod.core.objects.math.Mat4f;
import com.seibel.lod.core.objects.math.Vec3d;
@@ -18,17 +20,19 @@ import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LevelRenderer.RenderChunkInfo;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher.CompiledChunk;
import net.minecraft.core.BlockPos;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.phys.Vec3;
/**
* A singleton that contains everything
* related to rendering in Minecraft.
*
* @author James Seibel
* @version 11-18-2021
* @version 11-26-2021
*/
public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
{
@@ -73,8 +77,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override
public Mat4f getDefaultProjectionMatrix(float partialTicks)
{
// return McObjectConverter.Convert(gameRenderer.getProjectionMatrix(gameRenderer.getMainCamera(), partialTicks, true));
return McObjectConverter.Convert(gameRenderer.getProjectionMatrix(partialTicks));
return McObjectConverter.Convert(gameRenderer.getProjectionMatrix(gameRenderer.getFov(gameRenderer.getMainCamera(), partialTicks, true)));
}
@Override
@@ -82,7 +85,23 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
{
return mc.options.gamma;
}
@Override
public Color getFogColor() {
float[] colorValues = new float[4];
GL20.glGetFloatv(GL20.GL_FOG_COLOR, colorValues);
return new Color(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
}
@Override
public Color getSkyColor() {
if (mc.level.dimensionType().hasSkyLight()) {
Vec3 colorValues = mc.level.getSkyColor(mc.gameRenderer.getMainCamera().getPosition(), mc.getFrameTime());
return new Color((float) colorValues.x, (float) colorValues.y, (float) colorValues.z);
} else
return new Color(0, 0, 0);
}
@Override
public double getFov(float partialTicks)
{
@@ -124,7 +143,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
// go through every RenderInfo to get the compiled chunks
LevelRenderer renderer = mc.levelRenderer;
for (LevelRenderer.RenderChunkInfo worldRenderer$LocalRenderInformationContainer : renderer.renderChunks)
for (RenderChunkInfo worldRenderer$LocalRenderInformationContainer : renderer.renderChunks)
{
CompiledChunk compiledChunk = worldRenderer$LocalRenderInformationContainer.chunk.getCompiledChunk();
if (!compiledChunk.hasNoRenderableLayers())
@@ -138,4 +157,5 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
return loadedPos;
}
}
@@ -58,7 +58,9 @@ import net.minecraft.core.Direction;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.dimension.DimensionType;
import org.jetbrains.annotations.Nullable;
/**
* A singleton that wraps the Minecraft class
@@ -114,12 +116,15 @@ public class MinecraftWrapper implements IMinecraftWrapper
//=================//
@Override
public float getShade(LodDirection lodDirection)
{
Direction mcDir = McObjectConverter.Convert(lodDirection);
return mc.level.getShade(mcDir, true);
public float getShade(LodDirection lodDirection) {
if (mc.level != null)
{
Direction mcDir = McObjectConverter.Convert(lodDirection);
return mc.level.getShade(mcDir, true);
}
else return 0.0f;
}
@Override
public boolean hasSinglePlayerServer()
{
@@ -211,7 +216,7 @@ public class MinecraftWrapper implements IMinecraftWrapper
{
return mc.player;
}
@Override
public boolean playerExists()
{
@@ -228,7 +233,8 @@ public class MinecraftWrapper implements IMinecraftWrapper
@Override
public ChunkPosWrapper getPlayerChunkPos()
{
return new ChunkPosWrapper(getPlayer().chunkPosition().x, getPlayer().chunkPosition().z);
ChunkPos playerPos = getPlayer().chunkPosition();
return new ChunkPosWrapper(playerPos.x, playerPos.z);
}
public Options getOptions()
@@ -241,16 +247,11 @@ public class MinecraftWrapper implements IMinecraftWrapper
return mc.getModelManager();
}
public ClientLevel getClientWorld()
public ClientLevel getClientLevel()
{
return mc.level;
}
/**
* Attempts to get the ServerWorld for the dimension
* the user is currently in.
* @returns null if no ServerWorld is available
*/
@Override
public IWorldWrapper getWrappedServerWorld()
{
@@ -276,6 +277,37 @@ public class MinecraftWrapper implements IMinecraftWrapper
return WorldWrapper.getWorldWrapper(serverWorld);
}
public WorldWrapper getWrappedClientLevel()
{
return WorldWrapper.getWorldWrapper(mc.level);
}
public WorldWrapper getWrappedServerLevel()
{
if (mc.level == null)
return null;
DimensionType dimension = mc.level.dimensionType();
IntegratedServer server = mc.getSingleplayerServer();
if (server == null)
return null;
Iterable<ServerLevel> worlds = server.getAllLevels();
ServerLevel returnWorld = null;
for (ServerLevel world : worlds)
{
if (world.dimensionType() == dimension)
{
returnWorld = world;
break;
}
}
return WorldWrapper.getWorldWrapper(returnWorld);
}
@Nullable
@Override
public IWorldWrapper getWrappedClientWorld()
{
@@ -296,8 +328,7 @@ public class MinecraftWrapper implements IMinecraftWrapper
else if (mc.getProfiler() != profilerWrapper.profiler)
profilerWrapper.profiler = mc.getProfiler();
return profilerWrapper;
}
return profilerWrapper; }
public ClientPacketListener getConnection()
{
@@ -384,11 +415,9 @@ public class MinecraftWrapper implements IMinecraftWrapper
CrashReport report = new CrashReport(errorMessage, exception);
Minecraft.crash(report);
}
}
@@ -5,8 +5,6 @@ import com.seibel.lod.core.wrapperInterfaces.minecraft.IProfilerWrapper;
import net.minecraft.util.profiling.ProfilerFiller;
/**
*
*
* @author James Seibel
* @version 11-20-2021
*/
@@ -3,24 +3,22 @@ package com.seibel.lod.fabric.wrappers.misc;
import com.mojang.blaze3d.platform.NativeImage;
import com.seibel.lod.core.wrapperInterfaces.misc.ILightMapWrapper;
/**
*
* @author Leonardo Amato
* @version 11-13-2021
* @author James Seibel
* @version 11-21-2021
*/
public class LightMapWrapper implements ILightMapWrapper
{
private NativeImage lightMap = null;
static NativeImage lightMap = null;
public LightMapWrapper(NativeImage newlightMap)
public LightMapWrapper(NativeImage newLightMap)
{
lightMap = newlightMap;
lightMap = newLightMap;
}
public void setLightMap(NativeImage newlightMap)
public static void setLightMap(NativeImage newLightMap)
{
lightMap = newlightMap;
lightMap = newLightMap;
}
@Override
@@ -26,9 +26,7 @@ import com.seibel.lod.fabric.wrappers.block.BlockPosWrapper;
import net.minecraft.client.renderer.BiomeColors;
/**
*
* @author Cola?
* @version 11-15-2021
*/
@@ -1,34 +1,49 @@
/*
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.fabric.wrappers.world;
import java.awt.Color;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.seibel.lod.core.util.ColorUtil;
import com.seibel.lod.core.util.LodUtil;
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.lod.fabric.wrappers.block.BlockColorSingletonWrapper;
import com.seibel.lod.fabric.wrappers.block.BlockColorWrapper;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.MaterialColor;
/**
* This class wraps the minecraft BlockPos.Mutable (and BlockPos) class
*
* @author James Seibel
* @version 11-15-2021
*/
//This class wraps the minecraft BlockPos.Mutable (and BlockPos) class
public class BiomeWrapper implements IBiomeWrapper
{
public static final ConcurrentMap<Biome, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
private final Biome biome;
private Biome biome;
public BiomeWrapper(Biome biome)
{
this.biome = biome;
}
static public BiomeWrapper getBiomeWrapper(Biome biome)
static public IBiomeWrapper getBiomeWrapper(Biome biome)
{
//first we check if the biome has already been wrapped
if(biomeWrapperMap.containsKey(biome) && biomeWrapperMap.get(biome) != null)
@@ -49,72 +64,57 @@ public class BiomeWrapper implements IBiomeWrapper
public int getColorForBiome(int x, int z)
{
int colorInt;
int tintValue = 0;
switch (biome.getBiomeCategory())
{
case NETHER:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.NETHERRACK).getColor();
colorInt = Blocks.NETHERRACK.defaultBlockState().getMaterial().getColor().col;
break;
case THEEND:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.END_STONE).getColor();
colorInt = Blocks.END_STONE.defaultBlockState().getMaterial().getColor().col;
break;
case BEACH:
case DESERT:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.SAND).getColor();
colorInt = Blocks.SAND.defaultBlockState().getMaterial().getColor().col;
break;
case EXTREME_HILLS:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.STONE).getColor();
colorInt = Blocks.STONE.defaultMaterialColor().col;
break;
case MUSHROOM:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.MYCELIUM).getColor();
colorInt = MaterialColor.COLOR_LIGHT_GRAY.col;
break;
case ICY:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.SNOW).getColor();
colorInt = Blocks.SNOW.defaultMaterialColor().col;
break;
case MESA:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.RED_SAND).getColor();
colorInt = Blocks.RED_SAND.defaultMaterialColor().col;
break;
case OCEAN:
case RIVER:
colorInt = BlockColorSingletonWrapper.INSTANCE.getWaterColor().getColor();
tintValue = biome.getWaterColor();
break;
case PLAINS:
case SAVANNA:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.GRASS_BLOCK).getColor();
tintValue = biome.getGrassColor(x, z);
colorInt = ColorUtil.multiplyRGBcolors(colorInt,tintValue);
break;
case TAIGA:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.SPRUCE_LEAVES).getColor();
tintValue = biome.getFoliageColor();
colorInt = ColorUtil.multiplyRGBcolors(colorInt,tintValue);
break;
case JUNGLE:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.JUNGLE_LEAVES).getColor();
tintValue = biome.getFoliageColor();
colorInt = ColorUtil.multiplyRGBcolors(colorInt,tintValue);
colorInt = biome.getWaterColor();
break;
case NONE:
default:
case SWAMP:
case FOREST:
colorInt = BlockColorWrapper.getBlockColorWrapper(Blocks.OAK_LEAVES).getColor();
tintValue = biome.getFoliageColor();
colorInt = ColorUtil.multiplyRGBcolors(colorInt,tintValue);
case TAIGA:
case JUNGLE:
case PLAINS:
case SAVANNA:
case SWAMP:
default:
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
break;
}
return colorInt;
@@ -139,13 +139,13 @@ public class BiomeWrapper implements IBiomeWrapper
}
@Override public boolean equals(Object o)
@Override public boolean equals(Object obj)
{
if (this == o)
if (this == obj)
return true;
if (!(o instanceof BiomeWrapper))
if (!(obj instanceof BiomeWrapper))
return false;
BiomeWrapper that = (BiomeWrapper) o;
BiomeWrapper that = (BiomeWrapper) obj;
return Objects.equals(biome, that.biome);
}
@@ -1,20 +1,40 @@
/*
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.fabric.wrappers.world;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
import net.minecraft.world.level.dimension.DimensionType;
/**
*
* @author ??
* @version 11-15-2021
* @author James Seibel
* @version 11-21-2021
*/
public class DimensionTypeWrapper implements IDimensionTypeWrapper
{
private static final ConcurrentMap<DimensionType, DimensionTypeWrapper> dimensionTypeWrapperMap = new ConcurrentHashMap<>();
private final DimensionType dimensionType;
private DimensionType dimensionType;
public DimensionTypeWrapper(DimensionType dimensionType)
{
@@ -36,12 +56,18 @@ public class DimensionTypeWrapper implements IDimensionTypeWrapper
return dimensionTypeWrapper;
}
public static void clearMap()
{
dimensionTypeWrapperMap.clear();
}
@Override
public String getDimensionName()
{
return dimensionType.effectsLocation().getPath();
}
@Override
public boolean hasCeiling()
{
@@ -1,3 +1,22 @@
/*
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.fabric.wrappers.world;
import java.io.File;
@@ -6,28 +25,30 @@ import java.util.concurrent.ConcurrentMap;
import com.seibel.lod.core.enums.WorldType;
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.fabric.wrappers.block.BlockPosWrapper;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LightLayer;
import org.jetbrains.annotations.Nullable;
/**
*
* @author James Seibel
* @author ??
* @version 11-15-2021
* @version 11-21-2021
*/
public class WorldWrapper implements IWorldWrapper
{
private static final ConcurrentMap<Level, WorldWrapper> worldWrapperMap = new ConcurrentHashMap<>();
private final Level world;
private static final ConcurrentMap<LevelAccessor, WorldWrapper> worldWrapperMap = new ConcurrentHashMap<>();
private final LevelAccessor world;
public final WorldType worldType;
public WorldWrapper(Level newWorld)
public WorldWrapper(LevelAccessor newWorld)
{
world = newWorld;
@@ -40,8 +61,8 @@ public class WorldWrapper implements IWorldWrapper
}
public static WorldWrapper getWorldWrapper(Level world)
@Nullable
public static WorldWrapper getWorldWrapper(LevelAccessor world)
{
if (world == null) return null;
//first we check if the biome has already been wrapped
@@ -61,9 +82,10 @@ public class WorldWrapper implements IWorldWrapper
{
worldWrapperMap.clear();
}
@Override
public WorldType getWorldType() {
public WorldType getWorldType()
{
return worldType;
}
@@ -72,26 +94,26 @@ public class WorldWrapper implements IWorldWrapper
{
return DimensionTypeWrapper.getDimensionTypeWrapper(world.dimensionType());
}
@Override
public int getBlockLight(AbstractBlockPosWrapper blockPos)
{
return world.getLightEngine().blockEngine.getLightValue(((BlockPosWrapper) blockPos).getBlockPos());
return world.getBrightness(LightLayer.BLOCK, ((BlockPosWrapper) blockPos).getBlockPos());
}
@Override
public int getSkyLight(AbstractBlockPosWrapper blockPos)
{
return world.getLightEngine().skyEngine.getLightValue(((BlockPosWrapper) blockPos).getBlockPos());
return world.getBrightness(LightLayer.SKY, ((BlockPosWrapper) blockPos).getBlockPos());
}
@Override
public BiomeWrapper getBiome(AbstractBlockPosWrapper blockPos)
public IBiomeWrapper getBiome(AbstractBlockPosWrapper blockPos)
{
return BiomeWrapper.getBiomeWrapper(world.getBiome(((BlockPosWrapper) blockPos).getBlockPos()));
}
public Level getWorld()
public LevelAccessor getWorld()
{
return world;
}
@@ -128,7 +150,7 @@ public class WorldWrapper implements IWorldWrapper
throw new UnsupportedOperationException("getSaveFolder can only be called for ServerWorlds.");
ServerChunkCache chunkSource = ((ServerLevel) world).getChunkSource();
return chunkSource.dataStorage.dataFolder;
return chunkSource.getDataStorage().dataFolder;
}
@@ -27,8 +27,6 @@ import java.util.stream.Stream;
import com.seibel.lod.core.util.LodUtil;
import com.seibel.lod.fabric.wrappers.WrapperUtil;
import com.sun.jna.Structure;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.RegistryAccess;
@@ -60,6 +58,7 @@ import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.lighting.LevelLightEngine;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.phys.AABB;
@@ -136,8 +135,8 @@ public class LodServerWorld implements WorldGenLevel
}
@Override
public boolean isFluidAtPosition(BlockPos pos, Predicate<FluidState> state) {
return state.test(chunk.getFluidState(pos));
public boolean isFluidAtPosition(BlockPos blockPos, Predicate<FluidState> predicate) {
return predicate.test(chunk.getFluidState(blockPos));
}
@Override
@@ -157,9 +156,9 @@ public class LodServerWorld implements WorldGenLevel
{
return serverWorld.startsForFeature(p_241827_1_, p_241827_2_);
}
@Override
public TickList getLiquidTicks()
public TickList<Fluid> getLiquidTicks()
{
return EmptyTickList.empty();
}
@@ -194,7 +193,7 @@ public class LodServerWorld implements WorldGenLevel
{
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public void playSound(Player player, BlockPos pos, SoundEvent soundIn, SoundSource category, float volume,
float pitch)
@@ -220,13 +219,13 @@ public class LodServerWorld implements WorldGenLevel
{
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public float getShade(Direction p_230487_1_, boolean p_230487_2_)
{
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public WorldBorder getWorldBorder()
{
@@ -287,13 +286,13 @@ public class LodServerWorld implements WorldGenLevel
}
// TODO: Check if this causes any issues
@Override
public void gameEvent(@Nullable Entity entity, GameEvent gameEvent, BlockPos blockPos) {
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public List<Entity> getEntities(Entity arg0, AABB arg1, Predicate<? super Entity> arg2)
{
@@ -5,6 +5,9 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
@@ -26,20 +29,16 @@ import net.minecraft.core.Registry;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ThreadedLevelLightEngine;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.SnowAndFreezeFeature;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
/**
* This is used for generating chunks
* in a variety of detail and threading levels.
*
* @author coolGi2007
* @author James Seibel
* @version 11-23-2021
* @version 11-13-2021
*/
public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
{
@@ -51,6 +50,8 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
* features that could cause issues down the line.
*/
private static final ConcurrentHashMap<Integer, ConfiguredFeature<?, ?>> FEATURES_TO_AVOID = new ConcurrentHashMap<>();
private static ExecutorService Executor = Executors.newSingleThreadExecutor();
public final ServerLevel serverWorld;
@@ -76,30 +77,29 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
@Override
public void generateBiomesOnly(AbstractChunkPosWrapper pos, DistanceGenerationMode generationMode)
{
/*
List<ChunkAccess> chunkList = new LinkedList<>();
ProtoChunk chunk = new ProtoChunk((ChunkPosWrapper) pos, UpgradeData.EMPTY, serverWorld);
ProtoChunk chunk = new ProtoChunk(((ChunkPosWrapper) pos).getChunkPos(), UpgradeData.EMPTY, serverWorld);
chunkList.add(chunk);
ServerChunkCache chunkSource = serverWorld.getChunkSource();
ChunkGenerator chunkGen = chunkSource.getGenerator();
// generate the terrain (this is thread safe)
// ChunkStatus.EMPTY.generate(serverWorld, chunkGen, serverWorld.getStructureManager(), (ThreadedLevelLightEngine) serverWorld.getLightEngine(), null, chunkList);
ChunkStatus.EMPTY.generate(Executor, serverWorld, chunkGen, serverWorld.getStructureManager(), (ThreadedLevelLightEngine) serverWorld.getLightEngine(), null, chunkList);
// override the chunk status, so we can run the next generator stage
chunk.setStatus(ChunkStatus.STRUCTURE_REFERENCES);
chunkGen.createBiomes(serverWorld.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), chunk);
chunk.setStatus(ChunkStatus.STRUCTURE_REFERENCES);
// generate fake height data for this LOD
int seaLevel = serverWorld.getSeaLevel();
boolean simulateHeight = generationMode == DistanceGenerationMode.BIOME_ONLY_SIMULATE_HEIGHT;
boolean inTheEnd = false;
// add fake heightmap data so our LODs aren't at height 0
Heightmap heightmap = new Heightmap(chunk, WrapperUtil.DEFAULT_HEIGHTMAP);
for (int x = 0; x < LodUtil.CHUNK_WIDTH && !inTheEnd; x++)
@@ -115,7 +115,7 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
case NETHER:
heightmap.setHeight(x, z, serverWorld.getHeight() / 2);
break;
case EXTREME_HILLS:
heightmap.setHeight(x, z, seaLevel + 30);
break;
@@ -129,16 +129,16 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
case NONE:
heightmap.setHeight(x, z, 0);
break;
case OCEAN:
case RIVER:
heightmap.setHeight(x, z, seaLevel);
break;
case THEEND:
inTheEnd = true;
break;
// DESERT
// FOREST
// ICY
@@ -160,10 +160,10 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
}
}// z
}// x
chunk.setHeightmap(WrapperUtil.DEFAULT_HEIGHTMAP, heightmap.getRawData());
if (!inTheEnd)
{
lodBuilder.generateLodNodeFromChunk(lodDim, new ChunkWrapper(chunk), new LodBuilderConfig(true, true, false));
@@ -181,7 +181,6 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
// long startTime = System.currentTimeMillis();
// long endTime = System.currentTimeMillis();
// System.out.println(endTime - startTime);
*/
}
@@ -189,9 +188,8 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
@Override
public void generateSurface(AbstractChunkPosWrapper pos)
{
/*
List<ChunkAccess> chunkList = new LinkedList<>();
ProtoChunk chunk = new ProtoChunk(((ChunkPosWrapper) pos).getChunkPos(), UpgradeData.EMPTY);
ProtoChunk chunk = new ProtoChunk(((ChunkPosWrapper) pos).getChunkPos(), UpgradeData.EMPTY, serverWorld);
chunkList.add(chunk);
LodServerWorld lodServerWorld = new LodServerWorld(serverWorld, chunk);
@@ -202,17 +200,18 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
// generate the terrain (this is thread safe)
ChunkStatus.EMPTY.generate(serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
ChunkStatus.EMPTY.generate(Executor, serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
// override the chunk status, so we can run the next generator stage
chunk.setStatus(ChunkStatus.STRUCTURE_REFERENCES);
chunkGen.createBiomes(serverWorld.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), chunk);
ChunkStatus.NOISE.generate(serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
ChunkStatus.SURFACE.generate(serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
ChunkStatus.NOISE.generate(Executor, serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
// TODO[FABRIC]: Find whay this dosnt work
ChunkStatus.SURFACE.generate(Executor, serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
// this feature has been proven to be thread safe,
// so we will add it
IceAndSnowFeature snowFeature = new IceAndSnowFeature(NoFeatureConfig.CODEC);
snowFeature.place(lodServerWorld, chunkGen, serverWorld.random, chunk.getPos().getWorldPosition(), null);
// SnowAndFreezeFeature snowFeature = new SnowAndFreezeFeature(NoFeatureConfig.CODEC);
// snowFeature.place(lodServerWorld, chunkGen, serverWorld.random, chunk.getPos().getWorldPosition(), null);
lodBuilder.generateLodNodeFromChunk(lodDim, new ChunkWrapper(chunk), new LodBuilderConfig(DistanceGenerationMode.SURFACE));
@@ -220,8 +219,8 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
/*TODO if we want to use Biome utils and terrain utils for overworld
* lodBuilder.generateLodNodeFromChunk(lodDim, pos ,detailLevel, serverWorld.getSeed());*/
}
/**
* takes about 15 - 20 ms
* <p>
@@ -231,25 +230,25 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
@Override
public void generateFeatures(AbstractChunkPosWrapper pos)
{
/*
List<ChunkAccess> chunkList = new LinkedList<>();
ProtoChunk chunk = new ProtoChunk(((ChunkPosWrapper) pos).getChunkPos(), UpgradeData.EMPTY);
ProtoChunk chunk = new ProtoChunk(((ChunkPosWrapper) pos).getChunkPos(), UpgradeData.EMPTY, serverWorld);
chunkList.add(chunk);
LodServerWorld lodServerWorld = new LodServerWorld(serverWorld, chunk);
ServerChunkProvider chunkSource = serverWorld.getChunkSource();
ServerWorldLightManager lightEngine = (ServerWorldLightManager) serverWorld.getLightEngine();
TemplateManager templateManager = serverWorld.getStructureManager();
ChunkGenerator chunkGen = chunkSource.generator;
ServerChunkCache chunkSource = serverWorld.getChunkSource();
ThreadedLevelLightEngine lightEngine = (ThreadedLevelLightEngine) serverWorld.getLightEngine();
StructureManager templateManager = serverWorld.getStructureManager();
ChunkGenerator chunkGen = chunkSource.getGenerator();
// generate the terrain (this is thread safe)
ChunkStatus.EMPTY.generate(serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
ChunkStatus.EMPTY.generate(Executor, serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
// override the chunk status, so we can run the next generator stage
chunk.setStatus(ChunkStatus.STRUCTURE_REFERENCES);
chunkGen.createBiomes(serverWorld.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), chunk);
ChunkStatus.NOISE.generate(serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
ChunkStatus.SURFACE.generate(serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
ChunkStatus.NOISE.generate(Executor, serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
// TODO[FABRIC]: Find whay this dosnt work
ChunkStatus.SURFACE.generate(Executor, serverWorld, chunkGen, templateManager, lightEngine, null, chunkList);
// get all the biomes in the chunk
@@ -337,7 +336,6 @@ public class WorldGeneratorWrapper extends AbstractWorldGeneratorWrapper
// generate a Lod like normal
lodBuilder.generateLodNodeFromChunk(lodDim, new ChunkWrapper(chunk), new LodBuilderConfig(DistanceGenerationMode.FEATURES));
*/
}
@@ -1,97 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common;
import java.util.ArrayList;
import java.util.List;
public class WorldWorkerManager
{
private static List<IWorker> workers = new ArrayList<IWorker>();
private static long startTime = -1;
private static int index = 0;
public static void tick(boolean start)
{
if (start)
{
startTime = System.currentTimeMillis();
return;
}
index = 0;
IWorker task = getNext();
if (task == null)
return;
long time = 50 - (System.currentTimeMillis() - startTime);
if (time < 10)
time = 10; //If ticks are lagging, give us at least 10ms to do something.
time += System.currentTimeMillis();
while (System.currentTimeMillis() < time && task != null)
{
boolean again = task.doWork();
if (!task.hasWork())
{
remove(task);
task = getNext();
}
else if (!again)
{
task = getNext();
}
}
}
public static synchronized void addWorker(IWorker worker)
{
workers.add(worker);
}
private static synchronized IWorker getNext()
{
return workers.size() > index ? workers.get(index++) : null;
}
private static synchronized void remove(IWorker worker)
{
workers.remove(worker);
index--;
}
//Internal only, used to clear everything when the server shuts down.
public static synchronized void clear()
{
workers.clear();
}
public static interface IWorker
{
boolean hasWork();
/**
* Perform a task, returning true from this will have the manager call this function again this tick if there is time left.
* Returning false will skip calling this worker until next tick.
*/
boolean doWork();
}
}