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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#isCreative() . 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: BlockInfestedLeaves.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@Override
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
	if (!world.isRemote && !player.isCreative()) {
		TileEntity tile = world.getTileEntity(pos);

		if (tile != null) {
			if (tile instanceof TileInfestedLeaves) {
				TileInfestedLeaves leaves = (TileInfestedLeaves) tile;

				if (leaves != null && player.getHeldItemMainhand() != null
						&& player.getHeldItemMainhand().getItem() instanceof ICrook) {
					if (world.rand.nextFloat() < leaves.getProgress() * Config.stringChance) {
						Util.dropItemInWorld(leaves, player, new ItemStack(Items.STRING, 1, 0), 0.02f);
					}

					if (world.rand.nextFloat() < leaves.getProgress() * Config.stringChance / 4.0d) {
						Util.dropItemInWorld(leaves, player, new ItemStack(Items.STRING, 1, 0), 0.02f);
					}
				}
			}

			world.removeTileEntity(pos);
		}
	}
}
 
Example 2
Source File: WorldEventsCommon.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SubscribeEvent
public void playerTick(PlayerTickEvent event) {
    if (event.phase == Phase.START) {
        EntityPlayer player = event.player;
        //TODO: fix the fall damage
        // @thebest108: what fall damage?
        //                    --DaPorkchop_, 28/03/2017
        if (VSConfig.doValkyriumLifting && !player.isCreative()) {
            for (NonNullList<ItemStack> stackArray : player.inventory.allInventories) {
                for (ItemStack stack : stackArray) {
                    if (stack != null) {
                        if (stack.getItem() instanceof ItemBlock) {
                            ItemBlock blockItem = (ItemBlock) stack.getItem();
                            if (blockItem.getBlock() instanceof BlockValkyriumOre) {
                                player.addVelocity(0, .0025D * stack.stackSize * VSConfig.valkyriumOreForce, 0);
                            }
                        } else if (stack.getItem() instanceof ItemValkyriumCrystal) {
                            player.addVelocity(0, .0025D * stack.stackSize * VSConfig.valkyriumCrystalForce, 0);
                        }
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: ItemComponentBox.java    From Cyberware with MIT License 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	if (playerIn.isSneaking())
	{
		EnumActionResult res = super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
		if (res == EnumActionResult.SUCCESS && playerIn.isCreative())
		{
			playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
		}
		return res;
	}
	else
	{
		playerIn.openGui(Cyberware.INSTANCE, 6, worldIn, 0, 0, 0);
	}
	return EnumActionResult.SUCCESS;
}
 
Example 4
Source File: ItemCybereyes.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void overlayPre(RenderGameOverlayEvent.Pre event)
{
	if (event.getType() == ElementType.ALL)
	{
		EntityPlayer e = Minecraft.getMinecraft().thePlayer;
		
		if (isBlind && !e.isCreative())
		{
			GlStateManager.pushMatrix();
			GlStateManager.enableBlend();
			GlStateManager.color(1F, 1F, 1F, .9F);
			Minecraft.getMinecraft().getTextureManager().bindTexture(EssentialsMissingHandler.BLACK_PX);
			ClientUtils.drawTexturedModalRect(0, 0, 0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
			GlStateManager.popMatrix();
		}
	}
}
 
Example 5
Source File: TileEntityCrop.java    From AgriCraft with MIT License 6 votes vote down vote up
@Override
@Nonnull
public MethodResult onBroken(@Nonnull Consumer<ItemStack> consumer, @Nullable EntityPlayer player) {
    // Verify the consumer is not null.
    Preconditions.checkNotNull(consumer);

    // If on client side do nothing!
    if (this.isRemote()) {
        return MethodResult.PASS;
    }

    // Drop drops if should drop.
    if (player == null || !player.isCreative()) {
        this.getDrops(consumer, true, true, true);
    }

    // Remove the block.
    this.getWorld().removeTileEntity(pos);
    this.getWorld().setBlockToAir(pos);

    // The operation was a success.
    return MethodResult.SUCCESS;
}
 
Example 6
Source File: GTItemDestructoPack.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
	if (playerIn.isSneaking() && playerIn.isCreative()) {
		for (int i = 0; i < playerIn.inventory.getSizeInventory(); i++) {
			Item item = playerIn.inventory.getStackInSlot(i).getItem();
			if (!(item instanceof GTItemDestructoPack || item instanceof GTItemCreativeScanner
					|| item instanceof GTItemSurvivalScanner || item instanceof GTItemMagnifyingGlass)) {
				playerIn.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
			}
		}
		return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
	}
	if (IC2.platform.isSimulating()) {
		IC2.platform.launchGui(playerIn, this.getInventory(playerIn, handIn, playerIn.getHeldItem(handIn)), handIn);
	}
	return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
 
Example 7
Source File: BlockCreativeManaBattery.java    From Wizardry with GNU Lesser General Public License v3.0 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 (playerIn.isCreative() && playerIn.isSneaking()) {
		buildStructure(worldIn, pos);
	} else {
		TileEntity tile = worldIn.getTileEntity(pos);
		if (!(tile instanceof TileManaBattery)) return false;
		else {
			((TileManaBattery) tile).revealStructure = !((TileManaBattery) tile).revealStructure;
			tile.markDirty();
		}
	}
	return true;
}
 
Example 8
Source File: EntityLivingHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public void updateThirst(NBTTagCompound tfcData, IFoodStatsTFC food, EntityPlayer player)
{
	double temp = WeatherManager.getInstance().getTemperature(player.getPosition());
	if(player.isCreative())
		return;
	float thirst = 0.28f;
	if(temp > 20)
	{
		temp -= 20;
		thirst += thirst * (temp / 0.35);
	}
	food.setWaterLevel(Math.max(food.getWaterLevel()-thirst, 0));
}
 
Example 9
Source File: BlockManaBattery.java    From Wizardry with GNU Lesser General Public License v3.0 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 (playerIn.isCreative() && playerIn.isSneaking()) {
		buildStructure(worldIn, pos);
	} else {
		TileManaBattery tile = (TileManaBattery) worldIn.getTileEntity(pos);
		if (tile == null) return false;

		tile.revealStructure = !tile.revealStructure;
		tile.markDirty();
	}
	return true;
}
 
Example 10
Source File: DrinkSoymilkRamune.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(true)||playerIn.isCreative())
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 11
Source File: ItemJar.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);
	if (stack.getItemDamage() != 1) {
		BlockPos offset = pos.offset(side);
		IBlockState offsetState = world.getBlockState(offset);
		if (offsetState.getBlock().isAir(offsetState, world, offset) || offsetState.getBlock().isReplaceable(world, offset)) {

			if (!world.mayPlace(ModBlocks.JAR, offset, false, side, player)) return PASS;

			boolean replacable = world.getBlockState(pos).getBlock().isReplaceable(world, pos);
			boolean success = world.setBlockState(replacable ? pos : offset, ModBlocks.JAR.getDefaultState());
			if (success) {
				world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1, 1, false);

				if (!player.isCreative())
					stack.shrink(1);

				TileEntity tileEntity = world.getTileEntity(replacable ? pos : offset);
				if (tileEntity instanceof TileJar) {
					TileJar jar = (TileJar) tileEntity;
					jar.fairy = FairyData.deserialize(NBTHelper.getCompound(stack, "fairy"));
					jar.markDirty();
					world.checkLight(replacable ? pos : offset);
				}
			}

			return SUCCESS;
		}
	}
	return PASS;
}
 
Example 12
Source File: BlockPepperSplint.java    From Sakura_mod 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) {
	ItemStack heldSeed = playerIn.getHeldItem(hand);
	if(worldIn.isRemote) return true;
	if(ItemStack.areItemsEqual(heldSeed, new ItemStack(ItemLoader.MATERIAL, 1, 19))){
		worldIn.setBlockState(pos, BlockLoader.PEPPERCROP.getDefaultState().withProperty(BlockPepperCrop.AGE, 0));
		if(!playerIn.isCreative())heldSeed.shrink(1);
		return true;
	}
	return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 13
Source File: BlockGrapeSplintStand.java    From Sakura_mod 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) {
	ItemStack heldSeed = playerIn.getHeldItem(hand);
	if(worldIn.isRemote) return true;
	if(ItemStack.areItemsEqual(heldSeed, new ItemStack(ItemLoader.MATERIAL, 1, 23))){
		worldIn.setBlockState(pos, BlockLoader.GRAPE_VINE.getDefaultState().withProperty(BlockVanillaCrop.AGE, 0));
		if(!playerIn.isCreative())heldSeed.shrink(1);
		return true;
	}
	return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 14
Source File: ItemAxe.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	//ItemStack stack = playerIn.getHeldItem(hand);
	if(worldIn.isRemote || !playerIn.capabilities.isCreativeMode)
		return EnumActionResult.FAIL;
	IBlockState state = worldIn.getBlockState(pos);
	if(playerIn.isCreative() && state.getBlock() == TFCBlocks.Sapling)
		((BlockSapling)state.getBlock()).grow(worldIn, worldIn.rand, pos, state);
	if(playerIn.isCreative() && state.getBlock() == TFCBlocks.Sapling2)
		((BlockSapling2)state.getBlock()).grow(worldIn, worldIn.rand, pos, state);

	return EnumActionResult.SUCCESS;
}
 
Example 15
Source File: Hydroponic.java    From EmergingTechnology with MIT License 4 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;
    }

    HydroponicTileEntity tileEntity = (HydroponicTileEntity) worldIn.getTileEntity(pos);
    ItemStack itemStackHeld = playerIn.getHeldItemMainhand();
    Item itemHeld = itemStackHeld.getItem();

    if (itemHeld == Items.WATER_BUCKET || itemHeld == Items.LAVA_BUCKET) {

        Fluid fluid = itemHeld == Items.WATER_BUCKET ? FluidRegistry.WATER : FluidRegistry.LAVA;

        int waterFilled = tileEntity.fluidHandler.fill(new FluidStack(fluid, 1000), true);
        
        if (waterFilled > 0 && !playerIn.isCreative()) {
            playerIn.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.BUCKET));
        }

    } else if (itemHeld instanceof UniversalBucket) {

        UniversalBucket bucket = (UniversalBucket) itemHeld;
        FluidStack fluidStack = bucket.getFluid(itemStackHeld);

        if (tileEntity.fluidHandler.canFillFluidType(fluidStack)) {
            tileEntity.fluidHandler.fill(fluidStack, true);
            playerIn.setHeldItem(EnumHand.MAIN_HAND, bucket.getEmpty());
        }

    } else if (HydroponicHelper.isItemStackValid(itemStackHeld) && tileEntity.itemHandler.getStackInSlot(0).isEmpty()) {

        ItemStack remainder = tileEntity.itemHandler.insertItem(0, itemStackHeld.copy(), false);

        if (!playerIn.isCreative()) {
            playerIn.setHeldItem(EnumHand.MAIN_HAND, remainder);
        }

        return true;

    } else if (PlantHelper.isPlantItem(itemHeld) && facing == EnumFacing.UP) {

        return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);

        // Otherwise open the gui
    } else {
        playerIn.openGui(EmergingTechnology.instance, Reference.GUI_HYDROPONIC, worldIn, pos.getX(), pos.getY(),
                pos.getZ());
        return true;
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 16
Source File: ItemLungsUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onDrawScreenPost(RenderGameOverlayEvent.Post event)
{
	if (event.getType() == ElementType.AIR)
	{
		EntityPlayer p = Minecraft.getMinecraft().thePlayer;
		if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 0)) && !p.isCreative())
		{
			GL11.glPushMatrix();
			ItemStack stack = CyberwareAPI.getCyberware(p, new ItemStack(this, 1, 0));
			int air = getAir(stack);
			
			Minecraft.getMinecraft().getTextureManager().bindTexture(Gui.ICONS);
	
			ScaledResolution res = event.getResolution();
			GlStateManager.enableBlend();
			int left = res.getScaledWidth() / 2 + 91;
			int top = res.getScaledHeight() - 49 - 8;//- right_height;
			
			float r = 1F;
			float b = 1F;
			float g = 1F;

		
			if (p.isInsideOfMaterial(Material.WATER))
			{
				while (air > 0)
				{
					r += 1F;
					b -= .25F;
					g += .25F;
					GL11.glColor3f(r, g, b);
					int drawAir = Math.min(300, air);
					int full = MathHelper.ceiling_double_int((double)(drawAir - 2) * 10.0D / 300.0D);
					int partial = MathHelper.ceiling_double_int((double)drawAir * 10.0D / 300.0D) - full;
			
					for (int i = 0; i < full + partial; ++i)
					{
						ClientUtils.drawTexturedModalRect(left - i * 8 - 9, top, (i < full ? 16 : 25), 18, 9, 9);
					}
					
					
					air -= 300;
					top -= 8;
				}
			}
		
			GL11.glColor3f(1.0F, 1.0F, 1.0F);
			//GlStateManager.disableBlend();
			GL11.glPopMatrix();
		}
	}
}
 
Example 17
Source File: StackHelper.java    From AgriCraft with MIT License 4 votes vote down vote up
/**
 * Decreases the size of a given stack by the given amount, if the given player is not in
 * creative mode. Notice, this method treats null players as not being in creative mode, which
 * is important in many automation applications.
 *
 * @param player the player holding the given stack, or null if no player is holding the given
 * stack.
 * @param stack the stack to have its size decreased.
 * @param amount the amount to decrease the stack size by, must be a positive number.
 * @return
 * <table>
 * <tr>
 * <td>{@link MethodResult#PASS}</td>
 * <td>if and only if the stack was not null and the stack size was greater than or equal to the
 * amount to be removed.</td>
 * </tr>
 * <tr>
 * <td>{@link MethodResult#PASS}</td>
 * <td>if and only if the stack was not null and the player is in creative mode.</td>
 * </tr>
 * <tr>
 * <td>{@link MethodResult#FAIL}</td>
 * <td>otherwise.</td>
 * </tr>
 * </table>
 * @throws IllegalArgumentException if the given amount was less than zero.
 */
@Nonnull
public static final MethodResult decreaseStackSize(@Nullable EntityPlayer player, @Nonnull ItemStack stack, @Nonnegative int amount) {
    // Validate arguments.
    Preconditions.checkNotNull(stack, "Null Itemstack Detected!");
    Preconditions.checkArgument(amount > 0, "Cannot decrease ItemStack size by a negative amount! %d", amount);

    // Do stuff.
    if (stack.isEmpty()) {
        return MethodResult.FAIL;
    } else if (amount < 0) {
        throw new IllegalArgumentException("" + amount + " is not valid!");
    } else if (player != null && player.isCreative()) {
        return MethodResult.PASS;
    } else if (stack.getCount() - amount < 0) {
        return MethodResult.FAIL;
    } else {
        stack.setCount(stack.getCount() - amount);
        return MethodResult.PASS;
    }
}
 
