Fixed block colouring in the world
This commit is contained in:
parent
367fa2cefa
commit
60f2ee807b
8 changed files with 149 additions and 55 deletions
|
@ -44,7 +44,7 @@ public class BlockBOPDecoration extends Block implements IBOPBlock
|
|||
@Override
|
||||
public String getStateName(IBlockState state) {return "";}
|
||||
@Override
|
||||
public IBlockColor getColourHandler() { return ModBlocks.FOLIAGE_COLOURING; }
|
||||
public IBlockColor getColourHandler() { return null; }
|
||||
|
||||
// constructor
|
||||
public BlockBOPDecoration() {
|
||||
|
|
|
@ -20,6 +20,7 @@ import net.minecraft.block.properties.IProperty;
|
|||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.color.IBlockColor;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
@ -71,8 +72,41 @@ public class BlockBOPDoublePlant extends BlockBOPDoubleDecoration implements ISh
|
|||
{
|
||||
return ((DoublePlantType) state.getValue(VARIANT)).getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public enum ColoringType {PLAIN, LIKE_LEAVES, LIKE_GRASS};
|
||||
|
||||
public static ColoringType getColoringType(DoublePlantType plant)
|
||||
{
|
||||
switch (plant)
|
||||
{
|
||||
case FLAX:
|
||||
return ColoringType.LIKE_GRASS;
|
||||
default:
|
||||
return ColoringType.PLAIN;
|
||||
}
|
||||
}
|
||||
|
||||
public IBlockColor getColourHandler()
|
||||
{
|
||||
return new IBlockColor()
|
||||
{
|
||||
@Override
|
||||
public int colorMultiplier(IBlockState state, IBlockAccess world, BlockPos pos, int tintIndex)
|
||||
{
|
||||
if ( world != null && pos != null)
|
||||
{
|
||||
switch (getColoringType((DoublePlantType) state.getValue(VARIANT)))
|
||||
{
|
||||
case LIKE_GRASS:
|
||||
return BiomeColorHelper.getGrassColorAtPos(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
return ColorizerFoliage.getFoliageColorBasic();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public BlockBOPDoublePlant()
|
||||
{
|
||||
super();
|
||||
|
@ -93,18 +127,7 @@ public class BlockBOPDoublePlant extends BlockBOPDoubleDecoration implements ISh
|
|||
|
||||
|
||||
|
||||
public enum ColoringType {PLAIN, LIKE_LEAVES, LIKE_GRASS};
|
||||
|
||||
public static ColoringType getColoringType(DoublePlantType plant)
|
||||
{
|
||||
switch (plant)
|
||||
{
|
||||
case FLAX:
|
||||
return ColoringType.LIKE_GRASS;
|
||||
default:
|
||||
return ColoringType.PLAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* // different variants have different sizes
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Random;
|
|||
import biomesoplenty.api.block.BOPBlocks;
|
||||
import biomesoplenty.api.block.IBOPBlock;
|
||||
import biomesoplenty.api.block.ISustainsPlantType;
|
||||
import biomesoplenty.common.init.ModBlocks;
|
||||
import biomesoplenty.common.item.ItemBOPBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
|
@ -86,7 +87,7 @@ public class BlockBOPGrass extends BlockGrass implements IBOPBlock, ISustainsPla
|
|||
}
|
||||
}
|
||||
@Override
|
||||
public IBlockColor getColourHandler() { return null; }
|
||||
public IBlockColor getColourHandler() { return ModBlocks.GRASS_COLORING; }
|
||||
|
||||
public BlockBOPGrass()
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Random;
|
|||
|
||||
import biomesoplenty.api.block.IBOPBlock;
|
||||
import biomesoplenty.api.item.BOPItems;
|
||||
import biomesoplenty.common.enums.BOPPlants;
|
||||
import biomesoplenty.common.enums.BOPTrees;
|
||||
import biomesoplenty.common.item.ItemBOPBlock;
|
||||
import biomesoplenty.common.util.block.VariantPagingHelper;
|
||||
|
@ -99,8 +100,48 @@ public class BlockBOPLeaves extends BlockLeaves implements IBOPBlock
|
|||
return tree.getName() + "_leaves";
|
||||
}
|
||||
}
|
||||
|
||||
public enum ColoringType {PLAIN, TINTED, OVERLAY};
|
||||
|
||||
public static ColoringType getColoringType(BOPTrees tree)
|
||||
{
|
||||
switch (tree)
|
||||
{
|
||||
case BAMBOO: case UMBRAN: case DEAD: case ETHEREAL: case FIR: case HELLBARK: case JACARANDA: case MAGIC: case MAPLE: case ORANGE_AUTUMN: case ORIGIN: case PINK_CHERRY: case WHITE_CHERRY: case YELLOW_AUTUMN: case RED_BIG_FLOWER: case YELLOW_BIG_FLOWER:
|
||||
return ColoringType.PLAIN;
|
||||
case FLOWERING:
|
||||
return ColoringType.OVERLAY;
|
||||
case MAHOGANY: case MANGROVE: case PALM: case PINE: case REDWOOD: case SACRED_OAK: case WILLOW: case EBONY: case EUCALYPTUS: default:
|
||||
return ColoringType.TINTED;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockColor getColourHandler() { return null; }
|
||||
public IBlockColor getColourHandler()
|
||||
{
|
||||
final IProperty variantProp = this.variantProperty;
|
||||
|
||||
return new IBlockColor()
|
||||
{
|
||||
@Override
|
||||
public int colorMultiplier(IBlockState state, IBlockAccess world, BlockPos pos, int tintIndex)
|
||||
{
|
||||
if ( world != null && pos != null)
|
||||
{
|
||||
switch (getColoringType((BOPTrees) state.getValue(variantProp)))
|
||||
{
|
||||
case TINTED:
|
||||
return BiomeColorHelper.getFoliageColorAtPos(world, pos);
|
||||
case OVERLAY:
|
||||
if (tintIndex == 0)
|
||||
return BiomeColorHelper.getFoliageColorAtPos(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private BlockBOPLeaves()
|
||||
{
|
||||
|
@ -134,22 +175,6 @@ public class BlockBOPLeaves extends BlockLeaves implements IBOPBlock
|
|||
return meta;
|
||||
}
|
||||
|
||||
|
||||
public enum ColoringType {PLAIN, TINTED, OVERLAY};
|
||||
|
||||
public static ColoringType getColoringType(BOPTrees tree)
|
||||
{
|
||||
switch (tree)
|
||||
{
|
||||
case BAMBOO: case UMBRAN: case DEAD: case ETHEREAL: case FIR: case HELLBARK: case JACARANDA: case MAGIC: case MAPLE: case ORANGE_AUTUMN: case ORIGIN: case PINK_CHERRY: case WHITE_CHERRY: case YELLOW_AUTUMN: case RED_BIG_FLOWER: case YELLOW_BIG_FLOWER:
|
||||
return ColoringType.PLAIN;
|
||||
case FLOWERING:
|
||||
return ColoringType.OVERLAY;
|
||||
case MAHOGANY: case MANGROVE: case PALM: case PINE: case REDWOOD: case SACRED_OAK: case WILLOW: case EBONY: case EUCALYPTUS: default:
|
||||
return ColoringType.TINTED;
|
||||
}
|
||||
}
|
||||
|
||||
// blocks that are not placed during generation should not decay
|
||||
@Override
|
||||
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
||||
|
@ -359,7 +384,7 @@ public class BlockBOPLeaves extends BlockLeaves implements IBOPBlock
|
|||
}
|
||||
|
||||
|
||||
//The fields used by getBlockLayer() and isOpaqueCube() are set externally for Blocks.leaves *specifically*. As a result, we do not inherit
|
||||
//The fields used by getBlockLayer(), isOpaqueCube() and shouldSideBeRendered are set externally for Blocks.leaves *specifically*. As a result, we do not inherit
|
||||
//it simply be extending BlockLeaves.
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -373,8 +398,14 @@ public class BlockBOPLeaves extends BlockLeaves implements IBOPBlock
|
|||
{
|
||||
return Blocks.leaves.isOpaqueCube(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side)
|
||||
{
|
||||
return Blocks.leaves.shouldSideBeRendered(state, world, pos, side);
|
||||
}
|
||||
|
||||
// We are forced to implement the method below in order to extend the BlockLeaves abstract class
|
||||
// ...however, we don't actually use it anywhere so it's safe to just return null
|
||||
// it makes no sense in our context
|
||||
|
|
|
@ -20,6 +20,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.color.IBlockColor;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -107,6 +108,48 @@ public class BlockBOPPlant extends BlockBOPDecoration implements IShearable
|
|||
return plant.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ColoringType {PLAIN, LIKE_LEAVES, LIKE_GRASS};
|
||||
|
||||
public static ColoringType getColoringType(BOPPlants plant)
|
||||
{
|
||||
switch (plant)
|
||||
{
|
||||
case SHRUB: case LEAFPILE: case POISONIVY: case BUSH: case BERRYBUSH:
|
||||
return ColoringType.LIKE_LEAVES;
|
||||
case SHORTGRASS: case MEDIUMGRASS: case SPROUT: case KORU: case CLOVERPATCH: case WHEATGRASS: case DAMPGRASS:
|
||||
return ColoringType.LIKE_GRASS;
|
||||
default:
|
||||
return ColoringType.PLAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockColor getColourHandler()
|
||||
{
|
||||
final IProperty variantProp = this.variantProperty;
|
||||
|
||||
return new IBlockColor()
|
||||
{
|
||||
@Override
|
||||
public int colorMultiplier(IBlockState state, IBlockAccess world, BlockPos pos, int tintIndex)
|
||||
{
|
||||
if ( world != null && pos != null)
|
||||
{
|
||||
switch (getColoringType((BOPPlants) state.getValue(variantProp)))
|
||||
{
|
||||
case LIKE_LEAVES:
|
||||
return BiomeColorHelper.getFoliageColorAtPos(world, pos);
|
||||
|
||||
case LIKE_GRASS:
|
||||
return BiomeColorHelper.getGrassColorAtPos(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
return ColorizerFoliage.getFoliageColorBasic();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private BlockBOPPlant()
|
||||
{
|
||||
|
@ -262,23 +305,6 @@ public class BlockBOPPlant extends BlockBOPDecoration implements IShearable
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public enum ColoringType {PLAIN, LIKE_LEAVES, LIKE_GRASS};
|
||||
|
||||
public static ColoringType getColoringType(BOPPlants plant)
|
||||
{
|
||||
switch (plant)
|
||||
{
|
||||
case SHRUB: case LEAFPILE: case POISONIVY: case BUSH: case BERRYBUSH:
|
||||
return ColoringType.LIKE_LEAVES;
|
||||
case SHORTGRASS: case MEDIUMGRASS: case SPROUT: case KORU: case CLOVERPATCH: case WHEATGRASS: case DAMPGRASS:
|
||||
return ColoringType.LIKE_GRASS;
|
||||
default:
|
||||
return ColoringType.PLAIN;
|
||||
}
|
||||
}
|
||||
|
||||
// different variants have different sizes
|
||||
/* @Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package biomesoplenty.common.block;
|
||||
|
||||
import biomesoplenty.api.block.IBOPBlock;
|
||||
import biomesoplenty.common.init.ModBlocks;
|
||||
import biomesoplenty.common.item.ItemBOPBlock;
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.block.SoundType;
|
||||
|
@ -19,7 +20,9 @@ import net.minecraft.init.Blocks;
|
|||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ColorizerGrass;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.biome.BiomeColorHelper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -36,7 +39,7 @@ public class BlockBOPVine extends BlockVine implements IBOPBlock
|
|||
@Override
|
||||
public String getStateName(IBlockState state) {return "";}
|
||||
@Override
|
||||
public IBlockColor getColourHandler() { return null; }
|
||||
public IBlockColor getColourHandler() { return useGreyScaleTextures ? ModBlocks.FOLIAGE_COLOURING : null; }
|
||||
|
||||
// if set to true, (the default), use BlockVine getBlockColor(), getRenderColor() and colorMultiplier() functions to color the texture based on biome
|
||||
// if set to false, use 0xFFFFFF for all the color functions so that the texture is used as it is
|
||||
|
|
|
@ -87,6 +87,7 @@ import net.minecraft.item.ItemDoor;
|
|||
import net.minecraft.item.ItemSlab;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ColorizerFoliage;
|
||||
import net.minecraft.world.ColorizerGrass;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.biome.BiomeColorHelper;
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
@ -106,6 +107,15 @@ public class ModBlocks
|
|||
}
|
||||
};
|
||||
|
||||
public static final IBlockColor GRASS_COLORING = new IBlockColor()
|
||||
{
|
||||
@Override
|
||||
public int colorMultiplier(IBlockState state, IBlockAccess world, BlockPos pos, int tintIndex)
|
||||
{
|
||||
return world != null && pos != null ? BiomeColorHelper.getGrassColorAtPos(world, pos) : ColorizerGrass.getGrassColor(0.5D, 1.0D);
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: use getDrops() in classes where the drops are very specific, instead of implementing all 3 of quantityDropped() getItemDropped() and damageDropped()
|
||||
// TODO: docblocks!
|
||||
// TODO: make better use of canSustainPlant() in BlockDecoration and children
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"parent": "block/tallgrass",
|
||||
"parent": "block/tinted_cross",
|
||||
"textures": {
|
||||
"cross": "biomesoplenty:blocks/flax_lower"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue