Java Code Examples for net.minecraft.world.World

The following are top voted examples for showing how to use net.minecraft.world.World. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GardenStuff   File: ItemCandelillaSeeds.java   View source code 6 votes vote down vote up
@Override
public EnumActionResult onItemUse (EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    IBlockState state = worldIn.getBlockState(pos);

    if (facing != EnumFacing.UP)
        return EnumActionResult.FAIL;
    if (!player.canPlayerEdit(pos.offset(facing), facing, stack))
        return EnumActionResult.FAIL;
    if (!state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this))
        return EnumActionResult.FAIL;
    if (!worldIn.isAirBlock(pos.up()))
        return EnumActionResult.FAIL;

    worldIn.setBlockState(pos.up(), ModBlocks.candelilla.getDefaultState());
    if (player instanceof EntityPlayerMP)
        CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos.up(), stack);

    stack.shrink(1);
    return EnumActionResult.SUCCESS;
}
 
Example 2
Project: CustomWorldGen   File: BlockRedstoneWire.java   View source code 6 votes vote down vote up
/**
 * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
 * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
 * block, etc.
 */
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
{
    if (!worldIn.isRemote)
    {
        if (this.canPlaceBlockAt(worldIn, pos))
        {
            this.updateSurroundingRedstone(worldIn, pos, state);
        }
        else
        {
            this.dropBlockAsItem(worldIn, pos, state, 0);
            worldIn.setBlockToAir(pos);
        }
    }
}
 
Example 3
Project: BaseClient   File: ItemDye.java   View source code 6 votes vote down vote up
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target)
{
    IBlockState iblockstate = worldIn.getBlockState(target);

    if (iblockstate.getBlock() instanceof IGrowable)
    {
        IGrowable igrowable = (IGrowable)iblockstate.getBlock();

        if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote))
        {
            if (!worldIn.isRemote)
            {
                if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate))
                {
                    igrowable.grow(worldIn, worldIn.rand, target, iblockstate);
                }

                --stack.stackSize;
            }

            return true;
        }
    }

    return false;
}
 
Example 4
Project: minecraft-quiverbow   File: PackedUpBB.java   View source code 6 votes vote down vote up
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float sideX, float sideY, float sideZ)
   {
	if (world.isRemote) { return true; }	// Not doing this on client side
	
	Entity_BB turret = new Entity_BB(world, player);
	
	turret.setPosition(x + 0.5, y + 1 , z + 0.5);		
	world.spawnEntityInWorld(turret);
	
	// Custom name
	if (stack.hasDisplayName())	{ AI_Properties.applyNameTag(player, turret, stack, false); }
	
	if (player.capabilities.isCreativeMode) { return true; }	// Not deducting them in creative mode

	stack.stackSize -= 1;
	if (stack.stackSize <= 0)	// Used up
	{
		player.setCurrentItemOrArmor(0, null);
	}
	
	return true;
   }
 
Example 5
Project: GlobalXP   File: XPBlock.java   View source code 6 votes vote down vote up
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
	if(worldIn.isRemote || !stack.hasTagCompound())
		return;
	
	TileEntity te = worldIn.getTileEntity(pos);
	
	if(te instanceof TileEntityXPBlock)
	{
		NBTTagCompound tag = stack.getTagCompound().getCompoundTag("BlockEntityTag");

		tag.setInteger("x", pos.getX());
		tag.setInteger("y", pos.getY());
		tag.setInteger("z", pos.getZ());
		((TileEntityXPBlock)te).readFromNBT(tag);
		((TileEntityXPBlock)te).markDirty();
		GlobalXP.network.sendToAllAround(new SPacketUpdateXPBlock((TileEntityXPBlock)te), new NetworkRegistry.TargetPoint(worldIn.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64));
	}
}
 
Example 6
Project: Loot-Slash-Conquer   File: Dungeon.java   View source code 6 votes vote down vote up
/**
 * Generates a stores potential room positions off of the current template. Note: this does not take into account existing rooms. Check for existing rooms when spawning each specific room position.
 * @param currentTemplate
 */
private List<DungeonRoomPosition> generatePotentialRooms(TemplateManager manager, World world, Template currentTemplate, Rotation currentTemplateRotation, BlockPos currentCenter, Rotation currentSide)
{
	List<DungeonRoomPosition> list = Lists.newArrayList();
	
	//Rotation side = Rotation.values()[(int) (Math.random() * 4)];
	for (Rotation side : Rotation.values())
	{
		Template nextTemplate = DungeonHelper.getRandomizedDungeonTemplate(manager, world);
		Rotation nextTemplateRotation = Rotation.values()[(int) (Math.random() * 4)];
		BlockPos centeredPosition = DungeonHelper.translateToNextRoom(currentTemplate, nextTemplate, currentCenter, side, currentTemplateRotation, nextTemplateRotation);
		StructureBoundingBox boundingBox = DungeonHelper.getStructureBoundingBox(nextTemplate, nextTemplateRotation, centeredPosition);
		
		if (currentSide == null || (currentSide != null && currentSide.add(Rotation.CLOCKWISE_180) != side)) // check to make sure we aren't spawning a room on the side we just spawned from.
		{
			list.add(new DungeonRoomPosition(centeredPosition, nextTemplate, nextTemplateRotation, side, boundingBox));
		}
	}
	
	return list;
}
 
Example 7
Project: Soot   File: AlchemyResult.java   View source code 6 votes vote down vote up
public static AlchemyResult create(AspectList list,AspectRangeList range,World world)
{
    AlchemyResult result = new AlchemyResult();
    double totalDelta = 0;
    double totalCompare = 0;
    for (String aspect: range.minAspects.getAspects()) {
        int amt = list.getAspect(aspect);
        int compareAmt = range.getExact(aspect,world);
        double delta = Math.abs(amt - compareAmt);
        result.totalAsh += amt;
        totalDelta += delta;
        totalCompare += compareAmt;
        result.deltas.put(aspect,(int)delta);
    }
    result.accuracy = Math.max(0.0,1.0 - totalDelta / totalCompare);
    result.accuracy = Math.round(result.accuracy * 100.0) / 100.0;
    return result;
}
 
Example 8
Project: PurificatiMagicae   File: ItemGlove.java   View source code 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{

    ItemStack glove = playerIn.getHeldItem(handIn);
    if (handIn == EnumHand.OFF_HAND)
    {
        ItemStack shard = playerIn.getHeldItem(EnumHand.MAIN_HAND);
        if (shard.getItem() == ItemRegistry.crystal_shard)
        {
            int shrink = playerIn.isSneaking() ? shard.getCount() : 1;
            playerIn.playSound(SoundRegistry.GLASS, 1, 1);
            if (ItemSipAmulet.checkForAmulet(playerIn))
            {
                ItemStack amulet = ItemUtils.getBauble(playerIn, BaubleType.AMULET.getValidSlots()[0]);
                amulet.getCapability(CapabilityRegistry.SIP_STORE_CAP, null).add(SipUtils.getSipInStack(shard), shrink);
                ItemUtils.setBauble(playerIn, BaubleType.AMULET.getValidSlots()[0], amulet);
            }
            playerIn.getHeldItem(EnumHand.MAIN_HAND).shrink(shrink);
            return new ActionResult<>(EnumActionResult.SUCCESS, glove);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, glove);
}
 
Example 9
Project: Clef   File: ItemInstrument.java   View source code 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack is, @Nullable World worldIn, List<String> list, ITooltipFlag flag)
{
    NBTTagCompound tag = is.getTagCompound();
    if(tag != null)
    {
        Instrument instrument = InstrumentLibrary.getInstrumentByName(tag.getString("itemName"));
        if(instrument != null)
        {
            list.add(I18n.translateToLocal("item.clef.instrument." + instrument.info.itemName + ".desc"));
            list.add(I18n.translateToLocal(instrument.info.twoHanded && Clef.config.allowOneHandedTwoHandedInstrumentUse == 0 ? "clef.item.twoHanded" : "clef.item.oneHanded"));
            if(GuiScreen.isShiftKeyDown())
            {
                list.add("");
                list.add(I18n.translateToLocal("clef.item.packName") + ": " + instrument.packInfo.packName);
                list.add(I18n.translateToLocal("clef.item.itemName") + ": " + instrument.info.itemName);
            }
        }
    }
}
 
Example 10
Project: Backmemed   File: StructureStrongholdPieces.java   View source code 6 votes vote down vote up
public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn)
{
    if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn))
    {
        return false;
    }
    else
    {
        this.fillWithRandomizedBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 4, 4, 4, true, randomIn, StructureStrongholdPieces.STRONGHOLD_STONES);
        this.placeDoor(worldIn, randomIn, structureBoundingBoxIn, this.entryDoor, 1, 1, 0);
        EnumFacing enumfacing = this.getCoordBaseMode();

        if (enumfacing != EnumFacing.NORTH && enumfacing != EnumFacing.EAST)
        {
            this.fillWithBlocks(worldIn, structureBoundingBoxIn, 4, 1, 1, 4, 3, 3, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false);
        }
        else
        {
            this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 1, 1, 0, 3, 3, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false);
        }

        return true;
    }
}
 
Example 11
Project: CustomWorldGen   File: WorldGenMegaPineTree.java   View source code 6 votes vote down vote up
private void placePodzolAt(World worldIn, BlockPos pos)
{
    for (int i = 2; i >= -3; --i)
    {
        BlockPos blockpos = pos.up(i);
        IBlockState iblockstate = worldIn.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (block.canSustainPlant(iblockstate, worldIn, blockpos, net.minecraft.util.EnumFacing.UP, ((net.minecraft.block.BlockSapling)Blocks.SAPLING)))
        {
            this.setBlockAndNotifyAdequately(worldIn, blockpos, PODZOL);
            break;
        }

        if (iblockstate.getMaterial() != Material.AIR && i < 0)
        {
            break;
        }
    }
}
 
Example 12
Project: Bewitchment   File: ItemRemedyTalisman.java   View source code 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	if (!world.isRemote) {
		IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
		for (int i = 0; i < baubles.getSlots(); i++)
			if (baubles.getStackInSlot(i).isEmpty() && baubles.isItemValidForSlot(i, player.getHeldItem(hand), player)) {
				baubles.setStackInSlot(i, player.getHeldItem(hand).copy());
				if (!player.capabilities.isCreativeMode) {
					player.setHeldItem(hand, ItemStack.EMPTY);
				}
				onEquipped(player.getHeldItem(hand), player);
				break;
			}
	}
	return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
 
Example 13
Project: BaseClient   File: ItemSlab.java   View source code 6 votes vote down vote up
private boolean tryPlace(ItemStack stack, World worldIn, BlockPos pos, Object variantInStack)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);

    if (iblockstate.getBlock() == this.singleSlab)
    {
        Comparable comparable = iblockstate.getValue(this.singleSlab.getVariantProperty());

        if (comparable == variantInStack)
        {
            IBlockState iblockstate1 = this.doubleSlab.getDefaultState().withProperty((IProperty)this.singleSlab.getVariantProperty(), comparable);

            if (worldIn.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setBlockState(pos, iblockstate1, 3))
            {
                worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.doubleSlab.stepSound.getPlaceSound(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getFrequency() * 0.8F);
                --stack.stackSize;
            }

            return true;
        }
    }

    return false;
}
 
Example 14
Project: Backmemed   File: BlockDispenser.java   View source code 5 votes vote down vote up
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY)
{
    if (worldIn.isRemote)
    {
        return true;
    }
    else
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityDispenser)
        {
            playerIn.displayGUIChest((TileEntityDispenser)tileentity);

            if (tileentity instanceof TileEntityDropper)
            {
                playerIn.addStat(StatList.DROPPER_INSPECTED);
            }
            else
            {
                playerIn.addStat(StatList.DISPENSER_INSPECTED);
            }
        }

        return true;
    }
}
 
Example 15
Project: OpenSensors   File: CommonProxy.java   View source code 5 votes vote down vote up
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	TileEntity te = world.getTileEntity(x, y, z);
	if (te != null && te instanceof TileEntitySensor) {
		TileEntitySensor icte = (TileEntitySensor) te;
		return new SensorContainer(player.inventory, icte);
	} else {
		return null;
	}
}
 
Example 16
Project: BaseClient   File: BlockOre.java   View source code 5 votes vote down vote up
/**
 * Spawns this Block's drops into the World as EntityItems.
 */
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
    super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);

    if (this.getItemDropped(state, worldIn.rand, fortune) != Item.getItemFromBlock(this))
    {
        int i = 0;

        if (this == Blocks.coal_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 0, 2);
        }
        else if (this == Blocks.diamond_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
        }
        else if (this == Blocks.emerald_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 3, 7);
        }
        else if (this == Blocks.lapis_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
        }
        else if (this == Blocks.quartz_ore)
        {
            i = MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);
        }

        this.dropXpOnBlockBreak(worldIn, pos, i);
    }
}
 
Example 17
Project: Backmemed   File: BlockTripWireHook.java   View source code 5 votes vote down vote up
private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
{
    if (!this.canPlaceBlockAt(worldIn, pos))
    {
        this.dropBlockAsItem(worldIn, pos, state, 0);
        worldIn.setBlockToAir(pos);
        return false;
    }
    else
    {
        return true;
    }
}
 
Example 18
Project: Backmemed   File: BlockObserver.java   View source code 5 votes vote down vote up
/**
 * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
 */
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (((Boolean)state.getValue(field_190963_a)).booleanValue() && worldIn.isUpdateScheduled(pos, this))
    {
        this.func_190961_e(worldIn, pos, state.withProperty(field_190963_a, Boolean.valueOf(false)));
    }
}
 
Example 19
Project: BaseClient   File: BiomeGenDesert.java   View source code 5 votes vote down vote up
public void decorate(World worldIn, Random rand, BlockPos pos)
{
    super.decorate(worldIn, rand, pos);

    if (rand.nextInt(1000) == 0)
    {
        int i = rand.nextInt(16) + 8;
        int j = rand.nextInt(16) + 8;
        BlockPos blockpos = worldIn.getHeight(pos.add(i, 0, j)).up();
        (new WorldGenDesertWells()).generate(worldIn, rand, blockpos);
    }
}
 
Example 20
Project: Proyecto-DASI   File: BlockDrawingHelper.java   View source code 5 votes vote down vote up
/**
 * Draw a single Minecraft block.
 * @param b Contains information about the block to be drawn.
 * @param w The world in which to draw.
 * @throws Exception Throws an exception if the block type is not recognised.
 */
private void DrawPrimitive( DrawBlock b, World w ) throws Exception
{
    XMLBlockState blockType = new XMLBlockState(b.getType(), b.getColour(),  b.getFace(), b.getVariant());
    if (!blockType.isValid())
        throw new Exception("Unrecogised item type: " + b.getType().value());
    BlockPos pos = new BlockPos( b.getX(), b.getY(), b.getZ() );
    setBlockState(w, pos, blockType );
}
 
Example 21
Project: ForgeHax   File: AimbotMod.java   View source code 5 votes vote down vote up
/**
 * Finds entity closest to crosshair
 */
