Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.reygok.octablocks.items;
- import scala.collection.mutable.SetBuilder;
- import com.reygok.octablocks.OctablocksMod;
- import com.reygok.octablocks.blocks.TileEntityTinyDirt;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockSnow;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.item.ItemBlock;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.world.World;
- public class ItemTinyDirt extends ItemBlock{
- public ItemTinyDirt(Block block) {
- super(block);
- }
- @Override
- public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
- {
- IBlockState iblockstate = worldIn.getBlockState(pos);
- Block block = iblockstate.getBlock();
- if (block == Blocks.snow_layer && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
- {
- side = EnumFacing.UP;
- }
- else if (!block.isReplaceable(worldIn, pos))
- {
- if(!(worldIn.getTileEntity(pos) instanceof TileEntityTinyDirt))
- {
- pos = pos.offset(side);
- }
- else if(hitX == 1.0 || hitX == 0.0 || hitY == 1.0 || hitY == 0.0 || hitZ == 1.0 || hitZ == 0.0)
- {
- pos = pos.offset(side);
- }
- }
- if (stack.stackSize == 0)
- {
- return false;
- }
- else if (!playerIn.canPlayerEdit(pos, side, stack))
- {
- return false;
- }
- else if (pos.getY() == 255 && this.block.getMaterial().isSolid())
- {
- return false;
- }
- else if(worldIn.getTileEntity(pos) instanceof TileEntityTinyDirt)
- {
- TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) worldIn.getTileEntity(pos);
- if(setBlockBits(worldIn, pos, tileEntity, hitX, hitY, hitZ))
- {
- System.out.println("set new bit");
- worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
- --stack.stackSize;
- if(tileEntity.isFull())
- {
- // TO FILL IN
- }
- return true;
- }
- else
- return false;
- }
- else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
- {
- int i = this.getMetadata(stack.getMetadata());
- IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);
- if (placeBlockAt(stack, playerIn, worldIn, pos, side, hitX, hitY, hitZ, iblockstate1))
- {
- worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
- --stack.stackSize;
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
- {
- if (!world.setBlockState(pos, newState, 3)) return false;
- setTileEntityNBT(world, pos, stack, player, hitX, hitY, hitZ);
- return true;
- }
- public static boolean setTileEntityNBT(World worldIn, BlockPos pos, ItemStack stack, EntityPlayer player, float hitX, float hitY, float hitZ)
- {
- TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) worldIn.getTileEntity(pos);
- setBlockBits(worldIn, pos,tileEntity, hitX, hitY, hitZ);
- return false;
- }
- public static boolean setBlockBits(World world, BlockPos pos, TileEntityTinyDirt tileEntity, float hitX, float hitY, float hitZ)
- {
- boolean xAxis = (hitX == 1.0 || hitX < 0.5) && hitX != 0.0 ? true : false;
- boolean yAxis = (hitY == 1.0 || hitY < 0.5) && hitY != 0.0 ? true : false;
- boolean zAxis = (hitZ == 1.0 || hitZ < 0.5) && hitZ != 0.0 ? true : false;
- if(xAxis)
- {
- if(yAxis)
- {
- if(zAxis)
- { // botNW
- if(tileEntity.isBot_nw())
- return false;
- else
- tileEntity.setBot_nw(true);
- }
- else
- { // botSW
- if(tileEntity.isBot_sw())
- return false;
- else
- tileEntity.setBot_sw(true);
- }
- }
- else
- {
- if(zAxis)
- { // topNW
- if(tileEntity.isTop_nw())
- return false;
- else
- tileEntity.setTop_nw(true);
- }
- else
- { // topSW
- if(tileEntity.isTop_sw())
- return false;
- else
- tileEntity.setTop_sw(true);
- }
- }
- }
- else
- {
- if(yAxis)
- {
- if(zAxis)
- { // botNE
- if(tileEntity.isBot_ne())
- return false;
- else
- tileEntity.setBot_ne(true);
- }
- else
- { // botSE
- if(tileEntity.isBot_se())
- return false;
- else
- tileEntity.setBot_se(true);
- }
- }
- else
- {
- if(zAxis)
- { // topNE
- if(tileEntity.isTop_ne())
- return false;
- else
- tileEntity.setTop_ne(true);
- }
- else
- { // topSE
- if(tileEntity.isTop_se())
- return false;
- else
- tileEntity.setTop_se(true);
- }
- }
- }
- world.markBlockForUpdate(pos);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment