From c5ed74bfd5a81b954ff44941c532852f5533cb2d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 15 Oct 2018 18:36:46 +0200 Subject: [PATCH] gold tree stuff --- build.gradle | 63 ++----- .../java/de/ellpeck/naturesaura/Helper.java | 10 + .../naturesaura/blocks/BlockGoldenLeaves.java | 176 ++++++++++++++++++ .../naturesaura/blocks/BlockNatureAltar.java | 2 + .../ellpeck/naturesaura/blocks/ModBlocks.java | 1 + .../naturesaura/items/ItemGoldFiber.java | 36 ++++ .../ellpeck/naturesaura/items/ModItems.java | 2 + .../blockstates/golden_leaves.json | 28 +++ .../assets/naturesaura/lang/en_US.lang | 5 +- .../naturesaura/models/item/gold_fiber.json | 6 + .../naturesaura/models/item/gold_leaf.json | 6 + .../assets/naturesaura/recipes/eye.json | 23 +++ .../naturesaura/recipes/gold_fiber.json | 26 +++ .../naturesaura/textures/items/gold_fiber.png | Bin 0 -> 399 bytes .../naturesaura/textures/items/gold_leaf.png | Bin 0 -> 688 bytes 15 files changed, 339 insertions(+), 45 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/BlockGoldenLeaves.java create mode 100644 src/main/java/de/ellpeck/naturesaura/items/ItemGoldFiber.java create mode 100644 src/main/resources/assets/naturesaura/blockstates/golden_leaves.json create mode 100644 src/main/resources/assets/naturesaura/models/item/gold_fiber.json create mode 100644 src/main/resources/assets/naturesaura/models/item/gold_leaf.json create mode 100644 src/main/resources/assets/naturesaura/recipes/eye.json create mode 100644 src/main/resources/assets/naturesaura/recipes/gold_fiber.json create mode 100644 src/main/resources/assets/naturesaura/textures/items/gold_fiber.png create mode 100644 src/main/resources/assets/naturesaura/textures/items/gold_leaf.png diff --git a/build.gradle b/build.gradle index ac995256..73522a96 100644 --- a/build.gradle +++ b/build.gradle @@ -7,73 +7,48 @@ buildscript { 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" -group = "de.ellpeck.naturesaura" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +group = "de.ellpeck.naturesaura" archivesBaseName = "naturesaura" -sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. +sourceCompatibility = targetCompatibility = '1.8' compileJava { 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 { 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" - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. + + runDir = "run" + makeObfSourceJar = false replaceIn "NaturesAura.java" 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 { - // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version - - // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { 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) { exclude 'mcmod.info' } diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 12502cb5..e54abab5 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -3,6 +3,8 @@ package de.ellpeck.naturesaura; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import java.util.ArrayList; import java.util.List; @@ -23,4 +25,12 @@ public final class Helper { 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); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockGoldenLeaves.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockGoldenLeaves.java new file mode 100644 index 00000000..38cea2a9 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockGoldenLeaves.java @@ -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 getModelLocations() { + return Collections.singletonMap(new ItemStack(this), new ModelVariant(new ResourceLocation(NaturesAura.MOD_ID, this.getBaseName()), "inventory")); + } + + @Override + public List onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { + NonNullList 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 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; + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java index 132a72a2..afc0f924 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java @@ -13,6 +13,8 @@ public class BlockNatureAltar extends BlockContainerImpl { public BlockNatureAltar() { super(Material.ROCK, "nature_altar", TileEntityNatureAltar.class, "nature_altar"); + this.setHardness(4F); + this.setHarvestLevel("pickaxe", 1); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index bf6a5379..636ea6da 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -12,4 +12,5 @@ public final class ModBlocks { public static final Block ANCIENT_SAPLING = new BlockAncientSapling(); public static final Block NATURE_ALTAR = new BlockNatureAltar(); public static final Block DECAYED_LEAVES = new BlockDecayedLeaves(); + public static final Block GOLDEN_LEAVES = new BlockGoldenLeaves(); } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemGoldFiber.java b/src/main/java/de/ellpeck/naturesaura/items/ItemGoldFiber.java new file mode 100644 index 00000000..895ca3dc --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemGoldFiber.java @@ -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; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java index dc1104ea..9f106d65 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ModItems.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ModItems.java @@ -5,4 +5,6 @@ import net.minecraft.item.Item; public final class ModItems { 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"); } diff --git a/src/main/resources/assets/naturesaura/blockstates/golden_leaves.json b/src/main/resources/assets/naturesaura/blockstates/golden_leaves.json new file mode 100644 index 00000000..c397519f --- /dev/null +++ b/src/main/resources/assets/naturesaura/blockstates/golden_leaves.json @@ -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": {} + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index 3b2aaf56..f5674071 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -6,5 +6,8 @@ tile.naturesaura.ancient_leaves.name=Ancient Leaves tile.naturesaura.ancient_sapling.name=Ancient Sapling tile.naturesaura.nature_altar.name=Natural Altar tile.naturesaura.decayed_leaves.name=Decayed Leaves +tile.naturesaura.golden_leaves.name=Golden Leaves -item.naturesaura.eye.name=Environmental Eye \ No newline at end of file +item.naturesaura.eye.name=Environmental Eye +item.naturesaura.gold_fiber.name=Brilliant Fiber +item.naturesaura.gold_leaf.name=Gold Leaf \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/models/item/gold_fiber.json b/src/main/resources/assets/naturesaura/models/item/gold_fiber.json new file mode 100644 index 00000000..cc791837 --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/gold_fiber.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "naturesaura:items/gold_fiber" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/models/item/gold_leaf.json b/src/main/resources/assets/naturesaura/models/item/gold_leaf.json new file mode 100644 index 00000000..382d6efb --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/item/gold_leaf.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "naturesaura:items/gold_leaf" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/recipes/eye.json b/src/main/resources/assets/naturesaura/recipes/eye.json new file mode 100644 index 00000000..e77f2b4e --- /dev/null +++ b/src/main/resources/assets/naturesaura/recipes/eye.json @@ -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" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/recipes/gold_fiber.json b/src/main/resources/assets/naturesaura/recipes/gold_fiber.json new file mode 100644 index 00000000..22ecd03d --- /dev/null +++ b/src/main/resources/assets/naturesaura/recipes/gold_fiber.json @@ -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 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/items/gold_fiber.png b/src/main/resources/assets/naturesaura/textures/items/gold_fiber.png new file mode 100644 index 0000000000000000000000000000000000000000..d46e09d708effca4ac005874cdbefa26c81d55c5 GIT binary patch literal 399 zcmV;A0dW3_P)N2bZe?^J zG%hhNF=Hy6O8@`?4M{{nR5(wakxOocFbqYrYUT_8ArSwcK){4Ou)I{qJm;l6Dz%Md z*}gc(b}&z8nkM@S|98&wd;~O2^E24LC=o{)z&K@d~@Ig6TA6S-t`Oj=sNx z$+eah(d8hl>-sAItEuJ=0yfXH_%uz$E8sW|mt*b^a8$(heV0NWj(i+Pd5b%McZj0s tf~bg5#0zWAWsQ9R7KY&`;IC$kF<%q=y}gLv30D9B002ovPDHLkV1i%Lq>=yt literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/naturesaura/textures/items/gold_leaf.png b/src/main/resources/assets/naturesaura/textures/items/gold_leaf.png new file mode 100644 index 0000000000000000000000000000000000000000..5b598dbacca9466b8a262489e75537795a1ac466 GIT binary patch literal 688 zcmV;h0#E&kP)N2bZe?^J zG%hhNF=Hy6O8@`@E=fc|R5(wSlG|<)Q51$3JcH3d%ama{6zItq6R&(WuY7<83f2Zg zD$EILX=ON6+oVm5iH$wRD{Wc|hyCm5Gv(36jkMAt|R7DlJICFBX77=0Nt7(Z2<`tV&N8 zHEQop$a(@8sj=SYx0Cp^KZ#l)ij|d!sPBqEJct_EARRooFQ(}66xecgd~e>y`$LA! z2u^nss5u&{jz+Gn_&ofNpp})AV0(1}CkIp5T-MNjmq5Lw;rPuAI=fLY$V)+$;!Tg{ z3f!FIgT8C3u z%WJ%A3>&2pY^-Qt2vu8=Yb%b@hs}BQLcsU9mK2`=-obJWp7Dw>y!!)*P