mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 03:59:45 +00:00
170 lines
5.3 KiB
Java
170 lines
5.3 KiB
Java
/*******************************************************************************
|
|
* Copyright (c) 2011-2014 SirSengir.
|
|
* All rights reserved. This program and the accompanying materials
|
|
* are made available under the terms of the GNU Lesser Public License v3
|
|
* which accompanies this distribution, and is available at
|
|
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
*
|
|
* Various Contributors including, but not limited to:
|
|
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
|
******************************************************************************/
|
|
package forestry.lepidopterology.blocks;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.ITileEntityProvider;
|
|
import net.minecraft.block.SoundType;
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
import net.minecraft.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
import forestry.api.core.IItemModelRegister;
|
|
import forestry.api.core.IModelManager;
|
|
import forestry.api.core.IStateMapperRegister;
|
|
import forestry.api.lepidopterology.ButterflyManager;
|
|
import forestry.api.lepidopterology.EnumFlutterType;
|
|
import forestry.api.lepidopterology.IButterfly;
|
|
import forestry.core.proxy.Proxies;
|
|
import forestry.core.tiles.TileUtil;
|
|
import forestry.lepidopterology.blocks.property.PropertyCocoon;
|
|
import forestry.lepidopterology.genetics.alleles.AlleleButterflyCocoon;
|
|
import forestry.lepidopterology.items.ItemButterflyGE;
|
|
import forestry.lepidopterology.tiles.TileCocoon;
|
|
|
|
public class BlockCocoon extends Block implements ITileEntityProvider, IStateMapperRegister, IItemModelRegister {
|
|
public static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.3125F, 0.3125F, 0.3125F, 0.6875F, 1F, 0.6875F);
|
|
private static final PropertyCocoon COCOON = AlleleButterflyCocoon.COCOON;
|
|
|
|
public BlockCocoon() {
|
|
super(new MaterialCocoon());
|
|
setTickRandomly(true);
|
|
setSoundType(SoundType.GROUND);
|
|
setCreativeTab(null);
|
|
setDefaultState(this.blockState.getBaseState().withProperty(COCOON, AlleleButterflyCocoon.cocoonDefault).withProperty(AlleleButterflyCocoon.AGE, 0));
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
protected BlockStateContainer createBlockState() {
|
|
return new BlockStateContainer(this, COCOON, AlleleButterflyCocoon.AGE);
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@Override
|
|
public IBlockState getActualState(@Nonnull IBlockState state, IBlockAccess world, BlockPos pos) {
|
|
TileCocoon cocoon = TileUtil.getTile(world, pos, TileCocoon.class);
|
|
if(cocoon != null){
|
|
state = state.withProperty(COCOON, cocoon.getCaterpillar().getGenome().getCocoon()).withProperty(AlleleButterflyCocoon.AGE, cocoon.getAge());
|
|
}
|
|
return super.getActualState(state, world, pos);
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@Override
|
|
public void registerStateMapper() {
|
|
Proxies.render.registerStateMapper(this, new CocoonStateMapper());
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@Override
|
|
public void registerModel(Item item, IModelManager manager) {
|
|
//To delete the error message
|
|
manager.registerItemModel(item, 0, "cocoon_late");
|
|
}
|
|
|
|
@Override
|
|
public boolean isFullBlock(IBlockState state) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isOpaqueCube(IBlockState state) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
|
TileCocoon tileCocoon = TileUtil.getTile(world, pos, TileCocoon.class);
|
|
if (tileCocoon == null) {
|
|
return;
|
|
}
|
|
|
|
if (tileCocoon.isInvalid()) {
|
|
return;
|
|
}
|
|
|
|
if (world.rand.nextFloat() > 0.1) {
|
|
return;
|
|
}
|
|
tileCocoon.onBlockTick();
|
|
}
|
|
|
|
@Override
|
|
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
|
return new TileCocoon(false);
|
|
}
|
|
|
|
@Override
|
|
public int getMetaFromState(IBlockState state){
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
|
|
if (worldIn.isAirBlock(pos.up())) {
|
|
worldIn.setBlockToAir(pos);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
|
return Collections.emptyList();
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
|
|
TileCocoon tile = TileUtil.getTile(world, pos, TileCocoon.class);
|
|
if (tile == null) {
|
|
return null;
|
|
}
|
|
|
|
IButterfly caterpillar = tile.getCaterpillar();
|
|
int age = tile.getAge();
|
|
|
|
ItemStack stack = ButterflyManager.butterflyRoot.getMemberStack(caterpillar, EnumFlutterType.COCOON);
|
|
if (stack == null) {
|
|
return null;
|
|
}
|
|
|
|
stack.getTagCompound().setInteger(ItemButterflyGE.NBT_AGE, age);
|
|
|
|
return stack;
|
|
}
|
|
|
|
@Override
|
|
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos) {
|
|
return BOUNDING_BOX.offset(pos);
|
|
}
|
|
|
|
@Override
|
|
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) {
|
|
return BOUNDING_BOX;
|
|
}
|
|
|
|
}
|