BloodMagic/src/main/java/WayofTime/bloodmagic/block/BlockAlchemyArray.java

144 lines
4.4 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic;
2017-08-15 21:30:48 -07:00
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.tile.TileAlchemyArray;
import WayofTime.bloodmagic.util.Utils;
2017-01-01 21:43:34 -08:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
2016-03-18 13:16:38 -04:00
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
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;
2017-01-01 21:43:34 -08:00
import javax.annotation.Nullable;
2017-08-15 21:30:48 -07:00
import java.util.List;
import java.util.Random;
2017-01-01 21:43:34 -08:00
2017-08-15 21:30:48 -07:00
public class BlockAlchemyArray extends Block {
2016-03-18 13:16:38 -04:00
protected static final AxisAlignedBB ARRAY_AABB = new AxisAlignedBB(0, 0, 0, 1, 0.1, 1);
2017-08-15 21:30:48 -07:00
public BlockAlchemyArray() {
2016-04-24 10:06:28 -07:00
super(Material.CLOTH);
setUnlocalizedName(BloodMagic.MODID + ".alchemyArray");
setHardness(0.1f);
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_) {
// No-op
}
@Override
2017-08-15 21:30:48 -07:00
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
TileEntity tile = world.getTileEntity(pos);
2017-08-15 21:30:48 -07:00
if (tile instanceof TileAlchemyArray) {
((TileAlchemyArray) tile).onEntityCollidedWithBlock(state, entity);
}
}
@Override
2017-08-15 21:30:48 -07:00
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
2016-03-18 13:16:38 -04:00
return ARRAY_AABB;
}
@Override
@SideOnly(Side.CLIENT)
2017-08-15 21:30:48 -07:00
public BlockRenderLayer getBlockLayer() {
2016-03-18 13:16:38 -04:00
return BlockRenderLayer.CUTOUT;
}
@Override
2017-08-15 21:30:48 -07:00
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
2016-03-18 13:16:38 -04:00
return false;
}
@Override
2017-08-15 21:30:48 -07:00
public boolean isFullCube(IBlockState state) {
2016-03-18 13:16:38 -04:00
return false;
}
@Override
2017-08-15 21:30:48 -07:00
public boolean causesSuffocation(IBlockState state) {
return false;
}
@Override
2017-08-15 21:30:48 -07:00
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
2017-08-15 21:30:48 -07:00
public EnumBlockRenderType getRenderType(IBlockState state) {
2016-03-18 13:16:38 -04:00
return EnumBlockRenderType.INVISIBLE;
}
@Override
2017-08-15 21:30:48 -07:00
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
//TODO: Right click should rotate it
TileAlchemyArray array = (TileAlchemyArray) world.getTileEntity(pos);
if (array == null || player.isSneaking())
return false;
2016-03-18 13:16:38 -04:00
ItemStack playerItem = player.getHeldItem(hand);
2017-08-15 21:30:48 -07:00
if (!playerItem.isEmpty()) {
if (array.getStackInSlot(0).isEmpty()) {
Utils.insertItemToTile(array, player, 0);
2017-08-15 21:30:48 -07:00
} else if (!array.getStackInSlot(0).isEmpty()) {
Utils.insertItemToTile(array, player, 1);
array.attemptCraft();
2017-08-15 21:30:48 -07:00
} else {
return true;
}
}
2016-03-18 13:16:38 -04:00
world.notifyBlockUpdate(pos, state, state, 3);
return true;
}
@Override
2017-08-15 21:30:48 -07:00
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
return new ItemStack(RegistrarBloodMagicItems.ARCANE_ASHES);
}
@Override
2017-08-15 21:30:48 -07:00
public int quantityDropped(Random random) {
return 0;
}
@Override
2017-08-15 21:30:48 -07:00
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState) {
TileAlchemyArray alchemyArray = (TileAlchemyArray) world.getTileEntity(blockPos);
if (alchemyArray != null)
alchemyArray.dropItems();
super.breakBlock(world, blockPos, blockState);
}
2017-01-01 21:43:34 -08:00
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
@Nullable
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileAlchemyArray();
}
}