Example 18
Source File: BlockCrop.java    From AgriCraft with MIT License 4 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) {
    ItemStack heldItem = player.getHeldItem(hand);

    // Step 0. Abort if remote.
    if (world.isRemote) {
        // I'm not sure if this is right, but oh well.
        return true;
    }

    // Step 1. Fetch the crop.
    TileEntityCrop crop = WorldHelper.getTile(world, pos, TileEntityCrop.class).orElse(null);

    // Step 2. Give up if the crop doesn't exist;
    if (crop == null) {
        // Allow others to use the click event.
        return false;
    }

    // Step 3. If the player is not holding anything, then harvest the crop.
    if (heldItem.isEmpty()) {
        crop.onHarvest((stack) -> WorldHelper.spawnItemInWorld(world, pos, stack), player);
        return true;
    }

    // Step 4. If the held item is excluded from handling, skip it.
    if (TypeHelper.isAnyType(heldItem.getItem(), ITEM_EXCLUDES)) {
        // Allow the excludes to do their things.
        return false;
    }

    // Step 5. If the held item is a type of fertilizer, apply it.
    if (AgriApi.getFertilizerRegistry().hasAdapter(heldItem)) {
        AgriApi.getFertilizerRegistry()
                .valueOf(heldItem)
                .ifPresent(f -> f.applyFertilizer(player, world, pos, crop, heldItem, crop.getRandom()));
        return true; // Even if it didn't grow or cross, we've still handled this block activation, so return true.
    }

    // Step 6. If the held item is crops, attempt to make cross-crops.
    if (heldItem.getItem() == AgriItems.getInstance().CROPS) {
        // Attempt to apply crop-sticks to crop.
        if (crop.onApplyCrops(player) == MethodResult.SUCCESS) {
            // If player isn't in creative remove an item from the stack.
            if (!player.isCreative()) {
                heldItem.setCount(heldItem.getCount() - 1);
            }
            // The application was a success!
            return true;
        }
    }

    // Step 7. Attempt to resolve held item as a seed.
    final Optional<AgriSeed> seed = AgriApi.getSeedRegistry().valueOf(heldItem);

    // Step 8. If held item is a seed, attempt to plant it in the crop.
    if (seed.isPresent()) {
        if (crop.onApplySeeds(seed.get(), player) == MethodResult.SUCCESS) {
            // Remove the consumed seed from the player's inventory.
            // But only if the player was not in creative mode.
            // For now we really don't care if the method fails,
            // so not checking the method's result is ok.
            StackHelper.decreaseStackSize(player, heldItem, 1);
            // The planting was a success!
            return true;
        }
    }

    // Step 8. If we can't do anything else, give up and attempt to harvest instead.
    crop.onHarvest((stack) -> WorldHelper.spawnItemInWorld(world, pos, stack), player);

    //Returning true will prevent other things from happening
    return true;

}
 
Example 19
Source File: EssentialsMissingHandler.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void overlayPre(RenderGameOverlayEvent.Pre event)
{

	if (event.getType() == ElementType.ALL)
	{
		EntityPlayer e = Minecraft.getMinecraft().thePlayer;
		
		HashMultimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
		multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getAttributeUnlocalizedName(), new AttributeModifier(speedId, "Missing leg speed", -100F, 0));
		//e.getAttributeMap().removeAttributeModifiers(multimap);
		
		
		if (CyberwareAPI.hasCapability(e))
		{
			ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
			
			if (!cyberware.hasEssential(EnumSlot.EYES) && !e.isCreative())
			{
				GlStateManager.pushMatrix();
				GlStateManager.enableBlend();
				GlStateManager.color(1F, 1F, 1F, .9F);
				Minecraft.getMinecraft().getTextureManager().bindTexture(BLACK_PX);
				ClientUtils.drawTexturedModalRect(0, 0, 0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
				GlStateManager.popMatrix();
			}
		}
		
		if (TileEntitySurgery.workingOnPlayer)
		{
			float trans = 1.0F;
			float ticks = TileEntitySurgery.playerProgressTicks + event.getPartialTicks();
			if (ticks < 20F)
			{
				trans = ticks / 20F;
			}
			else if (ticks > 60F)
			{
				trans = (80F - ticks) / 20F;
			}
			GL11.glEnable(GL11.GL_BLEND);
			GL11.glColor4f(1.0F, 1.0F, 1.0F, trans);
			Minecraft.getMinecraft().getTextureManager().bindTexture(BLACK_PX);
			ClientUtils.drawTexturedModalRect(0, 0, 0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
			GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
			GL11.glDisable(GL11.GL_BLEND);
		}
	}
}
 
Example 20
Source File: Light.java    From EmergingTechnology with MIT License 3 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;
    }

    TileEntity tileEntity = worldIn.getTileEntity(pos);

    if (tileEntity instanceof LightTileEntity) {

        LightTileEntity lightTileEntity = (LightTileEntity) tileEntity;

        ItemStack itemStackHeld = playerIn.getHeldItemMainhand();

        if (LightHelper.isItemStackValidBulb(itemStackHeld)
                && lightTileEntity.itemHandler.getStackInSlot(0).isEmpty()) {

            ItemStack remainder = lightTileEntity.itemHandler.insertItem(0, itemStackHeld.copy(), false);

            if (!playerIn.isCreative()) {
                playerIn.setHeldItem(EnumHand.MAIN_HAND, remainder);
            }

            return true;
        }
    }

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

    return true;
}