From 891d2cce323d44af2bd76ab625429bf63ba19662 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 20 Feb 2016 10:58:58 +0000 Subject: [PATCH] Added rubber processing --- .../techreborn/blocks/BlockRubberLeaves.java | 19 ++- .../techreborn/blocks/BlockRubberLog.java | 108 +++++++++++++++++- src/main/java/techreborn/init/ModRecipes.java | 1 + .../java/techreborn/world/TreeGenerator.java | 6 +- .../assets/techreborn/lang/en_US.lang | 6 + 5 files changed, 133 insertions(+), 7 deletions(-) diff --git a/src/main/java/techreborn/blocks/BlockRubberLeaves.java b/src/main/java/techreborn/blocks/BlockRubberLeaves.java index a5334c8b2..86652fc82 100644 --- a/src/main/java/techreborn/blocks/BlockRubberLeaves.java +++ b/src/main/java/techreborn/blocks/BlockRubberLeaves.java @@ -1,6 +1,5 @@ package techreborn.blocks; -import biomesoplenty.common.enums.BOPTrees; import me.modmuss50.jsonDestroyer.api.ITexturedBlock; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockPlanks; @@ -101,4 +100,22 @@ public class BlockRubberLeaves extends BlockLeaves implements ITexturedBlock { } return meta; } + + @SideOnly(Side.CLIENT) + public int getBlockColor() + { + return 16777215; + } + + @SideOnly(Side.CLIENT) + public int getRenderColor(IBlockState state) + { + return 16777215; + } + + @SideOnly(Side.CLIENT) + public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) + { + return 16777215; + } } diff --git a/src/main/java/techreborn/blocks/BlockRubberLog.java b/src/main/java/techreborn/blocks/BlockRubberLog.java index f83cebc18..e732e6098 100644 --- a/src/main/java/techreborn/blocks/BlockRubberLog.java +++ b/src/main/java/techreborn/blocks/BlockRubberLog.java @@ -3,17 +3,34 @@ package techreborn.blocks; import me.modmuss50.jsonDestroyer.api.ITexturedBlock; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyBool; +import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import reborncore.RebornCore; import techreborn.client.TechRebornCreativeTabMisc; +import techreborn.init.ModParts; +import techreborn.items.ItemParts; + +import java.util.List; +import java.util.Random; /** * Created by mark on 19/02/2016. */ public class BlockRubberLog extends Block implements ITexturedBlock { + + public static PropertyDirection SAP_SIDE = PropertyDirection.create("sapSide", EnumFacing.Plane.HORIZONTAL); + public static PropertyBool HAS_SAP = PropertyBool.create("hasSap"); + public BlockRubberLog() { super(Material.wood); setUnlocalizedName("techreborn.rubberlog"); @@ -21,6 +38,47 @@ public class BlockRubberLog extends Block implements ITexturedBlock { this.setHardness(2.0F); this.setStepSound(soundTypeWood); RebornCore.jsonDestroyer.registerObject(this); + this.setDefaultState(this.blockState.getBaseState().withProperty(SAP_SIDE, EnumFacing.NORTH).withProperty(HAS_SAP, false)); + this.setTickRandomly(true); + } + + protected BlockState createBlockState() { + return new BlockState(this, SAP_SIDE, HAS_SAP); + } + + @Override + public IBlockState getStateFromMeta(int meta) { + boolean hasSap = false; + int tempMeta = meta; + if(meta > 3){ + hasSap = true; + tempMeta -= 3; + } + EnumFacing facing = EnumFacing.getHorizontal(tempMeta); + return this.getDefaultState().withProperty(SAP_SIDE, facing).withProperty(HAS_SAP, hasSap); + } + + @Override + public int getMetaFromState(IBlockState state) { + int tempMeta = 0; + EnumFacing facing = state.getValue(SAP_SIDE); + switch (facing){ + case SOUTH: + tempMeta = 0; + break; + case WEST: + tempMeta = 1; + break; + case NORTH: + tempMeta = 2; + break; + case EAST: + tempMeta = 3; + } + if(state.getValue(HAS_SAP)){ + tempMeta += 3; + } + return tempMeta; } @Override @@ -28,12 +86,17 @@ public class BlockRubberLog extends Block implements ITexturedBlock { if(enumFacing == EnumFacing.DOWN || enumFacing == EnumFacing.UP){ return "techreborn:blocks/rubber_log_side"; } + if(iBlockState.getValue(HAS_SAP)){ + if(iBlockState.getValue(SAP_SIDE) == enumFacing){ + return "techreborn:blocks/rubber_log_sap"; + } + } return "techreborn:blocks/rubber_log"; } @Override public int amountOfStates() { - return 1; + return 8; } @Override @@ -49,15 +112,54 @@ public class BlockRubberLog extends Block implements ITexturedBlock { public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { int i = 4; int j = i + 1; - if (worldIn.isAreaLoaded(pos.add(-j, -j, -j), pos.add(j, j, j))) { for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-i, -i, -i), pos.add(i, i, i))) { IBlockState iblockstate = worldIn.getBlockState(blockpos); - if (iblockstate.getBlock().isLeaves(worldIn, blockpos)) { iblockstate.getBlock().beginLeavesDecay(worldIn, blockpos); } } } } + + @Override + public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { + super.updateTick(worldIn, pos, state, rand); + if(!state.getValue(HAS_SAP)){ + if(rand.nextInt(100) == 0){ + EnumFacing facing = EnumFacing.getHorizontal(rand.nextInt(3)); + if(worldIn.getBlockState(pos.down()).getBlock() == this && worldIn.getBlockState(pos.up()).getBlock() == this && worldIn.isAirBlock(pos.offset(facing))){ + worldIn.setBlockState(pos, state.withProperty(HAS_SAP, true).withProperty(SAP_SIDE, facing)); + } + } + } + } + + @Override + public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { + super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ); + if(state.getValue(HAS_SAP)){ + if(state.getValue(SAP_SIDE) == side){ + worldIn.setBlockState(pos, state.withProperty(HAS_SAP, false).withProperty(SAP_SIDE, EnumFacing.getHorizontal(0))); + if(!worldIn.isRemote){ + Random rand = new Random(); + BlockPos itemPos = pos.offset(side); + EntityItem item = new EntityItem(worldIn, itemPos.getX(), itemPos.getY(), itemPos.getZ(), ItemParts.getPartByName("rubberSap").copy()); + float factor = 0.05F; + item.motionX = rand.nextGaussian() * factor; + item.motionY = rand.nextGaussian() * factor + 0.2F; + item.motionZ = rand.nextGaussian() * factor; + worldIn.spawnEntityInWorld(item); + } + return true; + } + } + return false; + } + + @Override + public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { + super.getSubBlocks(itemIn, tab, list); + list.add(new ItemStack(itemIn, 1, 5)); + } } diff --git a/src/main/java/techreborn/init/ModRecipes.java b/src/main/java/techreborn/init/ModRecipes.java index d6fa5e001..6e643fda0 100644 --- a/src/main/java/techreborn/init/ModRecipes.java +++ b/src/main/java/techreborn/init/ModRecipes.java @@ -349,6 +349,7 @@ public class static void addSmeltingRecipes() { GameRegistry.addSmelting(ItemDusts.getDustByName("iron", 1), new ItemStack(Items.iron_ingot), 1F); GameRegistry.addSmelting(ItemDusts.getDustByName("gold", 1), new ItemStack(Items.gold_ingot), 1F); + GameRegistry.addSmelting(ItemParts.getPartByName("rubberSap"), ItemParts.getPartByName("rubber"), 1F); Core.logHelper.info("Smelting Recipes Added"); } diff --git a/src/main/java/techreborn/world/TreeGenerator.java b/src/main/java/techreborn/world/TreeGenerator.java index c167552cf..28562a0ad 100644 --- a/src/main/java/techreborn/world/TreeGenerator.java +++ b/src/main/java/techreborn/world/TreeGenerator.java @@ -21,16 +21,16 @@ public class TreeGenerator implements IWorldGenerator { @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { - int chance = 0; + int chance = 1; BiomeGenBase biomeGenBase = world.getBiomeGenForCoords( new BlockPos(chunkX * 16 + 16, 72, chunkZ * 16 + 16)); if(BiomeDictionary.isBiomeOfType(biomeGenBase, BiomeDictionary.Type.SWAMP)){ - chance += random.nextInt(10) + 5; + chance += random.nextInt(15) + 5; } if(BiomeDictionary.isBiomeOfType(biomeGenBase, BiomeDictionary.Type.FOREST) || BiomeDictionary.isBiomeOfType(biomeGenBase, BiomeDictionary.Type.JUNGLE)){ chance += random.nextInt(5) + 1; } if(world.provider.isSurfaceWorld()){ - if(random.nextInt(100) + 1 <= chance * 2){ + if(random.nextInt(chance) == 0){ treeGenerator.generate(world, random, new BlockPos(chunkX * 16 + random.nextInt(16), 72, chunkZ * 16 + random.nextInt(16))); } diff --git a/src/main/resources/assets/techreborn/lang/en_US.lang b/src/main/resources/assets/techreborn/lang/en_US.lang index aa4f8797a..377ee8ee4 100644 --- a/src/main/resources/assets/techreborn/lang/en_US.lang +++ b/src/main/resources/assets/techreborn/lang/en_US.lang @@ -59,6 +59,10 @@ tile.techreborn.electricfurnace.name=Electric Furnace tile.techreborn.machineFrame.advancedMachine.name=Advanced Machine Block tile.techreborn.machineFrame.machine.name=Machine Block +#Blocks +tile.techreborn.rubberlog.name=Rubber log +tile.techreborn.rubberleaves.name=Rubber Leaves + #Ores tile.techreborn.ore.Galena.name=Galena Ore tile.techreborn.ore.Iridium.name=Iridium Ore @@ -564,6 +568,8 @@ item.techreborn.part.computerMonitor.name=Computer Monitor item.techreborn.part.machineParts.name=Machine Parts item.techreborn.part.neutronReflector.name=Neutron Reflector item.techreborn.part.thickNeutronReflector.name=Thick Neutron Reflector +item.techreborn.part.rubberSap.name=Sap +item.techreborn.part.rubber.name=Rubber #Tools item.techreborn.rockcutter.name=Rockcutter