public Entity findTargetEntity(Vec3d selfPos, Vec3d selfLookVec, Angle viewAngles) {
    final World world = Minecraft.getMinecraft().world;
    final Vec3d selfLookVecNormal = selfLookVec.normalize();
    Entity target = null;
    double shortestDistance = -1;
    synchronized (world.loadedEntityList) {
        for (Entity entity : Collections.synchronizedList(Lists.newArrayList(world.loadedEntityList))) {
            if(entity != null) {
                Vec3d pos = EntityUtils.getOBBCenter(entity);
                if (isValidTarget(entity, pos, selfPos, selfLookVec, viewAngles)) {
                    double distance = pos
                            .subtract(selfPos)
                            .normalize()
                            .subtract(selfLookVecNormal)
                            .lengthVector();
                    if (shortestDistance == -1 || distance < shortestDistance) {
                        target = entity;
                        shortestDistance = distance;
                    }
                }
            }
        }
    }

    //System.out.printf("Took %d ms\n", System.currentTimeMillis() - start);
    LocalPlayerUtils.setTargetEntity(target);
    return target;
}
 
Example 22
Project: BaseClient   File: StructureMineshaftStart.java   View source code 5 votes vote down vote up
public StructureMineshaftStart(World worldIn, Random rand, int chunkX, int chunkZ)
{
    super(chunkX, chunkZ);
    StructureMineshaftPieces.Room structuremineshaftpieces$room = new StructureMineshaftPieces.Room(0, rand, (chunkX << 4) + 2, (chunkZ << 4) + 2);
    this.components.add(structuremineshaftpieces$room);
    structuremineshaftpieces$room.buildComponent(structuremineshaftpieces$room, this.components, rand);
    this.updateBoundingBox();
    this.markAvailableHeight(worldIn, rand, 10);
}
 
Example 23
Project: Loot-Slash-Conquer   File: EntityProjectileBase.java   View source code 5 votes vote down vote up
/** Only use this constructor if a player shoots the projectile with the correct item. */
public EntityProjectileBase(World world, double x, double y, double z, float velocity, float inaccuracy, EntityPlayer player, ItemStack stack)
{
	super(world, x, y, z);
	this.shoot(x, y, z, velocity, inaccuracy);
	this.player = player;
	this.stack = stack;
}
 
Example 24
Project: BaseClient   File: Block.java   View source code 5 votes vote down vote up
/**
 * Spawns the given amount of experience into the World as XP orb entities
 */
protected void dropXpOnBlockBreak(World worldIn, BlockPos pos, int amount)
{
    if (!worldIn.isRemote)
    {
        while (amount > 0)
        {
            int i = EntityXPOrb.getXPSplit(amount);
            amount -= i;
            worldIn.spawnEntityInWorld(new EntityXPOrb(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, i));
        }
    }
}
 
Example 25
Project: minecraft-quiverbow   File: SoulCairn.java   View source code 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	if (world.isRemote) { return stack; }								// Not doing this on client side
	if (this.getDamage(stack) >= this.getMaxDamage()) { return stack; }	// Is empty

	this.doSingleFire(stack, world, player);	// Handing it over to the neutral firing function
	return stack;
}
 
Example 26
Project: minecraft-quiverbow   File: SugarEngine.java   View source code 5 votes vote down vote up
private void doSpinSFX(ItemStack stack, World world, Entity player)
{
	// SFX
	int spin = stack.stackTagCompound.getInteger("spinning");

	float volume = 0.8F;
	float pitch = 1.8F;

	// Increasing in frequency as we spin up
	if (spin == 1) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }			// +4
	else if (spin == 5) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +4
	else if (spin == 9) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +4

	else if (spin == 13) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +3
	else if (spin == 16) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +3
	else if (spin == 19) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +3

	else if (spin == 21) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +2
	else if (spin == 23) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +2
	else if (spin == 25) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +2

	else if (spin == 27) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +1
	else if (spin == 28) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +1
	else if (spin == 29) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +1

	else if (spin >= 30) { world.playSoundAtEntity(player, "random.wood_click", volume, pitch); }	// +++
}
 
Example 27
Project: ExSartagine   File: BlockRange.java   View source code 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.getTileEntity(pos) instanceof TileEntityRange) || hand == EnumHand.OFF_HAND)
		return false;

	playerIn.openGui(ExSartagine.instance, 3, worldIn, pos.getX(), pos.getY(), pos.getZ());
	return true;
}
 
Example 28
Project: DecompiledMinecraft   File: BlockBrewingStand.java   View source code 5 votes vote down vote up
/**
 * Called by ItemBlocks after a block is set in the world, to allow post-place logic
 */
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
    if (stack.hasDisplayName())
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityBrewingStand)
        {
            ((TileEntityBrewingStand)tileentity).setName(stack.getDisplayName());
        }
    }
}
 
Example 29
Project: BaseClient   File: ItemPotion.java   View source code 5 votes vote down vote up
/**
 * Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
 * the Item before the action is complete.
 */
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn)
{
    if (!playerIn.capabilities.isCreativeMode)
    {
        --stack.stackSize;
    }

    if (!worldIn.isRemote)
    {
        List<PotionEffect> list = this.getEffects(stack);

        if (list != null)
        {
            for (PotionEffect potioneffect : list)
            {
                playerIn.addPotionEffect(new PotionEffect(potioneffect));
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);

    if (!playerIn.capabilities.isCreativeMode)
    {
        if (stack.stackSize <= 0)
        {
            return new ItemStack(Items.glass_bottle);
        }

        playerIn.inventory.addItemStackToInventory(new ItemStack(Items.glass_bottle));
    }

    return stack;
}
 
Example 30
Project: genera   File: BlockBurdockCrop.java   View source code 5 votes vote down vote up
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    super.updateTick(worldIn, pos, state, rand);
    if (!worldIn.isRemote) {
        if (state.getValue(AGE) == 2) {
            EntityFaerie faerie = new EntityFaerie(worldIn, 6.0D, 2, 0.2F, 0);
            faerie.setPosition((double) pos.getX(), (double) pos.up().getY(), (double) pos.getZ());
            worldIn.spawnEntity(faerie);
        }
    }
}
 
Example 31
Project: DecompiledMinecraft   File: ShapelessRecipes.java   View source code 5 votes vote down vote up
/**
 * Used to check if a recipe matches current crafting inventory
 */
public boolean matches(InventoryCrafting inv, World worldIn)
{
    List<ItemStack> list = Lists.newArrayList(this.recipeItems);

    for (int i = 0; i < inv.getHeight(); ++i)
    {
        for (int j = 0; j < inv.getWidth(); ++j)
        {
            ItemStack itemstack = inv.getStackInRowAndColumn(j, i);

            if (itemstack != null)
            {
                boolean flag = false;

                for (ItemStack itemstack1 : list)
                {
                    if (itemstack.getItem() == itemstack1.getItem() && (itemstack1.getMetadata() == 32767 || itemstack.getMetadata() == itemstack1.getMetadata()))
                    {
                        flag = true;
                        list.remove(itemstack1);
                        break;
                    }
                }

                if (!flag)
                {
                    return false;
                }
            }
        }
    }

    return list.isEmpty();
}
 
Example 32
Project: DecompiledMinecraft   File: BlockChest.java   View source code 5 votes vote down vote up
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
    this.checkForSurroundingChests(worldIn, pos, state);

    for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
    {
        BlockPos blockpos = pos.offset(enumfacing);
        IBlockState iblockstate = worldIn.getBlockState(blockpos);

        if (iblockstate.getBlock() == this)
        {
            this.checkForSurroundingChests(worldIn, blockpos, iblockstate);
        }
    }
}
 
Example 33
Project: BaseClient   File: WorldGenFire.java   View source code 5 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    for (int i = 0; i < 64; ++i)
    {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        if (worldIn.isAirBlock(blockpos) && worldIn.getBlockState(blockpos.down()).getBlock() == Blocks.netherrack)
        {
            worldIn.setBlockState(blockpos, Blocks.fire.getDefaultState(), 2);
        }
    }

    return true;
}
 
