Updated core

This commit is contained in:
coolGi2007
2021-12-11 04:05:48 +00:00
parent 4fdad05252
commit cb0516cae8
8 changed files with 135 additions and 163 deletions
@@ -40,7 +40,7 @@ public class BlockColorSingletonWrapper implements IBlockColorSingletonWrapper
@Override
public IBlockColorWrapper getWaterColor()
{
return BlockColorWrapper.getBlockColorWrapper(Blocks.WATER.defaultBlockState(), new BlockPosWrapper(0,0, 0));
return BlockColorWrapper.getBlockColorWrapper(Blocks.WATER);
}
}
@@ -32,50 +32,62 @@ import net.minecraft.world.level.block.state.BlockState;
public class BlockColorWrapper implements IBlockColorWrapper
{
//set of block which require tint
public static final ConcurrentMap<Block, IBlockColorWrapper> blockColorWrapperMap = new ConcurrentHashMap<>();
//public static final ModelDataMap dataMap = new ModelDataMap.Builder().build();
public static final AbstractBlockPosWrapper blockPos = new BlockPosWrapper(0,0,0);
public static Random random = new Random(0);
public static final ConcurrentMap<Block, BlockColorWrapper> blockColorWrapperMap = new ConcurrentHashMap<>();
// public static final ModelDataMap dataMap = new ModelDataMap.Builder().build();
public static final AbstractBlockPosWrapper blockPos = new BlockPosWrapper(0, 0, 0);
public static final 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 Block block;
private final Block block;
private int color;
private boolean isColored;
private boolean toTint;
private boolean folliageTint;
private boolean foliageTint;
private boolean grassTint;
private boolean waterTint;
/**Constructor only require for the block instance we are wrapping**/
public BlockColorWrapper(BlockState blockState, AbstractBlockPosWrapper blockPosWrapper)
public BlockColorWrapper(Block block)
{
this.block = blockState.getBlock();
this.block = block;
this.color = 0;
this.isColored = true;
this.toTint = false;
this.folliageTint = false;
this.foliageTint = false;
this.grassTint = false;
this.waterTint = false;
setupColorAndTint(blockState,blockPosWrapper);
System.out.println(block + " color " + Integer.toHexString(color) + " to tint " + toTint + " folliageTint " + folliageTint + " grassTint " + grassTint + " waterTint " + waterTint);
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);
}
/**
* this return a wrapper of the block in input
* @param blockState of the block to wrap
* @param block object of the block to wrap
*/
static public IBlockColorWrapper getBlockColorWrapper(BlockState blockState, AbstractBlockPosWrapper blockPosWrapper)
public static IBlockColorWrapper getBlockColorWrapper(Block block)
{
//first we check if the block has already been wrapped
if (blockColorWrapperMap.containsKey(blockState.getBlock()) && blockColorWrapperMap.get(blockState.getBlock()) != null)
return blockColorWrapperMap.get(blockState.getBlock());
if (blockColorWrapperMap.containsKey(block) && blockColorWrapperMap.get(block) != null)
return blockColorWrapperMap.get(block);
//if it hasn't been created yet, we create it and save it in the map
IBlockColorWrapper blockWrapper = new BlockColorWrapper(blockState, blockPosWrapper);
blockColorWrapperMap.put(blockState.getBlock(), blockWrapper);
BlockColorWrapper blockWrapper = new BlockColorWrapper(block);
blockColorWrapperMap.put(block, blockWrapper);
//we return the newly created wrapper
return blockWrapper;
@@ -85,8 +97,10 @@ public class BlockColorWrapper implements IBlockColorWrapper
* Generate the color of the given block from its texture
* and store it for later use.
*/
private void setupColorAndTint(BlockState blockState, AbstractBlockPosWrapper blockPosWrapper)
private void setupColorAndTint()
{
BlockState blockState = block.defaultBlockState();
BlockPosWrapper blockPosWrapper = new BlockPosWrapper();
MinecraftWrapper mc = MinecraftWrapper.INSTANCE;
TextureAtlasSprite texture;
List<BakedQuad> quads = null;
@@ -97,11 +111,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
// first step is to check if this block has a tinted face
for (Direction direction : directions)
{
if (LodCommonMain.forge) {
quads = LodCommonMain.forgeMethodCaller.getQuads(mc, block, blockState, direction, random);
} else {
quads = mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random);
}
quads = mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random);
listSize = Math.max(listSize, quads.size());
for (BakedQuad bakedQuad : quads)
{
@@ -116,11 +126,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
//now we get the first non-empty face
for (Direction direction : directions)
{
if (LodCommonMain.forge) {
quads = LodCommonMain.forgeMethodCaller.getQuads(mc, block, blockState, direction, random);
} else {
quads = mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random);
}
quads = mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random);
if (!quads.isEmpty())
break;
}
@@ -147,13 +153,13 @@ 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.getHeight(); u++)
for (int u = 0; u < texture.getWidth(); u++)
{
for (int v = 0; v < texture.getWidth(); v++)
for (int v = 0; v < texture.getHeight(); v++)
{
tempColor = TextureAtlasSpriteWrapper.getPixelRGBA(texture, frameIndex, u, v);
@@ -207,7 +213,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
// we check which kind of tint we need to apply
this.grassTint = grassInstance() && toTint;
this.folliageTint = leavesInstance() && toTint;
this.foliageTint = leavesInstance() && toTint;
this.waterTint = waterIstance() && toTint;
@@ -219,6 +225,9 @@ public class BlockColorWrapper implements IBlockColorWrapper
{
return block instanceof GrassBlock
|| block instanceof BushBlock
// || block instanceof IGrowable
// || block instanceof AbstractPlantBlock
// || block instanceof AbstractTopPlantBlock
|| block instanceof TallGrassBlock;
}
@@ -235,10 +244,9 @@ public class BlockColorWrapper implements IBlockColorWrapper
{
return block == Blocks.WATER;
}
@Override
public String getName()
{
public String getName(){
return block.getName().toString();
}
@@ -278,7 +286,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
@Override
public boolean hasFolliageTint()
{
return folliageTint;
return foliageTint;
}
@Override
@@ -304,5 +312,4 @@ public class BlockColorWrapper implements IBlockColorWrapper
{
return Objects.hash(block);
}
}
@@ -34,13 +34,13 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
private boolean noCollision;
/**Constructor only require for the block instance we are wrapping**/
public BlockShapeWrapper(Block block, IChunkWrapper chunkWrapper, AbstractBlockPosWrapper blockPosWrapper)
public BlockShapeWrapper(Block block, IChunkWrapper chunkWrapper, int x, int y, int z)
{
this.block = block;
this.nonFull = false;
this.noCollision = false;
this.toAvoid = ofBlockToAvoid();
setupShapes(chunkWrapper, blockPosWrapper);
setupShapes(chunkWrapper, x, y, z);
System.out.println(block + " non full " + nonFull + " no collision " + noCollision + " to avoid " + toAvoid);
}
@@ -56,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, ChunkWrapper chunkWrapper, AbstractBlockPosWrapper blockPosWrapper)
static public BlockShapeWrapper getBlockShapeWrapper(Block block, ChunkWrapper chunkWrapper, int x, int y, int z)
{
//first we check if the block has already been wrapped
if (blockShapeWrapperMap.containsKey(block) && blockShapeWrapperMap.get(block) != null)
@@ -64,17 +64,17 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
//if it hasn't been created yet, we create it and save it in the map
BlockShapeWrapper blockWrapper = new BlockShapeWrapper(block, chunkWrapper, blockPosWrapper);
BlockShapeWrapper blockWrapper = new BlockShapeWrapper(block, chunkWrapper, x, y, z);
blockShapeWrapperMap.put(block, blockWrapper);
//we return the newly created wrapper
return blockWrapper;
}
private void setupShapes(IChunkWrapper chunkWrapper, AbstractBlockPosWrapper blockPosWrapper)
private void setupShapes(IChunkWrapper chunkWrapper, int x, int y, int z)
{
ChunkAccess chunk = ((ChunkWrapper) chunkWrapper).getChunk();
BlockPos blockPos = ((BlockPosWrapper) blockPosWrapper).getBlockPos();
BlockPos blockPos = new BlockPos(x, y, z);
boolean noCollisionSetted = false;
boolean nonFullSetted = false;
if (!block.defaultBlockState().getFluidState().isEmpty())// || block instanceof SixWayBlock)
@@ -156,4 +156,4 @@ public class BlockShapeWrapper implements IBlockShapeWrapper
{
return Objects.hash(block);
}
}
}
@@ -12,10 +12,15 @@ import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
import com.seibel.lod.common.wrappers.block.BlockShapeWrapper;
import com.seibel.lod.common.wrappers.world.BiomeWrapper;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.Heightmap;
/**
*
@@ -24,9 +29,11 @@ import net.minecraft.world.level.chunk.ChunkAccess;
*/
public class ChunkWrapper implements IChunkWrapper
{
private ChunkAccess chunk;
private AbstractChunkPosWrapper chunkPos;
private final int CHUNK_SECTION_SHIFT = 4;
private final int CHUNK_SECTION_MASK = 0b1111;
private final int CHUNK_SIZE_SHIFT = 4;
private final int CHUNK_SIZE_MASK = 0b1111;
@Override
public int getHeight(){
@@ -34,9 +41,9 @@ public class ChunkWrapper implements IChunkWrapper
}
@Override
public boolean isPositionInWater(AbstractBlockPosWrapper blockPos)
public boolean isPositionInWater(int x, int y, int z)
{
BlockState blockState = chunk.getBlockState(((BlockPosWrapper) blockPos).getBlockPos());
BlockState blockState = chunk.getSections()[y >> CHUNK_SECTION_SHIFT].getBlockState(x & CHUNK_SIZE_MASK, y & CHUNK_SECTION_MASK, z & CHUNK_SIZE_MASK);
//This type of block is always in water
if((blockState.getBlock() instanceof LiquidBlock))// && !(blockState.getBlock() instanceof IWaterLoggable))
@@ -56,36 +63,74 @@ public class ChunkWrapper implements IChunkWrapper
}
@Override
public IBiomeWrapper getBiome(int xRel, int yAbs, int zRel)
public IBiomeWrapper getBiome(int x, int y, int z)
{
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(xRel >> 2, yAbs >> 2, zRel >> 2));
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome((x & CHUNK_SIZE_MASK) >> 2, y >> 2, (z & CHUNK_SIZE_MASK) >> 2));
}
@Override
public IBlockColorWrapper getBlockColorWrapper(AbstractBlockPosWrapper blockPos)
public IBlockColorWrapper getBlockColorWrapper(int x, int y, int z)
{
return BlockColorWrapper.getBlockColorWrapper(chunk.getBlockState(((BlockPosWrapper) blockPos).getBlockPos()), blockPos);
Block block = chunk.getSections()[y >> CHUNK_SECTION_SHIFT].getBlockState(x & CHUNK_SIZE_MASK, y & CHUNK_SECTION_MASK, z & CHUNK_SIZE_MASK).getBlock();
return BlockColorWrapper.getBlockColorWrapper(block);
}
@Override
public IBlockShapeWrapper getBlockShapeWrapper(AbstractBlockPosWrapper blockPos)
public IBlockShapeWrapper getBlockShapeWrapper(int x, int y, int z)
{
return BlockShapeWrapper.getBlockShapeWrapper(chunk.getBlockState(((BlockPosWrapper) blockPos).getBlockPos()).getBlock(), this, blockPos);
Block block = chunk.getSections()[y >> CHUNK_SECTION_SHIFT].getBlockState(x & CHUNK_SIZE_MASK, y & CHUNK_SECTION_MASK, z & CHUNK_SIZE_MASK).getBlock();
return BlockShapeWrapper.getBlockShapeWrapper(block, this, x, y, z);
}
public ChunkWrapper(ChunkAccess chunk)
{
this.chunk = chunk;
this.chunkPos = new ChunkPosWrapper(chunk.getPos());
}
public ChunkAccess getChunk(){
public ChunkAccess getChunk() {
return chunk;
}
@Override
public AbstractChunkPosWrapper getPos()
{
return chunkPos;
public int getChunkPosX(){
return chunk.getPos().x;
}
@Override
public int getChunkPosZ(){
return chunk.getPos().z;
}
@Override
public int getRegionPosX(){
return chunk.getPos().getRegionX();
}
@Override
public int getRegionPosZ(){
return chunk.getPos().getRegionZ();
}
@Override
public int getMaxY(int x, int z) {
return chunk.getHeight(Heightmap.Types.MOTION_BLOCKING, x, z);
}
@Override
public int getMaxX(){
return chunk.getPos().getMaxBlockX();
}
@Override
public int getMaxZ(){
return chunk.getPos().getMaxBlockZ();
}
@Override
public int getMinX(){
return chunk.getPos().getMinBlockX();
}
@Override
public int getMinZ() {
return chunk.getPos().getMinBlockZ();
}
@Override
@@ -93,38 +138,20 @@ public class ChunkWrapper implements IChunkWrapper
return chunk.isLightCorrect();
}
public boolean
isWaterLogged(BlockPosWrapper blockPos)
public boolean isWaterLogged(int x, int y, int z)
{
BlockState blockState = chunk.getBlockState(blockPos.getBlockPos());
BlockState blockState = chunk.getSections()[y >> CHUNK_SECTION_SHIFT].getBlockState(x & CHUNK_SIZE_MASK, y & CHUNK_SECTION_MASK, z & CHUNK_SIZE_MASK);
// //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());
return (!(blockState.getBlock() instanceof LiquidBlockContainer) && (blockState.getBlock() instanceof SimpleWaterloggedBlock))
&& (blockState.hasProperty(BlockStateProperties.WATERLOGGED) && blockState.getValue(BlockStateProperties.WATERLOGGED));
}
@Override
public boolean isWaterLogged(AbstractBlockPosWrapper blockPos)
public int getEmittedBrightness(int x, int y, int z)
{
// TODO Auto-generated method stub
return false;
}
BlockPos blockPos = new BlockPos(x,y,z);
@Override
public int getEmittedBrightness(AbstractBlockPosWrapper blockPos)
{
// TODO Auto-generated method stub
return 0;
return chunk.getLightEmission(blockPos);
}
}
@@ -109,6 +109,7 @@ public abstract class ConfigGui {
This is a small to do list for the config
Make config save
Make wiki better
Add a way to add min and max from another variable
*/
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
@@ -146,7 +147,7 @@ public abstract class ConfigGui {
if (field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.class) || field.isAnnotationPresent(ScreenEntry.class))
// TODO[CONFIG]: Fix the check for client/server
// if (Minecraft.getInstance().getEnvironmentType() == EnvType.CLIENT)
initClient(modid, field, info);
initClient(modid, field, info);
if (field.isAnnotationPresent(Entry.class))
try {
info.defaultValue = field.get(null);
@@ -393,18 +394,19 @@ public abstract class ConfigGui {
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
this.list.render(matrices, mouseX, mouseY, delta);
// drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF);
// Render title
drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF);
/*
// TODO[CONFIG]: Fix the tooltip
/*
for (EntryInfo info : entries) {
if (info.id.equals(modid) && info.category.matches(category)) {
if (info.id.equals(modid)) {
if (list.getHoveredButton(mouseX,mouseY).isPresent()) {
AbstractWidget buttonWidget = list.getHoveredButton(mouseX,mouseY).get();
Component text = ButtonEntry.buttonsWithText.get(buttonWidget);
TranslatableComponent name = new TranslatableComponent(this.translationPrefix + info.field.getName());
// When you fixed the config then add a @ before the tooltip in this line
String key = translationPrefix + info.field.getName() + (info.category != "" ? info.category + "." : "") + ".tooltip";
TranslatableComponent name = new TranslatableComponent(this.translationPrefix + (info.category != "" ? info.category + "." : "") + info.field.getName());
String key = translationPrefix + (info.category != "" ? info.category + "." : "") + info.field.getName() + ".@tooltip";
if (info.error != null && text.equals(name)) renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
else if (I18n.exists(key) && text.equals(name)) {
@@ -526,4 +528,4 @@ public abstract class ConfigGui {
return fieldAttributes.getAnnotation(Entry.class) == null;
}
}
}
}
@@ -1,59 +0,0 @@
/*
* 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.common.wrappers.world;
import com.seibel.lod.core.wrapperInterfaces.block.AbstractBlockPosWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeColorWrapperSingleton;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
import net.minecraft.client.renderer.BiomeColors;
/**
* @author Cola?
* @version 11-15-2021
*/
public class BiomeColorWrapperSingleton implements IBiomeColorWrapperSingleton
{
private static final BiomeColorWrapperSingleton instance = new BiomeColorWrapperSingleton();
@Override
public IBiomeColorWrapperSingleton getInstance()
{
return instance;
}
@Override
public int getGrassColor(IWorldWrapper world, AbstractBlockPosWrapper blockPos)
{
return BiomeColors.getAverageGrassColor(((WorldWrapper)world).getWorld(), ((BlockPosWrapper) blockPos).getBlockPos());
}
@Override
public int getWaterColor(IWorldWrapper world, AbstractBlockPosWrapper blockPos)
{
return BiomeColors.getAverageWaterColor(((WorldWrapper)world).getWorld(), ((BlockPosWrapper) blockPos).getBlockPos());
}
@Override
public int getFoliageColor(IWorldWrapper world, AbstractBlockPosWrapper blockPos)
{
return BiomeColors.getAverageFoliageColor(((WorldWrapper)world).getWorld(), ((BlockPosWrapper) blockPos).getBlockPos());
}
}
@@ -30,6 +30,7 @@ import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import com.seibel.lod.common.wrappers.block.BlockPosWrapper;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelAccessor;
@@ -96,21 +97,15 @@ public class WorldWrapper implements IWorldWrapper
}
@Override
public int getBlockLight(AbstractBlockPosWrapper blockPos)
public int getBlockLight(int x, int y, int z)
{
return world.getBrightness(LightLayer.BLOCK, ((BlockPosWrapper) blockPos).getBlockPos());
return world.getBrightness(LightLayer.BLOCK, new BlockPos(x,y,z));
}
@Override
public int getSkyLight(AbstractBlockPosWrapper blockPos)
public int getSkyLight(int x, int y, int z)
{
return world.getBrightness(LightLayer.SKY, ((BlockPosWrapper) blockPos).getBlockPos());
}
@Override
public IBiomeWrapper getBiome(AbstractBlockPosWrapper blockPos)
{
return BiomeWrapper.getBiomeWrapper(world.getBiome(((BlockPosWrapper) blockPos).getBlockPos()));
return world.getBrightness(LightLayer.SKY, new BlockPos(x,y,z));
}
public LevelAccessor getWorld()
+1 -1
Submodule core updated: 8292dc67c0...c1375f7a10