Java Code Examples for net.minecraft.block.state.IBlockState

The following examples show how to use net.minecraft.block.state.IBlockState. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: NOVA-Core   Source File: FWBlock.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
	Block blockInstance;

	// see onBlockHarvested for why the harvestedBlocks hack exists
	// this method will be called exactly once after destroying the block
	BlockPosition position = new BlockPosition((World) world, pos.getX(), pos.getY(), pos.getZ());
	if (harvestedBlocks.containsKey(position)) {
		blockInstance = harvestedBlocks.remove(position);
	} else {
		blockInstance = getBlockInstance(world, pos);
	}

	Block.DropEvent event = new Block.DropEvent(blockInstance);
	blockInstance.events.publish(event);

	return event.drops
		.stream()
		.map(ItemConverter.instance()::toNative)
		.collect(Collectors.toList());
}
 
Example 2
Source Project: EmergingTechnology   Source File: Bioreactor.java    License: MIT License 6 votes vote down vote up
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    if (!worldIn.isRemote) {
        IBlockState north = worldIn.getBlockState(pos.north());
        IBlockState east = worldIn.getBlockState(pos.east());
        IBlockState south = worldIn.getBlockState(pos.south());
        IBlockState west = worldIn.getBlockState(pos.west());

        EnumFacing face = (EnumFacing) state.getValue(FACING);

        if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) {
            face = EnumFacing.SOUTH;
        } else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) {
            face = EnumFacing.NORTH;
        } else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) {
            face = EnumFacing.WEST;
        } else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) {
            face = EnumFacing.EAST;
        }

        worldIn.setBlockState(pos, state.withProperty(FACING, face));
    }
}
 
Example 3
public boolean shouldBreak(EntityPlayer playerIn, World worldIn, BlockPos originalPos, BlockPos pos) {
	if (originalPos.equals(pos)) {
		return false;
	}
	IBlockState blockState = worldIn.getBlockState(pos);
	if (blockState.getMaterial() == Material.AIR) {
		return false;
	}
	if (blockState.getMaterial().isLiquid()) {
		return false;
	}
	float blockHardness = blockState.getPlayerRelativeBlockHardness(playerIn, worldIn, pos);
	if (blockHardness == -1.0F) {
		return false;
	}
	float originalHardness = worldIn.getBlockState(originalPos).getPlayerRelativeBlockHardness(playerIn, worldIn, originalPos);
	if ((originalHardness / blockHardness) > 10.0F) {
		return false;
	}
	return true;
}
 
Example 4
Source Project: OpenModsLib   Source File: OpenBlock.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation") // TODO review
@Override
public boolean eventReceived(IBlockState state, World world, BlockPos blockPos, int eventId, int eventParam) {
	if (eventId < 0 && !world.isRemote) {
		switch (eventId) {
			case EVENT_ADDED:
				return onBlockAddedNextTick(world, blockPos, state);
		}

		return false;
	}
	if (hasTileEntity) {
		super.eventReceived(state, world, blockPos, eventId, eventParam);
		TileEntity te = world.getTileEntity(blockPos);
		return te != null? te.receiveClientEvent(eventId, eventParam) : false;
	} else {
		return super.eventReceived(state, world, blockPos, eventId, eventParam);
	}
}
 
Example 5
Source Project: NOVA-Core   Source File: FWBlock.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity entity) {
	Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos));
	blockInstance.components.getOp(Collider.class).ifPresent(
		collider -> {
			Set<Cuboid> boxes = collider.occlusionBoxes.apply(Optional.ofNullable(entity != null ? EntityConverter.instance().toNova(entity) : null));

			list.addAll(
				boxes
					.stream()
					.map(c -> c.add(VectorConverter.instance().toNova(pos)))
					.filter(c -> c.intersects(CuboidConverter.instance().toNova(mask)))
					.map(CuboidConverter.instance()::toNative)
					.collect(Collectors.toList())
			);
		}
	);
}
 
