Java Code Examples for net.minecraft.entity.player.EntityPlayer.isCreative()

The following are Jave code examples for showing how to use isCreative() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pnc-repressurized   File: BlockPneumaticCraft.java   View Source Code Vote up 6 votes
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
    if (player.isCreative()) {
        if (!world.isRemote) {
            // Drop any contained items here (but don't drop the block itself as an item; this is creative mode)
            TileEntity te = world.getTileEntity(pos);
            if (te instanceof TileEntityBase) {
                NonNullList<ItemStack> drops = NonNullList.create();
                ((TileEntityBase) te).getAllDrops(drops);
                drops.forEach(stack -> PneumaticCraftUtils.dropItemOnGround(stack, world, pos.getX(), pos.getY(), pos.getZ()));
            }
        }
        return super.removedByPlayer(state, world, pos, player, false);
    } else {
        // This delays harvesting until after getDrops() is called, giving getDrops() a chance to serialize any TE
        // data onto the itemstack.  harvestBlock() must also be overridden to remove the block (see below)
        return willHarvest || super.removedByPlayer(state, world, pos, player, false);
    }
}
 
Example 2
Project: Bewitchment   File: ItemRitualChalk.java   View Source Code Vote up 6 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	boolean isReplacing = worldIn.getBlockState(pos).getBlock().equals(ModBlocks.ritual_glyphs) && worldIn.getBlockState(pos).getValue(BlockCircleGlyph.TYPE) != GlyphType.GOLDEN;
	if (!worldIn.isRemote && (facing == EnumFacing.UP && ModBlocks.ritual_glyphs.canPlaceBlockAt(worldIn, pos.up()) || isReplacing)) {
		ItemStack chalk = player.getHeldItem(hand);
		if (!chalk.hasTagCompound()) {
			chalk.setTagCompound(new NBTTagCompound());
			chalk.getTagCompound().setInteger("usesLeft", MAX_USES);
		}
		int type = chalk.getItemDamage();
		if (!player.isCreative()) {
			int usesLeft = chalk.getTagCompound().getInteger("usesLeft") - 1;
			chalk.getTagCompound().setInteger("usesLeft", usesLeft);
			if (usesLeft < 1) chalk.setCount(0);
		}
		IBlockState state = ModBlocks.ritual_glyphs.getExtendedState(ModBlocks.ritual_glyphs.getDefaultState(), worldIn, pos);
		state = state.withProperty(BlockCircleGlyph.FACING, EnumFacing.HORIZONTALS[(int) (Math.random() * 4)]);
		state = state.withProperty(BlockCircleGlyph.TYPE, BlockCircleGlyph.GlyphType.values()[type]);
		worldIn.setBlockState(isReplacing ? pos : pos.up(), state, 2);
		worldIn.playSound(null, pos, WitchSoundEvents.CHALK_SCRIBBLE, SoundCategory.BLOCKS, 0.5f, 1f + 0.5f * player.getRNG().nextFloat());
	}
	return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
 
Example 3
Project: Mods   File: EntityTF2Character.java   View Source Code Vote up 6 votes
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand) {
	if (!(player.getHeldItemMainhand() != null
			&& player.getHeldItemMainhand().getItem() instanceof ItemMonsterPlacerPlus)
			&& (this.getOwner() == player || this.getAttackTarget() == null || this.friendly) && this.isEntityAlive() && !this.isTrading()
			&& !this.isChild() && !player.isSneaking()) {
		if (this.world.isRemote && player.getTeam() == null
				&& ((this.getCapability(TF2weapons.WEAPONS_CAP, null).state & 1) == 0 || this.friendly)
				&& !player.isCreative())
			ClientProxy.displayScreenConfirm("Choose a team to interact",
					"Visit the Mann Co. Store located in a village");
		if (!this.world.isRemote && (TF2Util.isOnSameTeam(this, player) || player.isCreative())
				&& (this.tradeOffers == null || !this.tradeOffers.isEmpty())) {
			this.setCustomer(player);
			FMLNetworkHandler.openGui(player, TF2weapons.instance, 4, world, this.getEntityId(), 0, 0);
		}

		player.addStat(StatList.TALKED_TO_VILLAGER);
		return true;
	} else
		return super.processInteract(player, hand);
}
 
Example 4
Project: Mods   File: EntitySaxtonHale.java   View Source Code Vote up 6 votes
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand) {
	if (!(player.getHeldItemMainhand() != null
			&& player.getHeldItemMainhand().getItem() instanceof ItemMonsterPlacerPlus)
			&& this.getAttackTarget() == null && this.isEntityAlive() && !this.isTrading() && !this.isChild()
			&& !player.isSneaking()) {
		if (this.world.isRemote && player.getTeam() == null && !player.isCreative())
			ClientProxy.displayScreenJoinTeam();
		else if (!this.world.isRemote && (player.getTeam() != null || player.isCreative())
				&& (this.tradeOffers == null || !this.tradeOffers.isEmpty())) {
			this.setCustomer(player);
			player.displayVillagerTradeGui(this);
		}

		player.addStat(StatList.TALKED_TO_VILLAGER);
		return true;
	} else
		return super.processInteract(player, hand);
}
 
