Java Code Examples for net.minecraft.init.Items#STICK

The following examples show how to use net.minecraft.init.Items#STICK . 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: BlockSuperchestPart.java    From YouTubeModdingTutorial with MIT License 6 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 (player.getHeldItem(hand).getItem() == Items.STICK) {
        BlockSuperchest.toggleMultiBlock(world, pos, state, player);
        return true;
    }
    // Only work if the block is formed
    if (state.getBlock() == ModBlocks.blockSuperchestPart && state.getValue(FORMED) != SuperchestPartIndex.UNFORMED) {
        // Find the controller
        BlockPos controllerPos = BlockSuperchest.getControllerPos(world, pos);
        if (controllerPos != null) {
            IBlockState controllerState = world.getBlockState(controllerPos);
            return controllerState.getBlock().onBlockActivated(world, controllerPos, controllerState, player, hand, facing, hitX, hitY, hitZ);
        }
    }
    return false;
}
 
Example 2
Source File: ItemSupply.java    From minecraft-roguelike with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack getLootItem(Random rand, int level) {
	
	if(rand.nextInt(20) == 0) return new ItemStack(Items.CARROT, 1);
	if(rand.nextInt(20) == 0) return new ItemStack(Items.POTATO, 1);

	switch(rand.nextInt(8)){
	case 0: return new ItemStack(Items.WHEAT_SEEDS, rand.nextInt(8) + 1);
	case 1: return new ItemStack(Items.PUMPKIN_SEEDS, rand.nextInt(8) + 1);
	case 2: return new ItemStack(Items.MELON_SEEDS, rand.nextInt(8) + 1);		
	case 3: return new ItemStack(Items.WHEAT, rand.nextInt(8) + 1);
	case 4: return new ItemStack(Blocks.TORCH, 10 + rand.nextInt(10));
	case 5: return new ItemStack(Items.PAPER, rand.nextInt(8) + 1);
	case 6:	return new ItemStack(Items.BOOK, rand.nextInt(4) + 1);
	case 7:	return new ItemStack(Blocks.SAPLING, rand.nextInt(4) + 1, rand.nextInt(4));
	default: return new ItemStack(Items.STICK, 1);
	}
}
 
Example 3
Source File: BlockLogHorizontal.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createFallingEntity(World world, BlockPos pos, IBlockState state)
{
	if(world.rand.nextFloat() < 0.4)
	{
		world.setBlockToAir(pos);
		EntityItem ei = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.STICK, 1+world.rand.nextInt(3)));
		world.spawnEntity(ei);
	}
	else
	{
		int x = 0;
		int z = 0;
		if(world.rand.nextFloat() < 0.25)
		{
			x = -1 + world.rand.nextInt(3);
			z = -1 + world.rand.nextInt(3);
		}
		world.setBlockToAir(pos);
		EntityFallingBlockTFC entityfallingblock = new EntityFallingBlockTFC(world, pos.getX() + 0.5D + x, pos.getY(), pos.getZ() + 0.5D + z, state);
		world.spawnEntity(entityfallingblock);
	}
}
 
Example 4
Source File: BlockLogVertical.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createFallingEntity(World world, BlockPos pos, IBlockState state)
{
	if(world.rand.nextFloat() < 0.4)
	{
		world.setBlockToAir(pos);
		EntityItem ei = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.STICK, 1+world.rand.nextInt(3)));
		world.spawnEntity(ei);
	}
	else
	{
		int x = 0;
		int z = 0;
		if(world.rand.nextFloat() < 0.25)
		{
			x = -1 + world.rand.nextInt(3);
			z = -1 + world.rand.nextInt(3);
		}
		world.setBlockToAir(pos);
		EntityFallingBlockTFC entityfallingblock = new EntityFallingBlockTFC(world, pos.getX() + 0.5D + x, pos.getY(), pos.getZ() + 0.5D + z, state);
		world.spawnEntity(entityfallingblock);
	}
}
 
Example 5
Source File: ItemHelperTests.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void test_getDroppedStacks_range()
{
    BlockDrop drop1 = new BlockDrop(new WrappedItemStackConstant(new ItemStack(Items.APPLE)), IntRange.create(1, 10));
    BlockDrop drop2 = new BlockDrop(new WrappedItemStackConstant(new ItemStack(Items.STICK)), IntRange.create(11, 20));

    List<ItemStack> drops = ItemHelper.getDroppedStacks(new BlockDrop[] {drop1, drop2}, 0);
    ItemStack stack1 = drops.get(0);
    ItemStack stack2 = drops.get(1);

    assertSame(Items.APPLE, stack1.getItem());
    assertTrue(stack1.getCount() >= 1 && stack1.getCount() <= 10);

    assertSame(Items.STICK, stack2.getItem());
    assertTrue(stack2.getCount() >= 11 && stack2.getCount() <= 20);
}
 
Example 6
Source File: ItemHelperTests.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void test_getDroppedStacks_simple()
{
    BlockDrop drop1 = new BlockDrop(new WrappedItemStackConstant(new ItemStack(Items.APPLE)), IntRange.create(1, 1));
    BlockDrop drop2 = new BlockDrop(new WrappedItemStackConstant(new ItemStack(Items.STICK)), IntRange.create(2, 2));

    List<ItemStack> drops = ItemHelper.getDroppedStacks(new BlockDrop[] {drop1, drop2}, 0);
    ItemStack stack1 = drops.get(0);
    ItemStack stack2 = drops.get(1);

    assertSame(Items.APPLE, stack1.getItem());
    assertEquals(1, stack1.getCount());

    assertSame(Items.STICK, stack2.getItem());
    assertEquals(2, stack2.getCount());
}
 
Example 7
Source File: BlockPlanks.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void createFallingEntity(World world, BlockPos pos, IBlockState state)
{
	world.setBlockToAir(pos);
	EntityItem ei = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.STICK, 1+world.rand.nextInt(3)));
	world.spawnEntity(ei);
}
 
Example 8
Source File: BlockWoodSupport.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void createFallingEntity(World world, BlockPos pos, IBlockState state)
{
	world.setBlockToAir(pos);
	EntityItem ei = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.STICK, 1+world.rand.nextInt(3)));
	world.spawnEntity(ei);
}
 
Example 9
Source File: ItemHelperTests.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test_copyStack()
{
    ItemStack stack = new ItemStack(Items.STICK, 2, 0);
    ItemStack copy = ItemHelper.copyStack(stack, 42);

    assertSame(stack.getItem(), copy.getItem());
    assertEquals(42, copy.getCount());
}
 
Example 10
Source File: BlockSuperchest.java    From YouTubeModdingTutorial with MIT License 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 (player.getHeldItem(hand).getItem() == Items.STICK) {
        toggleMultiBlock(world, pos, state, player);
        return true;
    }
    // Only work if the block is formed
    if (state.getBlock() == ModBlocks.blockSuperchest && state.getValue(FORMED) != SuperchestPartIndex.UNFORMED) {
        return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
    } else {
        return false;
    }
}
 
Example 11
Source File: TileEntityEnderFurnace.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't fuel
 * @param stack
 * @return
 */
private static int getItemBurnTime(ItemStack stack)
{
    if (stack.isEmpty())
    {
        return 0;
    }

    int burnTime = ForgeEventFactory.getItemBurnTime(stack) * COOKTIME_DEFAULT * 3 / 400;

    if (burnTime >= 0)
    {
        return burnTime;
    }

    Item item = stack.getItem();

    if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR)
    {
        Block block = Block.getBlockFromItem(item);
        if (block.getDefaultState().getMaterial() == Material.WOOD) { return COOKTIME_DEFAULT * 225 / 100; }
        if (block == Blocks.COAL_BLOCK) { return COOKTIME_DEFAULT * 120; }
        if (block == Blocks.WOODEN_SLAB) { return COOKTIME_DEFAULT * 45 / 40; }
        if (block == Blocks.SAPLING) return COOKTIME_DEFAULT * 3 / 4;
    }
    else
    {
        if (item == Items.COAL) return COOKTIME_DEFAULT * 12;
        if (item == Items.BLAZE_ROD) return COOKTIME_DEFAULT * 18;

        if (item == Items.LAVA_BUCKET) return COOKTIME_DEFAULT * 150;
        if (item == Items.STICK) return COOKTIME_DEFAULT * 3 / 4;
        if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;
        if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;
        if (item instanceof ItemHoe && ((ItemHoe)item).getMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;

        // Ender Furnace custom fuels
        if (item == Items.BLAZE_POWDER) return COOKTIME_DEFAULT * 9;
        if (item == Items.ENDER_PEARL) { return COOKTIME_DEFAULT * 8; }
        if (item == Items.ENDER_EYE) { return COOKTIME_DEFAULT * 17; }
    }

    return 0;
}
 
Example 12
Source File: DungeonFirework.java    From minecraft-roguelike with GNU General Public License v3.0 4 votes vote down vote up
private void launcher(IWorldEditor editor, Random rand, Cardinal dir, Coord pos){
	Coord cursor = new Coord(pos);
	BlockType.get(BlockType.REDSTONE_WIRE).set(editor, cursor);
	cursor.add(Cardinal.reverse(dir));
	BlockType.get(BlockType.REDSTONE_WIRE).set(editor, cursor);
	cursor.add(Cardinal.reverse(dir));
	Repeater.generate(editor, rand, dir, 0, cursor);
	cursor.add(Cardinal.reverse(dir));
	cursor.add(Cardinal.UP);
	
	Dropper dropper = new Dropper();
	dropper.generate(editor, Cardinal.UP, cursor);
	for(int i = 0;i < 8; ++i){
		ItemStack stick = new ItemStack(Items.STICK, 1);
		Loot.setItemName(stick, Integer.toString(i));
		Loot.setItemLore(stick, "Random logic unit", TextFormat.DARKGRAY);
		dropper.add(editor, cursor, i, stick);
	}
	dropper.add(editor, cursor, 8, new ItemStack(Items.WOODEN_HOE));
	
	cursor.add(Cardinal.UP);
	Hopper.generate(editor, Cardinal.DOWN, cursor);
	cursor.add(dir);
	Comparator.generate(editor, rand, dir, false, cursor);
	cursor.add(dir);
	BlockType.get(BlockType.REDSTONE_WIRE).set(editor, cursor);
	cursor.add(dir);
	BlockType.get(BlockType.REDSTONE_WIRE).set(editor, cursor);
	cursor.add(dir);
	
	Coord top = new Coord(pos.getX(), 80, pos.getZ());
	while(top.getY() > pos.getY()){
		top.add(Cardinal.DOWN);
		if(editor.getBlock(top).getMaterial().isSolid()) break;
	}
	
	if(top.getY() >= 100) return;
	
	Coord start = new Coord(cursor);
	start.add(Cardinal.UP);
	

	start.add(dir);
	Coord end = new Coord(start);
	
	MetaBlock breadboard = ColorBlock.get(ColorBlock.CLAY, DyeColor.GREEN);
	
	
	boolean torch = false;
	while(end.getY() < top.getY()){
		if(torch){
			Torch.generate(editor, Torch.REDSTONE, Cardinal.UP, cursor);
		} else {
			breadboard.set(editor, cursor);
		}
		torch = !torch;
		cursor.add(Cardinal.UP);
		end.add(Cardinal.UP);
	}
	
	if(torch){
		cursor.add(Cardinal.DOWN);
	}
	
	Dispenser.generate(editor, Cardinal.UP, cursor);
	for(int i = 0; i < 9; i++){
		Dispenser.add(editor, cursor, i, Firework.get(rand, 16 + rand.nextInt(16)));
	}
	
	cursor.add(Cardinal.UP);
	MetaBlock cob = BlockType.get(BlockType.COBBLESTONE);
	RectSolid.fill(editor, rand, start, end, cob, true, true);
	start.add(Cardinal.reverse(dir), 2);
	end.add(Cardinal.reverse(dir), 2);
	RectSolid.fill(editor, rand, start, end, cob, true, true);
	start.add(dir);
	end.add(dir);
	Coord above = new Coord(end);
	above.add(Cardinal.UP, 10);
	MetaBlock air = BlockType.get(BlockType.AIR);
	for(Coord c : new RectSolid(cursor, above)){
		if(editor.getBlock(c).getMaterial().isSolid()){
			air.set(editor, c);
		}
	}
	start.add(Cardinal.left(dir));
	end.add(Cardinal.left(dir));
	RectSolid.fill(editor, rand, start, end, cob, true, true);
	start.add(Cardinal.right(dir), 2);
	end.add(Cardinal.right(dir), 2);
	RectSolid.fill(editor, rand, start, end, cob, true, true);
}
 
Example 13
Source File: ItemJunk.java    From minecraft-roguelike with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack getLootItem(Random rand, int level){

	if(level > 0 && rand.nextInt(200) == 0){
		if(level > 2 && rand.nextInt(10) == 0) return new ItemStack(Items.DIAMOND_HORSE_ARMOR, 1, 0);
		if(level > 1 && rand.nextInt(5) == 0) return new ItemStack(Items.GOLDEN_HORSE_ARMOR, 1, 0);
		if(rand.nextInt(3) == 0) return new ItemStack(Items.IRON_HORSE_ARMOR, 1, 0);
		return new ItemStack(Items.SADDLE);
	}

	if(rand.nextInt(100) == 0) return PotionMixture.getRandom(rand);
	
	if(level > 1 && rand.nextInt(100) == 0) return new ItemStack(Items.GHAST_TEAR);

	if(level < 3 && rand.nextInt(80) == 0) return new ItemStack(Items.BOOK);
	
	if(rand.nextInt(80) == 0) return Shield.get(rand);
	
	if(level > 1 && rand.nextInt(60) == 0) return TippedArrow.get(rand, 4 + rand.nextInt(level) * 2);
	
	if(level > 1 && rand.nextInt(50) == 0){			
		switch(rand.nextInt(6)){
		case 0: return new ItemStack(Items.GUNPOWDER, 1 + rand.nextInt(3));
		case 1: return new ItemStack(Items.BLAZE_POWDER, 1 + rand.nextInt(3));
		case 2: return new ItemStack(Items.GOLD_NUGGET, 1 + rand.nextInt(3));
		case 3: return new ItemStack(Items.REDSTONE, 1 + rand.nextInt(3));
		case 4: return new ItemStack(Items.GLOWSTONE_DUST, 1 + rand.nextInt(8));
		case 5: return new ItemStack(Items.DYE, 1 + rand.nextInt(3));
		}
	}

	if(rand.nextInt(60) == 0) return PotionMixture.getPotion(rand, PotionMixture.LAUDANUM);
	
	if(rand.nextInt(30) == 0) return new ItemStack(Blocks.TORCH, 6 + rand.nextInt(20));

	if(level > 0 && rand.nextInt(8) == 0){
		switch(rand.nextInt(8)){
		case 0: return new ItemStack(Items.SLIME_BALL);
		case 1: return new ItemStack(Items.SNOWBALL);
		case 2: return new ItemStack(Items.MUSHROOM_STEW);
		case 3: return new ItemStack(Items.CLAY_BALL);
		case 4: return new ItemStack(Items.FLINT);
		case 5: return new ItemStack(Items.FEATHER);
		case 6: return new ItemStack(Items.GLASS_BOTTLE);
		case 7: return new ItemStack(Items.LEATHER);
		}
	}

	switch(rand.nextInt(7)){
	case 0: return new ItemStack(Items.BONE);
	case 1: return new ItemStack(Items.ROTTEN_FLESH);
	case 2: return new ItemStack(Items.SPIDER_EYE);
	case 3: return new ItemStack(Items.PAPER);
	case 4: return new ItemStack(Items.STRING);
	case 5: return new ItemStack(Items.STICK);
	default: return new ItemStack(Items.STICK);
	}
}
 
Example 14
Source File: SettingsResolverTest.java    From minecraft-roguelike with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void ResolveInheritTwoLevel() throws Exception{
	
	DungeonSettings main = new DungeonSettings();
	DungeonSettings child = new DungeonSettings();
	DungeonSettings grandchild = new DungeonSettings();
	
	SettingsContainer settings = new SettingsContainer();
	
	main.id = new SettingIdentifier("main");
	child.id = new SettingIdentifier("child");
	grandchild.id = new SettingIdentifier("grandchild");
	settings.put(main);
	settings.put(child);
	settings.put(grandchild);
	
	main.inherit.add(child.id);
	child.inherit.add(grandchild.id);
	
	ItemStack stick = new ItemStack(Items.STICK);
	ItemStack diamond = new ItemStack(Items.DIAMOND);
	
	child.lootRules.add(Treasure.REWARD, new WeightedChoice<ItemStack>(stick , 1), 0, true, 1);
	grandchild.lootRules.add(Treasure.REWARD, new WeightedChoice<ItemStack>(diamond , 1), 0, true, 1);
	
	DungeonSettings assembled = SettingsResolver.processInheritance(main, settings);
	
	TreasureManager treasure = new TreasureManager();
	MockChest chest = new MockChest(Treasure.REWARD, 0);
	treasure.add(chest);
	
	assertTrue(chest.count(stick) == 0);
	assertTrue(chest.count(diamond) == 0);
	
	assembled.lootRules.process(new Random(), treasure);
	
	assertTrue(chest.count(stick) == 1);
	assertTrue(chest.count(new ItemStack(Items.BOAT)) == 0);
	assertTrue(chest.count(diamond) == 1);

}
 