Example 6
@Override
public IBlockState getExtendedState(IBlockState oldState, IBlockAccess world, BlockPos pos)
{
    if (this.isCamoBlock())
    {
        TileEntityEnderUtilities te = getTileEntitySafely(world, pos, TileEntityEnderUtilities.class);

        if (te != null)
        {
            IExtendedBlockState state = (IExtendedBlockState) oldState;
            state = state.withProperty(CAMOBLOCKSTATE, te.getCamoState());
            state = state.withProperty(CAMOBLOCKSTATEEXTENDED, te.getCamoExtendedState());
            return state;
        }
    }

    return oldState;
}
 
Example 7
@Override
public boolean onBlockDestroyed(final ItemStack tool, final World world, 
		final IBlockState target, final BlockPos coord, final EntityLivingBase player) {
	if(!world.isRemote && this.canHarvestBlock(target)){
		IBlockState bs = world.getBlockState(coord);
		ICrusherRecipe recipe = getCrusherRecipe(bs);
		if(recipe != null){
			ItemStack output = recipe.getOutput().copy();
			world.setBlockToAir(coord);
			if(output != null){
				int num = output.stackSize;
				output.stackSize = 1;
				for(int i = 0; i < num; i++){
					world.spawnEntityInWorld(new EntityItem(world, coord.getX()+0.5, coord.getY()+0.5, coord.getZ()+0.5, output.copy()));
				}
			}
		}
	}
	return super.onBlockDestroyed(tool, world, target, coord, player);
	
}
 
Example 8
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
    if (state.getValue(TYPE).retainsContents())
    {
        world.updateComparatorOutputLevel(pos, this);
        world.removeTileEntity(pos);
    }
    else
    {
        super.breakBlock(world, pos, state);
    }
}
 
Example 9
Source Project: Sakura_mod   Source File: TileEntityShoji.java    License: MIT License 5 votes vote down vote up
public void setFacing(EnumFacing facing) {
    this.facing = facing;
    markDirty(); 
    if (world != null) {
        IBlockState state = world.getBlockState(getPos());
        world.notifyBlockUpdate(getPos(), state, state, 3);
    }
}
 
Example 10
Source Project: Production-Line   Source File: ItemPLTreetap.java    License: MIT License 5 votes vote down vote up
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xOffset, float yOffset, float zOffset) {
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (block == BlockName.rubber_wood.getInstance()) {
        attemptExtract(player, world, pos, side, state, null);
        if (!world.isRemote) {
            stack.damageItem(1, player);
        }

        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.PASS;
    }
}
 
Example 11
Source Project: Sakura_mod   Source File: BlockStoneMortar.java    License: MIT License 5 votes vote down vote up
@Override
  public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
      if (world.isRemote) {
          return true;
      }
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileEntityStoneMortar) {
    player.openGui(SakuraMain.instance, SakuraGuiHandler.ID_STONEMORTAR, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
  }
 
Example 12
Source Project: AdvancedRocketry   Source File: BlockPressurizedFluidTank.java    License: MIT License 5 votes vote down vote up
@Override
public boolean shouldSideBeRendered(IBlockState blockState,
		IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
	
	if(side.getFrontOffsetY() != 0) {
		if(blockAccess.getBlockState(pos).getBlock() == this)
		return true;
	}
	
	return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
 
Example 13
Source Project: ExNihiloAdscensio   Source File: BlockInfestedLeaves.java    License: MIT License 5 votes vote down vote up
@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world,
		IBlockState blockState, IProbeHitData data) {

	TileInfestedLeaves tile = (TileInfestedLeaves) world.getTileEntity(data.getPos());

	if (tile.getProgress() >= 1.0F) {
		probeInfo.text("Progress: Done");
	} else {
		probeInfo.progress((int) (tile.getProgress()*100), 100);
	}

}
 
Example 14
Source Project: seppuku   Source File: BlockHighlightModule.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void render3D(EventRender3D event) {
    final Minecraft mc = Minecraft.getMinecraft();
    final RayTraceResult ray = mc.objectMouseOver;
    if(ray.typeOfHit == RayTraceResult.Type.BLOCK) {

        final BlockPos blockpos = ray.getBlockPos();
        final IBlockState iblockstate = mc.world.getBlockState(blockpos);

        if (iblockstate.getMaterial() != Material.AIR && mc.world.getWorldBorder().contains(blockpos)) {
            final Vec3d interp = MathUtil.interpolateEntity(mc.player, mc.getRenderPartialTicks());
            RenderUtil.drawBoundingBox(iblockstate.getSelectedBoundingBox(mc.world, blockpos).grow(0.0020000000949949026D).offset(-interp.x, -interp.y, -interp.z), 1.5f, 0xFF9900EE);
        }
    }
}
 
Example 15
Source Project: NOVA-Core   Source File: FWBlock.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@Deprecated
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World world, BlockPos pos) {
	Block blockInstance = getBlockInstance(world, pos);

	if (blockInstance.components.has(Collider.class)) {
		Collider collider = blockInstance.components.get(Collider.class);
		Set<Cuboid> cuboids = collider.selectionBoxes.apply(Optional.empty());
		Cuboid cuboid = cuboids.stream().reduce(collider.boundingBox.get(),
			(c1, c2) -> new Cuboid(Vector3DUtil.min(c1.min, c2.min), Vector3DUtil.max(c1.max, c2.max)));
		return CuboidConverter.instance().toNative(cuboid.add(VectorConverter.instance().toNova(pos)));
	}
	return super.getSelectedBoundingBox(state, world, pos);
}
 