Example 5
Project: ModularMachinery   File: ItemConstructTool.java   View Source Code Vote up 6 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if(!worldIn.isRemote && player.isCreative() && worldIn.getMinecraftServer().getPlayerList().canSendCommands(player.getGameProfile())) {
        IBlockState clicked = worldIn.getBlockState(pos);
        Block block = clicked.getBlock();
        if(block.equals(BlocksMM.blockController)) {
            PlayerStructureSelectionHelper.finalizeSelection(clicked.getValue(BlockController.FACING), worldIn, pos, player);

            PlayerStructureSelectionHelper.purgeSelection(player);
            PlayerStructureSelectionHelper.sendSelection(player);
        } else {
            PlayerStructureSelectionHelper.toggleInSelection(player, pos);
            PlayerStructureSelectionHelper.sendSelection(player);
        }
    }
    return EnumActionResult.SUCCESS;
}
 
Example 6
Project: Bewitchment   File: RitualDrawing.java   View Source Code Vote up 5 votes
@Override
public void onStarted(EntityPlayer player, IRitualHandler tile, World world, BlockPos pos, NBTTagCompound data) {
	ItemStack chalk = player.getHeldItemOffhand();
	data.setInteger("chalkType", chalk.getMetadata());
	if (!player.isCreative()) {
		int usesLeft = chalk.getTagCompound().getInteger("usesLeft") - coords.size();
		chalk.getTagCompound().setInteger("usesLeft", usesLeft);
		if (usesLeft < 1)
			chalk.setCount(0);
	}
	player.setHeldItem(EnumHand.OFF_HAND, chalk);
}
 
Example 7
Project: Bewitchment   File: RitualDrawing.java   View Source Code Vote up 5 votes
@Override
public boolean isValid(EntityPlayer player, World world, BlockPos pos, List<ItemStack> recipe) {
	for (int[] rc : coords) {
		BlockPos pos2 = pos.add(rc[0], 0, rc[1]);
		if (!world.isAirBlock(pos2) && !world.getBlockState(pos2).getBlock().isReplaceable(world, pos2) && world.getBlockState(pos2).getBlock() != ModBlocks.ritual_glyphs)
			return false;
	}

	return player.getHeldItemOffhand().getItem() == ModItems.ritual_chalk && player.getHeldItemOffhand().getMetadata() != 1 && (player.isCreative() || player.getHeldItemOffhand().getTagCompound().getInteger("usesLeft") >= coords.size());
}
 
Example 8
Project: EndermanEvolution   File: IronChests.java   View Source Code Vote up 5 votes
public static boolean canPlayerSilkHarvestChest(TileEntity te, EntityPlayer player) {
	if (!Mods.IRONCHESTS.isLoaded()) {
		return false;
	}
	BlockPos pos = te.getPos();
	Block block = te.getWorld() == null ? null : te.getWorld().getBlockState(pos).getBlock();
	return te != null && block != null && isIronChest(block) && player != null && player.getHeldItemMainhand() != null && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0 && !player.isCreative();
}
 
Example 9
Project: SimpleTubes   File: ItemUpgrade.java   View Source Code Vote up 5 votes
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {

	if (!world.isRemote) {

		ItemStack held = player.getHeldItem(hand);

		if (player.isSneaking())
			return EnumActionResult.PASS;

		if (held != ItemStack.EMPTY && held.getItem() instanceof ItemUpgrade) {

			if (held.getMetadata() == 0) {

				IBlockState state = world.getBlockState(pos);
				if (state.getBlock() instanceof BlockDisplacer)
					if (!state.getValue(BlockDisplacer.FILTER)) {
						state = state.withProperty(BlockDisplacer.FILTER, true);

						if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TileDisplacer) {
							if (!((TileDisplacer) world.getTileEntity(pos)).hasFilter()) {
								((TileDisplacer) world.getTileEntity(pos)).setHasFilter(true);
								((TileDisplacer) world.getTileEntity(pos)).markDirty();

								PacketHandler.sendToAll(new PacketDisplacerSync(((TileDisplacer) world.getTileEntity(pos)), true));
							}
						}
					}
				world.setBlockState(pos, state, 3);
				world.notifyBlockUpdate(pos, state, state, 3);

				if (!player.isCreative())
					player.getHeldItem(hand).splitStack(1);
			}
			return EnumActionResult.SUCCESS;
		}
	}

	return EnumActionResult.PASS;
}
 