Example 15
Source File: SettingsResolverTest.java    From minecraft-roguelike with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void ResolveInheritTwoLevelMultiple() throws Exception{
	DungeonSettings main = new DungeonSettings();
	DungeonSettings child = new DungeonSettings();
	DungeonSettings sibling = new DungeonSettings();
	DungeonSettings grandchild = new DungeonSettings();
	
	SettingsContainer settings = new SettingsContainer();
	
	main.id = new SettingIdentifier("main");
	child.id = new SettingIdentifier("child");
	sibling.id = new SettingIdentifier("sibling");
	grandchild.id = new SettingIdentifier("grandchild");
	settings.put(main);
	settings.put(child);
	settings.put(sibling);
	settings.put(grandchild);
	
	main.inherit.add(child.id);
	main.inherit.add(sibling.id);
	child.inherit.add(grandchild.id);
	
	ItemStack stick = new ItemStack(Items.STICK);
	ItemStack coal = new ItemStack(Items.COAL);
	ItemStack diamond = new ItemStack(Items.DIAMOND);
	
	child.lootRules.add(Treasure.REWARD, new WeightedChoice<ItemStack>(stick , 1), 0, true, 1);
	sibling.lootRules.add(Treasure.REWARD, new WeightedChoice<ItemStack>(coal , 1), 0, true, 1);
	grandchild.lootRules.add(Treasure.REWARD, new WeightedChoice<ItemStack>(diamond , 1), 0, true, 1);
	
	DungeonSettings assembled = SettingsResolver.processInheritance(main, settings);
	
	TreasureManager treasure = new TreasureManager();
	MockChest chest = new MockChest(Treasure.REWARD, 0);
	treasure.add(chest);
	
	assertTrue(chest.count(stick) == 0);
	assertTrue(chest.count(coal) == 0);
	assertTrue(chest.count(diamond) == 0);
	
	assembled.lootRules.process(new Random(), treasure);
	
	assertTrue(chest.count(new ItemStack(Items.BOAT)) == 0);
	assertTrue(chest.count(coal) == 1);
	assertTrue(chest.count(stick) == 1);
	assertTrue(chest.count(diamond) == 1);
	
}
 
Example 16
Source File: SettingsResolverTest.java    From minecraft-roguelike with GNU General Public License v3.0 3 votes vote down vote up
@Test
public void ResolveInheritOneLevel() throws Exception {
	
	DungeonSettings main = new DungeonSettings();
	DungeonSettings toInherit = new DungeonSettings();
	
	SettingsContainer settings = new SettingsContainer();
	
	main.id = new SettingIdentifier("main");
	toInherit.id = new SettingIdentifier("inherit");
	settings.put(main);
	settings.put(toInherit);
	
	main.inherit.add(toInherit.id);
	
	ItemStack stick = new ItemStack(Items.STICK);
	
	toInherit.lootRules.add(Treasure.REWARD, new WeightedChoice<ItemStack>(stick , 1), 0, true, 1);
	
	DungeonSettings assembled = SettingsResolver.processInheritance(main, settings);
	
	TreasureManager treasure = new TreasureManager();
	MockChest chest = new MockChest(Treasure.REWARD, 0);
	treasure.add(chest);
	
	assertTrue(chest.count(stick) == 0);
	
	assembled.lootRules.process(new Random(), treasure);
	
	assertTrue(chest.count(stick) == 1);
	
	
}
 
Example 17
Source File: TreasureManagerTest.java    From minecraft-roguelike with GNU General Public License v3.0 3 votes vote down vote up
@Test
public void addItem() {
	
	Random rand = new Random();
	WeightedChoice<ItemStack> stick = new WeightedChoice<ItemStack>(new ItemStack(Items.STICK), 1);
	WeightedRandomizer<ItemStack> loot = new WeightedRandomizer<ItemStack>();
	loot.add(stick);
	
	TreasureManager treasure = new TreasureManager();		
	MockChest toAdd = new MockChest(Treasure.ARMOUR, 0);
	treasure.add(toAdd);
	treasure.addItem(rand, Treasure.ARMOUR, 0, loot, 1);
	
	treasure.addItem(rand, Treasure.ARMOUR, 1, loot, 1);
	
	treasure.addItem(rand, Treasure.WEAPONS, 0, loot, 1);
	
	treasure.addItem(rand, Treasure.WEAPONS, 1, loot, 1);
	
	treasure.addItem(rand, Treasure.ARMOUR, loot, 1);
	
	treasure.addItem(rand, Treasure.WEAPONS, loot, 1);
	
	treasure.addItem(rand, 0, loot, 1);
	
	treasure.addItem(rand, 1, loot, 1);
	
}