net.minecraft.block.state.IBlockState Java Examples

The following examples show how to use net.minecraft.block.state.IBlockState. 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 check out the related API usage on the sidebar.
Example #1
Source File: OpenBlock.java    From OpenModsLib with 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 #2
Source File: BlockEnderUtilitiesTileEntity.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: FWBlock.java    From NOVA-Core with 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 #4
Source File: GTItemJackHammer.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #5
Source File: ItemMetalCrackHammer.java    From BaseMetals with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 #6
Source File: Bioreactor.java    From EmergingTechnology with 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 #7
Source File: FWBlock.java    From NOVA-Core with 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 #8
Source File: Harvester.java    From EmergingTechnology with 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 #9
Source File: SolarGlass.java    From EmergingTechnology with 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 #10
Source File: ItemUtils.java    From litematica with 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 #11
Source File: TileEntityShoji.java    From Sakura_mod with 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 #12
Source File: BlockStorage.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #13
Source File: BlockBBarrel.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #14
Source File: ItemPLTreetap.java    From Production-Line with 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 #15
Source File: BlockAlienSapling.java    From AdvancedRocketry with 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 #16
Source File: GTTileMagicEnergyAbsorber.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #17
Source File: BlockWaterHyacinth.java    From Production-Line with 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 #18
Source File: BlockSeal.java    From AdvancedRocketry with 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 #19
Source File: BlockStoneMortar.java    From Sakura_mod with 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 #20
Source File: BlockPressurizedFluidTank.java    From AdvancedRocketry with 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 #21
Source File: BlockInfestedLeaves.java    From ExNihiloAdscensio with 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 #22
Source File: ItemBrainUpgrade.java    From Cyberware with 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 #23
Source File: BlockNetworkRelay.java    From Valkyrien-Skies with 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 #24
Source File: BlockHighlightModule.java    From seppuku with 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 #25
Source File: FWBlock.java    From NOVA-Core with 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 #26
Source File: BlockBlueprintArchive.java    From Cyberware with 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 #27
Source File: Core.java    From TFC2 with 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 #28
Source File: BlockBackpack.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@Override
public boolean isOpaqueCube(IBlockState state) { return false; }
 
Example #29
Source File: BlockSpeedTelegraph.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isFullCube(IBlockState state) {
    return false;
}
 
Example #30
Source File: BlockTorikkiGrass.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Nonnull
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
	return Blocks.DIRT.getItemDropped(Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, DirtType.DIRT), rand, fortune);
}