Search in sources :

Example 46 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.

the class TileFarmStation method executeBonemeal.

private void executeBonemeal(@Nonnull IFarmer farmer, @Nonnull BlockPos farmingPos, @Nonnull Block block) {
    if (hasBonemeal() && bonemealCooldown-- <= 0 && random.nextFloat() <= FarmConfig.farmBonemealChance.get() && farmer.checkAction(FarmingAction.FERTILIZE, FarmingTool.HAND)) {
        final ItemStack fertStack = getStackInSlot(minFirtSlot);
        IFertilizer fertilizer = Fertilizer.getInstance(fertStack);
        boolean doApply;
        if (fertilizer.applyOnPlant() && fertilizer.applyOnAir()) {
            doApply = !isOpen(farmingPos, block) || world.isAirBlock(farmingPos);
        } else if (fertilizer.applyOnPlant()) {
            doApply = !isOpen(farmingPos, block);
        } else if (fertilizer.applyOnAir()) {
            doApply = world.isAirBlock(farmingPos);
        } else {
            doApply = true;
        }
        if (doApply) {
            FakePlayer farmerJoe = farmer.startUsingItem(Prep.getEmpty());
            final IFertilizerResult result = fertilizer.apply(fertStack, farmerJoe, world, farmingPos);
            if (result.wasApplied()) {
                setInventorySlotContents(minFirtSlot, result.getStack());
                PacketHandler.sendToAllAround(new PacketFarmAction(farmingPos), this);
                bonemealCooldown = FarmConfig.farmBonemealDelaySuccess.get();
                farmer.registerAction(FarmingAction.FERTILIZE, FarmingTool.HAND);
            } else {
                usePower(FarmConfig.farmBonemealEnergyUseFail.get());
                bonemealCooldown = FarmConfig.farmBonemealDelayFail.get();
            }
            farmer.handleExtraItems(farmer.endUsingItem(false), farmingPos);
        }
    }
}
Also used : IFertilizerResult(crazypants.enderio.api.farm.IFertilizerResult) ItemStack(net.minecraft.item.ItemStack) IFertilizer(crazypants.enderio.api.farm.IFertilizer) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 47 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.

the class ItemDarkSteelSword method onEntityDrop.

// Set priority to lowest in the hope any other mod adding head drops will have already added them
// by the time this is called to prevent multiple head drops
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onEntityDrop(LivingDropsEvent evt) {
    final Entity entity = evt.getSource().getTrueSource();
    final EntityLivingBase entityLiving = evt.getEntityLiving();
    if (!(entity instanceof EntityPlayer) || entityLiving == null) {
        return;
    }
    EntityPlayer player = (EntityPlayer) entity;
    // Handle TiC weapons with beheading differently
    if (handleBeheadingWeapons(player, evt)) {
        return;
    }
    double skullDropChance = getSkullDropChance(player, evt);
    if (player instanceof FakePlayer) {
        skullDropChance *= Config.fakePlayerSkullChance;
    }
    if (Math.random() <= skullDropChance) {
        dropSkull(evt, player);
    }
    // Special handling for ender pearl drops
    if (isEquipped(player)) {
        ResourceLocation name = EntityList.getKey(entityLiving);
        if (entityLiving instanceof EntityEnderman || ENDERZOO_ENDERMINY.equals(name)) {
            int numPearls = 0;
            double chance = Config.darkSteelSwordEnderPearlDropChance;
            while (chance >= 1) {
                numPearls++;
                chance--;
            }
            if (chance > 0 && Math.random() <= chance) {
                numPearls++;
            }
            for (int i = 0; i < evt.getLootingLevel(); i++) {
                chance = Config.darkSteelSwordEnderPearlDropChancePerLooting;
                while (chance >= 1) {
                    numPearls++;
                    chance--;
                }
                if (chance > 0 && Math.random() <= chance) {
                    numPearls++;
                }
            }
            int existing = 0;
            for (EntityItem stack : evt.getDrops()) {
                if (stack.getItem().getItem() == Items.ENDER_PEARL) {
                    existing += stack.getItem().getCount();
                }
            }
            int toDrop = numPearls - existing;
            if (toDrop > 0) {
                evt.getDrops().add(Util.createDrop(player.world, new ItemStack(Items.ENDER_PEARL, toDrop, 0), entityLiving.posX, entityLiving.posY, entityLiving.posZ, false));
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) EntityItem(net.minecraft.entity.item.EntityItem) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 48 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.

the class HandlerSoulBound method onPlayerDeath.

/*
   * This is called the moment the player dies and drops his stuff.
   * 
   * We go early, so we can get our items before other mods put them into some grave. Also remove them from the list so they won't get duped. If the inventory
   * overflows, e.g. because everything there and the armor is soulbound, let the remainder be dropped/graved.
   */
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onPlayerDeath(PlayerDropsEvent evt) {
    if (evt.getEntityPlayer() == null || evt.getEntityPlayer() instanceof FakePlayer || evt.isCanceled()) {
        return;
    }
    if (evt.getEntityPlayer().world.getGameRules().getBoolean("keepInventory")) {
        return;
    }
    Log.debug("Running onPlayerDeathEarly logic for " + evt.getEntityPlayer().getName());
    ListIterator<EntityItem> iter = evt.getDrops().listIterator();
    while (iter.hasNext()) {
        EntityItem ei = iter.next();
        ItemStack item = ei.getItem();
        if (isSoulBound(item)) {
            if (addToPlayerInventory(evt.getEntityPlayer(), item)) {
                iter.remove();
            }
        }
    }
    // Note: Baubles will also add its items to evt.drops, but later. We cannot
    // wait for that because gravestone mods also listen to this event. So we have
    // to fetch Baubles items ourselves here.
    // For the same reason we cannot put the items into Baubles slots.
    IInventory baubles = BaublesUtil.instance().getBaubles(evt.getEntityPlayer());
    if (baubles != null) {
        for (int i = 0; i < baubles.getSizeInventory(); i++) {
            ItemStack item = baubles.getStackInSlot(i);
            if (isSoulBound(item)) {
                if (addToPlayerInventory(evt.getEntityPlayer(), item)) {
                    baubles.setInventorySlotContents(i, Prep.getEmpty());
                }
            }
        }
    }
    // stuff into the normal inventory to not have to keep a separate list.
    if (evt.getEntityPlayer() instanceof EntityPlayerMP) {
        IInventory galacticraft = GalacticraftUtil.getGCInventoryForPlayer((EntityPlayerMP) evt.getEntityPlayer());
        if (galacticraft != null) {
            for (int i = 0; i < galacticraft.getSizeInventory(); i++) {
                ItemStack item = galacticraft.getStackInSlot(i);
                if (isSoulBound(item)) {
                    if (addToPlayerInventory(evt.getEntityPlayer(), item)) {
                        galacticraft.setInventorySlotContents(i, Prep.getEmpty());
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 49 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project ForestryMC by ForestryMC.

the class BreedingTracker method syncToPlayer.

private void syncToPlayer(Collection<String> discoveredSpecies, Collection<String> discoveredMutations, Collection<String> researchedMutations) {
    if (world != null && username != null && username.getName() != null) {
        EntityPlayer player = world.getPlayerEntityByName(username.getName());
        if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
            IBreedingTracker breedingTracker = getBreedingTracker(player);
            String modeName = breedingTracker.getModeName();
            setModeName(modeName);
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            writeToNBT(nbtTagCompound, discoveredSpecies, discoveredMutations, researchedMutations);
            PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbtTagCompound);
            NetworkUtil.sendToPlayer(packet, player);
            for (String species : discoveredSpecies) {
                SpeciesDiscoveredTrigger.INSTANCE.trigger((EntityPlayerMP) player, AlleleManager.alleleRegistry.getAllele(species));
            }
        }
    }
}
Also used : IBreedingTracker(forestry.api.genetics.IBreedingTracker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketGenomeTrackerSync(forestry.core.network.packets.PacketGenomeTrackerSync) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 50 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project ForestryMC by ForestryMC.

the class NetworkUtil method sendToPlayer.

public static void sendToPlayer(IForestryPacketClient packet, EntityPlayer entityplayer) {
    if (!(entityplayer instanceof EntityPlayerMP) || entityplayer instanceof FakePlayer) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entityplayer;
    Forestry.getPacketHandler().sendPacket(packet.getPacket(), player);
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Aggregations

FakePlayer (net.minecraftforge.common.util.FakePlayer)73 ItemStack (net.minecraft.item.ItemStack)26 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 IBlockState (net.minecraft.block.state.IBlockState)14 BlockPos (net.minecraft.util.math.BlockPos)11 EntityItem (net.minecraft.entity.item.EntityItem)10 World (net.minecraft.world.World)8 TileEntity (net.minecraft.tileentity.TileEntity)7 Block (net.minecraft.block.Block)6 BaseBlock (mcjty.lib.container.BaseBlock)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 IGregTechTileEntity (gregtech.api.interfaces.tileentity.IGregTechTileEntity)3 MannequinFakePlayer (riskyken.armourersWorkshop.client.render.MannequinFakePlayer)3 PlayerPointer (riskyken.armourersWorkshop.common.data.PlayerPointer)3 SacrificeKnifeUsedEvent (WayofTime.alchemicalWizardry.api.event.SacrificeKnifeUsedEvent)2 IMinerStats (cavern.api.IMinerStats)2