Example 34
Project: DecompiledMinecraft   File: BlockHopper.java   View source code 5 votes vote down vote up
private void updateState(World worldIn, BlockPos pos, IBlockState state)
{
    boolean flag = !worldIn.isBlockPowered(pos);

    if (flag != ((Boolean)state.getValue(ENABLED)).booleanValue())
    {
        worldIn.setBlockState(pos, state.withProperty(ENABLED, Boolean.valueOf(flag)), 4);
    }
}
 
Example 35
Project: Bewitchment   File: WorldGenOre.java   View source code 5 votes vote down vote up
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
	if (world.provider.getDimensionType().getId() == 0) {
		Set<BiomeDictionary.Type> set = BiomeDictionary.getTypes(world.getBiome(new BlockPos(chunkX, 0, chunkZ)));

		for (BiomeDictionary.Type type : set) {
			if (biomes.isEmpty() || biomes.contains(type)) {
				generateOre(world, random, chunkX, chunkZ);
				break;
			}
		}
	}
}
 
Example 36
Project: CustomWorldGen   File: BlockBeacon.java   View source code 5 votes vote down vote up
public static void updateColorAsync(final World worldIn, final BlockPos glassPos)
{
    HttpUtil.DOWNLOADER_EXECUTOR.submit(new Runnable()
    {
        public void run()
        {
            Chunk chunk = worldIn.getChunkFromBlockCoords(glassPos);

            for (int i = glassPos.getY() - 1; i >= 0; --i)
            {
                final BlockPos blockpos = new BlockPos(glassPos.getX(), i, glassPos.getZ());

                if (!chunk.canSeeSky(blockpos))
                {
                    break;
                }

                IBlockState iblockstate = worldIn.getBlockState(blockpos);

                if (iblockstate.getBlock() == Blocks.BEACON)
                {
                    ((WorldServer)worldIn).addScheduledTask(new Runnable()
                    {
                        public void run()
                        {
                            TileEntity tileentity = worldIn.getTileEntity(blockpos);

                            if (tileentity instanceof TileEntityBeacon)
                            {
                                ((TileEntityBeacon)tileentity).updateBeacon();
                                worldIn.addBlockEvent(blockpos, Blocks.BEACON, 1, 0);
                            }
                        }
                    });
                }
            }
        }
    });
}
 
Example 37
Project: BaseClient   File: BlockSilverfish.java   View source code 5 votes vote down vote up
/**
 * Spawns this Block's drops into the World as EntityItems.
 */
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
    if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"))
    {
        EntitySilverfish entitysilverfish = new EntitySilverfish(worldIn);
        entitysilverfish.setLocationAndAngles((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, 0.0F, 0.0F);
        worldIn.spawnEntityInWorld(entitysilverfish);
        entitysilverfish.spawnExplosionParticle();
    }
}
 
Example 38
Project: Thermionics   File: BlockPotStill.java   View source code 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) {
	if (!world.isRemote) {
		player.openGui(Thermionics.instance(), EnumGui.POT_STILL.id(), world, pos.getX(), pos.getY(), pos.getZ());
	} else {
		
	}
	return true;
}
 
Example 39
Project: DecompiledMinecraft   File: BlockLever.java   View source code 5 votes vote down vote up
private boolean func_181091_e(World p_181091_1_, BlockPos p_181091_2_, IBlockState p_181091_3_)
{
    if (this.canPlaceBlockAt(p_181091_1_, p_181091_2_))
    {
        return true;
    }
    else
    {
        this.dropBlockAsItem(p_181091_1_, p_181091_2_, p_181091_3_, 0);
        p_181091_1_.setBlockToAir(p_181091_2_);
        return false;
    }
}
 
Example 40
Project: BaseClient   File: DemoWorldManager.java   View source code 5 votes vote down vote up
/**
 * Attempts to right-click use an item by the given EntityPlayer in the given World
 */
public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
{
    if (this.demoTimeExpired)
    {
        this.sendDemoReminder();
        return false;
    }
    else
    {
        return super.tryUseItem(player, worldIn, stack);
    }
}