Some luv to rubber stuff )
This commit is contained in:
parent
6f9baaeb30
commit
63fe6d2ef4
2 changed files with 29 additions and 120 deletions
|
@ -24,117 +24,31 @@
|
|||
|
||||
package techreborn.blocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.BlockLeaves;
|
||||
import net.minecraft.block.BlockPlanks;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IItemProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.client.models.ModelCompound;
|
||||
import reborncore.client.models.RebornModelRegistry;
|
||||
import techreborn.TechReborn;
|
||||
import techreborn.init.TRContent;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockRubberLeaves extends BlockLeaves {
|
||||
|
||||
public BlockRubberLeaves() {
|
||||
super();
|
||||
this.setDefaultState(this.getDefaultState().with(CHECK_DECAY, true)
|
||||
.with(DECAYABLE, true));
|
||||
Blocks.FIRE.setFireInfo(this, 30, 60);
|
||||
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, CHECK_DECAY, DECAYABLE));
|
||||
super(Block.Properties.create(Material.LEAVES).hardnessAndResistance(0.2F).needsRandomTick().sound(SoundType.PLANT));
|
||||
((BlockFire) Blocks.FIRE).setFireInfo(this, 30, 60);
|
||||
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, DISTANCE, PERSISTENT));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockPlanks.EnumType getWoodType(int meta) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
|
||||
List<ItemStack> list = new java.util.ArrayList<>();
|
||||
list.add(new ItemStack(this, 1, 0));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderLayer getRenderLayer() {
|
||||
if(!fancyLeaves()){
|
||||
return super.getRenderLayer();
|
||||
}
|
||||
return BlockRenderLayer.CUTOUT_MIPPED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) {
|
||||
if(!fancyLeaves()){
|
||||
return state.isOpaqueCube();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, new IProperty[] { CHECK_DECAY, DECAYABLE });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().with(DECAYABLE, (meta & 1) == 0)
|
||||
.with(CHECK_DECAY, (meta & 2) > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
int meta = 0;
|
||||
if (!state.getValue(DECAYABLE)) {
|
||||
meta |= 1;
|
||||
}
|
||||
if (state.getValue(CHECK_DECAY)) {
|
||||
meta |= 2;
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public int getBlockColor() {
|
||||
return 16777215;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public int getRenderColor(IBlockState state) {
|
||||
return 16777215;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) {
|
||||
return 16777215;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
|
||||
return Item.getItemFromBlock(TRContent.RUBBER_SAPLING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
|
||||
if(!fancyLeaves()){
|
||||
return blockState.shouldSideBeRendered(blockAccess, pos, side);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean fancyLeaves(){
|
||||
return TechReborn.proxy.fancyGraphics();
|
||||
public IItemProvider getItemDropped(IBlockState state, World worldIn, BlockPos pos, int fortune) {
|
||||
return TRContent.RUBBER_SAPLING;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ package techreborn.blocks;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.BlockLeaves;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
|
@ -33,7 +34,6 @@ import net.minecraft.state.DirectionProperty;
|
|||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
@ -44,10 +44,7 @@ import net.minecraft.util.EnumHand;
|
|||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
import reborncore.client.models.ModelCompound;
|
||||
import reborncore.client.models.RebornModelRegistry;
|
||||
import reborncore.common.powerSystem.ExternalPowerSystems;
|
||||
|
@ -59,8 +56,6 @@ import techreborn.init.ModSounds;
|
|||
import techreborn.init.TRContent;
|
||||
import techreborn.items.tool.basic.ItemElectricTreetap;
|
||||
import techreborn.items.tool.ItemTreeTap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
|
@ -73,8 +68,7 @@ public class BlockRubberLog extends Block {
|
|||
|
||||
public BlockRubberLog() {
|
||||
super(Block.Properties.create(Material.WOOD).hardnessAndResistance(2f).sound(SoundType.WOOD).needsRandomTick());
|
||||
this.setDefaultState(
|
||||
this.getDefaultState().with(SAP_SIDE, EnumFacing.NORTH).with(HAS_SAP, false));
|
||||
this.setDefaultState(this.getDefaultState().with(SAP_SIDE, EnumFacing.NORTH).with(HAS_SAP, false));
|
||||
((BlockFire) Blocks.FIRE).setFireInfo(this, 5, 5);
|
||||
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this));
|
||||
}
|
||||
|
@ -92,27 +86,28 @@ public class BlockRubberLog extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
|
||||
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
|
||||
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 state1 = worldIn.getBlockState(blockpos);
|
||||
if (state1.getBlock().isLeaves(state1, worldIn, blockpos)) {
|
||||
state1.getBlock().beginLeavesDecay(state1, worldIn, blockpos);
|
||||
if (state1.getBlock() instanceof BlockLeaves) {
|
||||
state1.getBlock().tick(state1, worldIn, pos, worldIn.getRandom());
|
||||
state1.getBlock().randomTick(state1, worldIn, pos, worldIn.getRandom());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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(50) == 0) {
|
||||
EnumFacing facing = EnumFacing.byHorizontalIndex(rand.nextInt(4));
|
||||
public void tick(IBlockState state, World worldIn, BlockPos pos, Random random) {
|
||||
super.tick(state, worldIn, pos, random);
|
||||
if (!state.get(HAS_SAP)) {
|
||||
if (random.nextInt(50) == 0) {
|
||||
EnumFacing facing = EnumFacing.byHorizontalIndex(random.nextInt(4));
|
||||
if (worldIn.getBlockState(pos.down()).getBlock() == this
|
||||
&& worldIn.getBlockState(pos.up()).getBlock() == this) {
|
||||
&& worldIn.getBlockState(pos.up()).getBlock() == this) {
|
||||
worldIn.setBlockState(pos, state.with(HAS_SAP, true).with(SAP_SIDE, facing));
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +115,8 @@ public class BlockRubberLog extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn,
|
||||
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
|
||||
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||
if (stack.isEmpty()) {
|
||||
|
@ -131,11 +127,10 @@ public class BlockRubberLog extends Block {
|
|||
capEnergy = new ForgePowerItemManager(stack);
|
||||
}
|
||||
if ((capEnergy != null && capEnergy.getEnergyStored() > 20) || stack.getItem() instanceof ItemTreeTap) {
|
||||
if (state.getValue(HAS_SAP) && state.getValue(SAP_SIDE) == side) {
|
||||
worldIn.setBlockState(pos,
|
||||
state.with(HAS_SAP, false).with(SAP_SIDE, EnumFacing.byHorizontalIndex(0)));
|
||||
if (state.get(HAS_SAP) && state.get(SAP_SIDE) == side) {
|
||||
worldIn.setBlockState(pos, state.with(HAS_SAP, false).with(SAP_SIDE, EnumFacing.byHorizontalIndex(0)));
|
||||
worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS,
|
||||
0.6F, 1F);
|
||||
0.6F, 1F);
|
||||
if (!worldIn.isRemote) {
|
||||
if (capEnergy != null) {
|
||||
capEnergy.extractEnergy(20, false);
|
||||
|
|
Loading…
Reference in a new issue