use of net.minecraft.item.ItemBlock in project ArsMagica2 by Mithion.
the class BlockEverstone method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
if (player.getHeldItem() != null) {
Block block = null;
int meta = -1;
TileEntityEverstone everstone = getTE(world, x, y, z);
if (everstone == null)
return false;
if (player.getHeldItem().getItem() == ItemsCommonProxy.crystalWrench) {
if (!world.isRemote) {
if (everstone.getFacade() != null) {
everstone.setFacade(null, -1);
return true;
} else {
world.setBlockToAir(x, y, z);
this.dropBlockAsItem(world, x, y, z, new ItemStack(BlocksCommonProxy.everstone));
return true;
}
}
} else if (player.getHeldItem().getItem() instanceof ItemBlock) {
ItemBlock itemblock = (ItemBlock) player.getHeldItem().getItem();
block = itemblock.field_150939_a;
if (block.isOpaqueCube()) {
meta = itemblock.getMetadata(player.getHeldItem().getItemDamage());
}
}
if (everstone.getFacade() == null && block != null) {
everstone.setFacade(block, meta);
world.notifyBlockChange(x, y, z, this);
return true;
}
}
return false;
}
use of net.minecraft.item.ItemBlock in project Pearcel-Mod by MiningMark48.
the class ModBlocks method registerBlock.
private static void registerBlock(Block block) {
GameRegistry.register(block);
ItemBlock item = new ItemBlock(block);
item.setRegistryName(block.getRegistryName());
GameRegistry.register(item);
}
use of net.minecraft.item.ItemBlock in project Overloaded by CJ-MC-Mods.
the class PlayerInteractionUtil method placeBlock.
public static boolean placeBlock(@Nonnull ItemStack searchStack, @Nonnull EntityPlayerMP player, @Nonnull World worldIn, @Nonnull BlockPos newPosition, @Nonnull EnumFacing facing, @Nonnull IEnergyStorage energy, float hitX, float hitY, float hitZ) {
// Can we place a block at this Pos
ItemBlock itemBlock = ((ItemBlock) searchStack.getItem());
if (!worldIn.mayPlace(itemBlock.getBlock(), newPosition, false, facing, null)) {
return false;
}
BlockEvent.PlaceEvent event = ForgeEventFactory.onPlayerBlockPlace(player, new BlockSnapshot(worldIn, newPosition, worldIn.getBlockState(newPosition)), facing, EnumHand.MAIN_HAND);
if (event.isCanceled())
return false;
long distance = Math.round(player.getPosition().getDistance(newPosition.getX(), newPosition.getY(), newPosition.getZ()));
long cost = OverloadedConfig.multiToolConfig.placeBaseCost + OverloadedConfig.multiToolConfig.costPerMeterAway * distance;
if (cost > Integer.MAX_VALUE || cost < 0 || energy.getEnergyStored() < cost)
return false;
IItemHandler inventory = player.getCapability(ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
int foundStackSlot = findItemStack(searchStack, inventory);
if (foundStackSlot == -1) {
System.out.println("Stack not found");
return false;
}
System.out.println("Stack found at index: " + foundStackSlot);
ItemStack foundStack = inventory.extractItem(foundStackSlot, 1, player.capabilities.isCreativeMode);
int i = itemBlock.getMetadata(foundStack.getMetadata());
IBlockState iblockstate1 = itemBlock.block.getStateForPlacement(worldIn, newPosition, facing, hitX, hitY, hitZ, i, player, EnumHand.MAIN_HAND);
if (itemBlock.placeBlockAt(foundStack, player, worldIn, newPosition, facing, hitX, hitY, hitZ, iblockstate1)) {
SoundType soundtype = worldIn.getBlockState(newPosition).getBlock().getSoundType(worldIn.getBlockState(newPosition), worldIn, newPosition, player);
worldIn.playSound(null, newPosition, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
energy.extractEnergy((int) cost, false);
System.out.println("Place Block Successs");
return true;
}
System.out.println("Place Block Failed");
inventory.insertItem(foundStackSlot, foundStack, player.capabilities.isCreativeMode);
return false;
}
use of net.minecraft.item.ItemBlock in project minecolonies by Minecolonies.
the class BlockSolidSubstitution method initBlock.
/**
* initialize the block
* sets the creative tab, as well as the resistance and the hardness.
*/
private void initBlock() {
setRegistryName(BLOCK_NAME);
setUnlocalizedName(String.format("%s.%s", Constants.MOD_ID.toLowerCase(), BLOCK_NAME));
setCreativeTab(ModCreativeTabs.MINECOLONIES);
GameRegistry.register(this);
GameRegistry.register((new ItemBlock(this)).setRegistryName(this.getRegistryName()));
setHardness(BLOCK_HARDNESS);
setResistance(RESISTANCE);
}
use of net.minecraft.item.ItemBlock in project minecolonies by Minecolonies.
the class BlockSubstitution method initBlock.
/**
* initialize the block
* sets the creative tab, as well as the resistance and the hardness.
*/
private void initBlock() {
setRegistryName(BLOCK_NAME);
setUnlocalizedName(String.format("%s.%s", Constants.MOD_ID.toLowerCase(), BLOCK_NAME));
setCreativeTab(ModCreativeTabs.MINECOLONIES);
GameRegistry.register(this);
GameRegistry.register((new ItemBlock(this)).setRegistryName(this.getRegistryName()));
setHardness(BLOCK_HARDNESS);
setResistance(RESISTANCE);
}
Aggregations