gold tree stuff

This commit is contained in:
Ellpeck 2018-10-15 18:36:46 +02:00
parent 17cc118c62
commit c5ed74bfd5
15 changed files with 339 additions and 45 deletions

View file

@ -7,73 +7,48 @@ buildscript {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
} }
} }
apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'maven'
version = "1.0" version = "1.0"
group = "de.ellpeck.naturesaura" // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = "de.ellpeck.naturesaura"
archivesBaseName = "naturesaura" archivesBaseName = "naturesaura"
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. sourceCompatibility = targetCompatibility = '1.8'
compileJava { compileJava {
sourceCompatibility = targetCompatibility = '1.8' sourceCompatibility = targetCompatibility = '1.8'
} }
repositories {
maven {
url "http://dvs1.progwml6.com/files/maven"
}
}
dependencies {
deobfCompile "mezz.jei:jei_1.12.2:4.13.1.220"
}
minecraft { minecraft {
version = "1.12.2-14.23.5.2768" version = "1.12.2-14.23.5.2768"
runDir = "run"
// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = "snapshot_20180720" mappings = "snapshot_20180720"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
runDir = "run"
makeObfSourceJar = false
replaceIn "NaturesAura.java" replaceIn "NaturesAura.java"
replace "@VERSION@", project.version.toString() replace "@VERSION@", project.version.toString()
} }
dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
//compile "some.group:artifact:version"
// real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
//provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
// except that these dependencies get remapped to your current MCP mappings
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// for more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
processResources { processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info' include 'mcmod.info'
// replace version and mcversion
expand 'version': project.version, 'mcversion': project.minecraft.version expand 'version': project.version, 'mcversion': project.minecraft.version
} }
// copy everything else except the mcmod.info
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info' exclude 'mcmod.info'
} }

View file

@ -3,6 +3,8 @@ package de.ellpeck.naturesaura;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -23,4 +25,12 @@ public final class Helper {
return tiles; return tiles;
} }
@SideOnly(Side.CLIENT)
public static int blendColors(int c1, int c2, float ratio) {
int a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio));
int r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio));
int g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio));
int b = (int) ((c1 & 0xFF) * ratio + (c2 & 0xFF) * (1 - ratio));
return ((a & 255) << 24) | ((r & 255) << 16) | ((g & 255) << 8) | (b & 255);
}
} }

View file

@ -0,0 +1,176 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class BlockGoldenLeaves extends BlockLeaves implements
IModItem, IModelProvider, IColorProvidingBlock, IColorProvidingItem {
private static final int HIGHEST_STAGE = 3;
private static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, HIGHEST_STAGE);
public BlockGoldenLeaves() {
this.leavesFancy = true;
ModRegistry.addItemOrBlock(this);
}
@Override
public String getBaseName() {
return "golden_leaves";
}
@Override
public boolean shouldAddCreative() {
return true;
}
@Override
public void onPreInit(FMLPreInitializationEvent event) {
}
@Override
public void onInit(FMLInitializationEvent event) {
}
@Override
public void onPostInit(FMLPostInitializationEvent event) {
}
@Override
public Map<ItemStack, ModelVariant> getModelLocations() {
return Collections.singletonMap(new ItemStack(this), new ModelVariant(new ResourceLocation(NaturesAura.MOD_ID, this.getBaseName()), "inventory"));
}
@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
NonNullList<ItemStack> drops = NonNullList.create();
this.getDrops(drops, world, pos, world.getBlockState(pos), fortune);
return drops;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, CHECK_DECAY, DECAYABLE, STAGE);
}
@Override
public IBlockState getStateFromMeta(int meta) {
boolean check = (meta & 4) != 0; // 4th bit
boolean decay = (meta & 8) != 0; // 3rd bit
int stage = meta & HIGHEST_STAGE; // 1st and 2nd bit
return this.getDefaultState().withProperty(CHECK_DECAY, check).withProperty(DECAYABLE, decay).withProperty(STAGE, stage);
}
@Override
public int getMetaFromState(IBlockState state) {
boolean check = state.getValue(CHECK_DECAY);
boolean decay = state.getValue(DECAYABLE);
return (check ? 1 : 0) << 3 | (decay ? 1 : 0) << 2 | state.getValue(STAGE);
}
@Override
public void beginLeavesDecay(IBlockState state, World world, BlockPos pos) {
if (!state.getValue(CHECK_DECAY) && state.getValue(DECAYABLE)) {
world.setBlockState(pos, state.withProperty(CHECK_DECAY, true), 4);
}
}
@Override
public BlockPlanks.EnumType getWoodType(int meta) {
return null;
}
@Override
@SideOnly(Side.CLIENT)
public IBlockColor getBlockColor() {
return (state, worldIn, pos, tintIndex) -> {
int color = 0xF2FF00;
if (state != null && worldIn != null && pos != null) {
int foliage = BiomeColorHelper.getFoliageColorAtPos(worldIn, pos);
return Helper.blendColors(color, foliage, state.getValue(STAGE) / (float) HIGHEST_STAGE);
} else {
return color;
}
};
}
@Override
@SideOnly(Side.CLIENT)
public IItemColor getItemColor() {
return (stack, tintIndex) -> 0xF2FF00;
}
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
Random rand = world instanceof World ? ((World) world).rand : RANDOM;
if (state.getValue(STAGE) < HIGHEST_STAGE) {
if (rand.nextFloat() >= 0.75F) {
drops.add(new ItemStack(ModItems.GOLD_FIBER));
}
} else if (rand.nextFloat() >= 0.25F) {
drops.add(new ItemStack(ModItems.GOLD_LEAF));
}
}
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
super.updateTick(worldIn, pos, state, rand);
if (!worldIn.isRemote) {
int stage = state.getValue(STAGE);
if (stage < HIGHEST_STAGE) {
worldIn.setBlockState(pos, state.withProperty(STAGE, stage + 1));
}
if (stage > 1) {
EnumFacing facing = EnumFacing.random(rand);
convert(worldIn, pos.offset(facing));
}
}
}
public static boolean convert(World world, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == Blocks.LEAVES || state.getBlock() == Blocks.LEAVES2) {
if (!world.isRemote) {
world.setBlockState(pos, ModBlocks.GOLDEN_LEAVES.getDefaultState()
.withProperty(CHECK_DECAY, state.getValue(CHECK_DECAY))
.withProperty(DECAYABLE, state.getValue(DECAYABLE)));
}
return true;
}
return false;
}
}

View file

@ -13,6 +13,8 @@ public class BlockNatureAltar extends BlockContainerImpl {
public BlockNatureAltar() { public BlockNatureAltar() {
super(Material.ROCK, "nature_altar", TileEntityNatureAltar.class, "nature_altar"); super(Material.ROCK, "nature_altar", TileEntityNatureAltar.class, "nature_altar");
this.setHardness(4F);
this.setHarvestLevel("pickaxe", 1);
} }
@Override @Override

View file

@ -12,4 +12,5 @@ public final class ModBlocks {
public static final Block ANCIENT_SAPLING = new BlockAncientSapling(); public static final Block ANCIENT_SAPLING = new BlockAncientSapling();
public static final Block NATURE_ALTAR = new BlockNatureAltar(); public static final Block NATURE_ALTAR = new BlockNatureAltar();
public static final Block DECAYED_LEAVES = new BlockDecayedLeaves(); public static final Block DECAYED_LEAVES = new BlockDecayedLeaves();
public static final Block GOLDEN_LEAVES = new BlockGoldenLeaves();
} }

View file

@ -0,0 +1,36 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.blocks.BlockGoldenLeaves;
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemGoldFiber extends ItemImpl implements IColorProvidingItem {
public ItemGoldFiber() {
super("gold_fiber");
}
@Override
public IItemColor getItemColor() {
return (stack, tintIndex) -> 0xF2FF00;
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (BlockGoldenLeaves.convert(worldIn, pos)) {
if (!worldIn.isRemote) {
stack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
}

View file

@ -5,4 +5,6 @@ import net.minecraft.item.Item;
public final class ModItems { public final class ModItems {
public static final Item EYE = new ItemEye(); public static final Item EYE = new ItemEye();
public static final Item GOLD_FIBER = new ItemGoldFiber();
public static final Item GOLD_LEAF = new ItemImpl("gold_leaf");
} }

View file

@ -0,0 +1,28 @@
{
"forge_marker": 1,
"defaults": {
"model": "minecraft:leaves",
"textures": {
"all": "minecraft:blocks/leaves_oak"
},
"transform": "forge:default-block"
},
"variants": {
"normal": [{}],
"inventory": [{}],
"decayable": {
"true": {},
"false": {}
},
"check_decay": {
"true": {},
"false": {}
},
"stage": {
"0": {},
"1": {},
"2": {},
"3": {}
}
}
}

View file

@ -6,5 +6,8 @@ tile.naturesaura.ancient_leaves.name=Ancient Leaves
tile.naturesaura.ancient_sapling.name=Ancient Sapling tile.naturesaura.ancient_sapling.name=Ancient Sapling
tile.naturesaura.nature_altar.name=Natural Altar tile.naturesaura.nature_altar.name=Natural Altar
tile.naturesaura.decayed_leaves.name=Decayed Leaves tile.naturesaura.decayed_leaves.name=Decayed Leaves
tile.naturesaura.golden_leaves.name=Golden Leaves
item.naturesaura.eye.name=Environmental Eye item.naturesaura.eye.name=Environmental Eye
item.naturesaura.gold_fiber.name=Brilliant Fiber
item.naturesaura.gold_leaf.name=Gold Leaf

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:items/gold_fiber"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:items/gold_leaf"
}
}

View file

@ -0,0 +1,23 @@
{
"type": "forge:ore_shaped",
"pattern": [
"WLW",
"LEL",
"WLW"
],
"key": {
"E": {
"item": "minecraft:spider_eye"
},
"L": {
"item": "naturesaura:gold_leaf"
},
"W": {
"type": "forge:ore_dict",
"ore": "logWood"
}
},
"result": {
"item": "naturesaura:eye"
}
}

View file

@ -0,0 +1,26 @@
{
"type": "forge:ore_shaped",
"pattern": [
"LNL",
"NGN",
"LNL"
],
"key": {
"N": {
"type": "forge:ore_dict",
"ore": "nuggetGold"
},
"G": {
"item": "minecraft:tallgrass",
"data": 1
},
"L": {
"type": "forge:ore_dict",
"ore": "treeLeaves"
}
},
"result": {
"item": "naturesaura:gold_fiber",
"count": 4
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B