Example 16
Source Project: litematica   Source File: ItemUtils.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static ItemStack getStateToItemOverride(IBlockState state)
{
    if (state.getBlock() == Blocks.LAVA || state.getBlock() == Blocks.FLOWING_LAVA)
    {
        return new ItemStack(Items.LAVA_BUCKET);
    }
    else if (state.getBlock() == Blocks.WATER || state.getBlock() == Blocks.FLOWING_WATER)
    {
        return new ItemStack(Items.WATER_BUCKET);
    }

    return ItemStack.EMPTY;
}
 
Example 17
@SideOnly(Side.CLIENT)
@Override
public void randomTickDisplay(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
	if (this.isActive && this.portalMode
			&& worldIn.getBlockState(this.pos.offset(EnumFacing.DOWN)).getBlock() == Blocks.END_PORTAL) {
		for (EnumFacing facing : EnumFacing.HORIZONTALS) {
			BlockPos sidePos = pos.offset(facing);
			if (world.getBlockState(sidePos).isFullBlock()) {
				continue;
			}
			for (int k = 3; k > 0; --k) {
				ParticleManager er = Minecraft.getMinecraft().effectRenderer;
				float multPos = (float) (.1 * 2) + 0.9F;
				double x = (double) ((float) sidePos.getX() + 0.05F + rand.nextFloat() * multPos);
				double y = (double) ((float) sidePos.getY() + 0.0F + rand.nextFloat() * 0.5F);
				double z = (double) ((float) sidePos.getZ() + 0.05F + rand.nextFloat() * multPos);
				double[] velocity = new double[] { 0.0D, 7.6D, 0.0D };
				if (k < 4) {
					velocity[2] *= 0.55D;
				}
				float foo = rand.nextFloat() * .25F;
				float[] colour = new float[] { 0.0F, foo, foo };
				er.addEffect(new EntityChargePadAuraFX(this.world, x, y, z, 8, velocity, colour, false));
			}
		}
	}
}
 
Example 18
Source Project: EmergingTechnology   Source File: Harvester.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

    if (worldIn.isRemote) {
        return true;
    }

    playerIn.openGui(EmergingTechnology.instance, Reference.GUI_HARVESTER, worldIn, pos.getX(), pos.getY(),
            pos.getZ());

    return true;
}
 
Example 19
Source Project: TFC2   Source File: Core.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static IBlockState getNaturalLog(WoodType w)
{
	if(w == WoodType.Palm)
		return TFCBlocks.LogNaturalPalm.getDefaultState();
	if(w.getMeta() >= 16)
		return TFCBlocks.LogNatural2.getDefaultState().withProperty(BlockLogNatural2.WOOD, w);
	return TFCBlocks.LogNatural.getDefaultState().withProperty(BlockLogNatural.WOOD, w);
}
 
Example 20
Source Project: Cyberware   Source File: ItemBrainUpgrade.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleMining(BreakSpeed event)
{
	EntityPlayer p = event.getEntityPlayer();
	
	ItemStack test = new ItemStack(this, 1, 3);
	if (CyberwareAPI.isCyberwareInstalled(p, test) && EnableDisableHelper.isEnabled(CyberwareAPI.getCyberware(p, test)) && isContextWorking(p) && !p.isSneaking())
	{
		IBlockState state = event.getState();
		ItemStack tool = p.getHeldItem(EnumHand.MAIN_HAND);
		
		if (tool != null && (tool.getItem() instanceof ItemSword || tool.getItem().getUnlocalizedName().contains("sword"))) return;
		
		if (isToolEffective(tool, state)) return;
		
		for (int i = 0; i < 10; i++)
		{
			if (i != p.inventory.currentItem)
			{
				ItemStack potentialTool = p.inventory.mainInventory[i];
				if (isToolEffective(potentialTool, state))
				{
					p.inventory.currentItem = i;
					return;
				}
			}
		}
	}
}
 
Example 21
Source Project: Valkyrien-Skies   Source File: BlockNetworkRelay.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convert the BlockState into the correct metadata value
 */
@Override
public int getMetaFromState(IBlockState state) {
    int i;

    switch (state.getValue(FACING)) {
        case EAST:
            i = 1;
            break;
        case WEST:
            i = 2;
            break;
        case SOUTH:
            i = 3;
            break;
        case NORTH:
            i = 4;
            break;
        case UP:
        default:
            i = 5;
            break;
        case DOWN:
            i = 0;
    }

    return i;
}
 
Example 22
Source Project: Cyberware   Source File: BlockBlueprintArchive.java    License: MIT License 5 votes vote down vote up
@Override
public IBlockState getStateFromMeta(int meta)
{
	EnumFacing enumfacing = EnumFacing.getFront(meta);

	if (enumfacing.getAxis() == EnumFacing.Axis.Y)
	{
		enumfacing = EnumFacing.NORTH;
	}

	return this.getDefaultState().withProperty(FACING, enumfacing);
}
 
Example 23
Source Project: AdvancedRocketry   Source File: BlockSeal.java    License: MIT License 5 votes vote down vote up
public void clearBlob(World worldIn, BlockPos pos, IBlockState state) {
	AtmosphereHandler atmhandler = AtmosphereHandler.getOxygenHandler(worldIn.provider.getDimension());
	if(atmhandler == null)
		return;
	
	for(EnumFacing dir : EnumFacing.VALUES) {
		BlobHandler handler = blobList.remove(new HashedBlockPosition(pos.offset(dir)));
		if (handler != null) atmhandler.unregisterBlob(handler);
		
		//fireCheckAllDirections(worldIn, pos.offset(dir), dir);
	}
}
 
Example 24
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	TileEntity te = world.getTileEntity(pos);
	if (te != null && te instanceof TileEntityBBarrel) {
		TileEntityBBarrel chest = (TileEntityBBarrel) te;
		ItemStack currentItem = player.getHeldItem(hand);
		if (currentItem.getItem() instanceof IUpgrade) {
			IUpgrade upgrade = (IUpgrade) currentItem.getItem();
			ItemStack toPut = currentItem.copy();
			toPut.setCount(1);
			if (upgrade.canBePutInChest(chest, toPut)) {
				if (InvUtil.putStackInInventoryFirst(toPut, chest.getUpgradePart(), false, false, false, null).isEmpty()) {
					currentItem.setCount(currentItem.getCount() - 1);
					chest.markDirty();
					return true;
				}
			}
		}
		if (player.isSneaking()) {
			ContainerHelper.openGui(chest, player, (short) 0);
		} else {
			ItemStack stack = player.getHeldItem(hand);
			if (stack.isEmpty()) {
				stack = chest.getChestPart().getDummy();
				for (ItemStack other : InvUtil.getFromInv(player.inventory)) {
					if (ItemUtil.areItemsSameMatchingIdDamageNbt(stack, other)) {
						ItemStack curr = InvUtil.putStackInInventoryInternal(other, chest.getChestPart(), false);
						other.setCount(curr.getCount());
						if (!other.isEmpty()) {
							break;
						}
					}
				}
			} else if (chest.getChestPart().isItemValidForSlot(0, stack)) {
				stack.setCount(InvUtil.putStackInInventoryInternal(stack, chest.getChestPart(), false).getCount());
			}
		}
	}
	return true;
}
 
Example 25
Source Project: Production-Line   Source File: BlockWaterHyacinth.java    License: MIT License 5 votes vote down vote up
/**
 * Called When an Entity Collided with the Block
 */
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
    super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);

    if (entityIn instanceof EntityBoat) {
        worldIn.destroyBlock(new BlockPos(pos), true);
    }
}
 
Example 26
Source Project: EmergingTechnology   Source File: SolarGlass.java    License: MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
        EnumFacing side) {
    IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
    Block block = iblockstate.getBlock();

    if (block == this || block == ModBlocks.clearplasticblock) {
        return false;
    }

    return block == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
 
Example 27
Source Project: AdvancedRocketry   Source File: BlockAlienSapling.java    License: MIT License 5 votes vote down vote up
public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (((Integer)state.getValue(STAGE)).intValue() == 0)
    {
        worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4);
    }
    else
    {
        this.generateTree(worldIn, pos, state, rand);
    }
}
 
Example 28
Source Project: AgriCraft   Source File: PlayerInteractEventHandler.java    License: MIT License 4 votes vote down vote up
/**
 * Event handler to disable vanilla farming.
 * 
 * @param event
 */
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void vanillaSeedPlanting(PlayerInteractEvent.RightClickBlock event) {
    // If not disabled, don't bother.
    if (!AgriCraftConfig.disableVanillaFarming) {
        return;
    }

    // Fetch the event itemstack.
    final ItemStack stack = event.getItemStack();

    // If the stack is null, or otherwise invalid, who cares?
    if (!StackHelper.isValid(stack)) {
        return;
    }

    // If the item in the player's hand is not a seed, who cares?
    if (!AgriApi.getSeedRegistry().hasAdapter(stack)) {
        return;
    }

    // Fetch world information.
    final BlockPos pos = event.getPos();
    final World world = event.getWorld();
    final IBlockState state = world.getBlockState(pos);

    // Fetch the block at the location.
    final Block block = state.getBlock();

    // If clicking crop block, who cares?
    if (block instanceof IAgriCrop) {
        return;
    }

    // If the item is an instance of IPlantable we need to perfom an extra check.
    if (stack.getItem() instanceof IPlantable) {
        // If the clicked block cannot support the given plant, then who cares?
        if (!block.canSustainPlant(state, world, pos, EnumFacing.UP, (IPlantable) stack.getItem())) {
            return;
        }
    }

    // If clicking crop tile, who cares?
    if (WorldHelper.getTile(event.getWorld(), event.getPos(), IAgriCrop.class).isPresent()) {
        return;
    }

    // The player is attempting to plant a seed, which is simply unacceptable.
    // We must deny this event.
    event.setUseItem(Event.Result.DENY);

    // If we are on the client side we are done.
    if (event.getSide().isClient()) {
        return;
    }

    // Should the server notify the player that vanilla farming has been disabled?
    if (AgriCraftConfig.showDisabledVanillaFarmingWarning) {
        MessageUtil.messagePlayer(event.getEntityPlayer(), "`7Vanilla planting is disabled!`r");
    }
}
 
Example 29
@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
{
    return 15;
}
 
Example 30
Source Project: AdvancedRocketry   Source File: BlockLaser.java    License: MIT License 4 votes vote down vote up
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos,
		Block blockIn, BlockPos fromPos) {
	if(blockIn != this)
		((TileSpaceLaser)worldIn.getTileEntity(pos)).checkCanRun();
}