Example 10
Project: SimpleTubes   File: BlockDisplacer.java   View Source Code Vote up 5 votes
@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) {

		ItemStack held = player.getHeldItem(hand);

		if (player.isSneaking()) {

			if (state.getValue(FILTER) && ((TileDisplacer) world.getTileEntity(pos)).hasFilter()) {
				state = state.withProperty(FILTER, false);
				world.setBlockState(pos, state);

				if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TileDisplacer) {
					((TileDisplacer) world.getTileEntity(pos)).setHasFilter(false);
					((TileDisplacer) world.getTileEntity(pos)).markDirty();

					PacketHandler.sendToAll(new PacketDisplacerSync(((TileDisplacer) world.getTileEntity(pos)), false));
					if (!player.isCreative())
						InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(SimpleTubes.proxy.itemUpgrade, 1, 0));
				}
			}
			return true;
		} else {
			if (!(held.getItem() instanceof ItemUpgrade) || held == ItemStack.EMPTY) {
				if (((TileDisplacer) world.getTileEntity(pos)).hasFilter()) {
					player.openGui(SimpleTubes.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
					return true;
				}
			}
		}
	}

	return true;
}
 
Example 11
Project: Mods   File: ItemHorn.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	ItemStack itemStackIn = playerIn.getHeldItem(hand);
	ItemStack backpack = getBackpack(playerIn);
	if (!backpack.isEmpty() && (backpack.getTagCompound().getFloat("Rage") >= 1 || playerIn.isCreative())) {
		playerIn.setActiveHand(hand);
		if (TF2Util.getTeamForDisplay(playerIn) == 1)
			playerIn.playSound(ItemFromData.getSound(backpack, PropertyType.HORN_BLU_SOUND), 0.8f, 1f);
		else
			playerIn.playSound(ItemFromData.getSound(backpack, PropertyType.HORN_RED_SOUND), 0.8f, 1f);
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
	}
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
}
 
Example 12
Project: Mods   File: ItemSoldierBackpack.java   View Source Code Vote up 5 votes
@Override
public void onArmorTick(World world, final EntityPlayer player, ItemStack itemStack) {
	if (!world.isRemote) {
		if (player.ticksExisted % 20 == 0) {
			float heal = TF2Attribute.getModifier("Health Regen", itemStack, 0, player);
			if(heal > 0) {
				int lastHitTime = player.ticksExisted - player.getEntityData().getInteger("lasthit");
				if (lastHitTime >= 120)
					player.heal(heal);
				else if(lastHitTime >= 60)
					player.heal(TF2Util.lerp(heal, heal/4f, (lastHitTime-60)/60f));
				else
					player.heal(heal/4f);
			}
		}
		if (player.ticksExisted % 5 == 0 && itemStack.getTagCompound().getBoolean("Active")) {
			itemStack.getTagCompound().setFloat("Rage",
					Math.max(0,
							itemStack.getTagCompound().getFloat("Rage")
									- 1 / (TF2Attribute.getModifier("Buff Duration", itemStack,
											getData(itemStack).getInt(PropertyType.DURATION), player) - 20)));
			if (itemStack.getTagCompound().getFloat("Rage") <= 0)
				itemStack.getTagCompound().setBoolean("Active", false);
			for (EntityLivingBase living : world.getEntitiesWithinAABB(EntityLivingBase.class,
					player.getEntityBoundingBox().grow(10, 10, 10), new Predicate<EntityLivingBase>() {

						@Override
						public boolean apply(EntityLivingBase input) {
							// TODO Auto-generated method stub
							return TF2Util.isOnSameTeam(player, input);
						}

					}))
				living.addPotionEffect(new PotionEffect(this.getBuff(itemStack), 25));

		}
		if (player.isCreative())
			itemStack.getTagCompound().setFloat("Rage", 1);
	}
}
 
Example 13
Project: AdvancedCombat   File: SwordCreative.java   View Source Code Vote up 5 votes
@Override
  public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
if(!player.isCreative()) return super.onLeftClickEntity(stack, player, entity);
if(entity instanceof EntityLivingBase) ((EntityLivingBase)entity).onDeath(DamageSource.causePlayerDamage(player));
entity.setDead(); // bypasses all invulerabilities
  	return false; // bypass the damaging mechanic
  }
 
Example 14
Project: Never-Enough-Currency   File: SlotArmor.java   View Source Code Vote up 4 votes
/**
 * Return whether this slot's stack can be taken from this slot.
 */
@Override
public boolean canTakeStack(EntityPlayer playerIn) {
	ItemStack itemstack = this.getStack();
	return itemstack != ItemStack.EMPTY && !playerIn.isCreative() ? false : super.canTakeStack(playerIn);
}
 
Example 15
Project: EndermanEvolution   File: ChestUtils.java   View Source Code Vote up 4 votes
public static boolean canPlayerSilkHarvestChest(TileEntity te, EntityPlayer player) {
	BlockPos pos = te.getPos();
	Block block = te.getWorld() == null ? null : te.getWorld().getBlockState(pos).getBlock();
	return te != null && block != null && ChestUtils.isVanillaChest(block, false) && player != null && player.getHeldItemMainhand() != null && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0 && !player.isCreative();
}