Search in sources :

Example 51 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project BloodMagic by WayofTime.

the class ItemDaggerOfSacrifice method hitEntity.

@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
    if (attacker instanceof FakePlayer)
        return false;
    if (target == null || attacker == null || attacker.getEntityWorld().isRemote || (attacker instanceof EntityPlayer && !(attacker instanceof EntityPlayerMP)))
        return false;
    if (!target.isNonBoss())
        return false;
    if (target instanceof EntityPlayer)
        return false;
    if (target.isChild() && !(target instanceof IMob))
        return false;
    if (target.isDead || target.getHealth() < 0.5F)
        return false;
    EntityEntry entityEntry = EntityRegistry.getEntry(target.getClass());
    if (entityEntry == null)
        return false;
    int lifeEssenceRatio = BloodMagicAPI.INSTANCE.getValueManager().getSacrificial().getOrDefault(entityEntry.getRegistryName(), 25);
    if (lifeEssenceRatio <= 0)
        return false;
    int lifeEssence = (int) (lifeEssenceRatio * target.getHealth());
    if (target instanceof EntityAnimal) {
        lifeEssence = (int) (lifeEssence * (1 + PurificationHelper.getCurrentPurity((EntityAnimal) target)));
    }
    if (target.isChild()) {
        lifeEssence *= 0.5F;
    }
    if (PlayerSacrificeHelper.findAndFillAltar(attacker.getEntityWorld(), target, lifeEssence, true)) {
        target.getEntityWorld().playSound(null, target.posX, target.posY, target.posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (target.getEntityWorld().rand.nextFloat() - target.getEntityWorld().rand.nextFloat()) * 0.8F);
        target.setHealth(-1);
        target.onDeath(DamageSourceBloodMagic.INSTANCE);
    }
    return false;
}
Also used : EntityEntry(net.minecraftforge.fml.common.registry.EntityEntry) IMob(net.minecraft.entity.monster.IMob) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 52 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.

the class UIFactory method openUI.

public final void openUI(E holder, EntityPlayerMP player) {
    if (player instanceof FakePlayer) {
        return;
    }
    ModularUI uiTemplate = createUITemplate(holder, player);
    uiTemplate.initWidgets();
    player.getNextWindowId();
    player.closeContainer();
    int currentWindowId = player.currentWindowId;
    PacketBuffer serializedHolder = new PacketBuffer(Unpooled.buffer());
    writeHolderToSyncData(serializedHolder, holder);
    int uiFactoryId = FACTORY_REGISTRY.getIDForObject(this);
    ModularUIContainer container = new ModularUIContainer(uiTemplate);
    container.windowId = currentWindowId;
    // accumulate all initial updates of widgets in open packet
    container.accumulateWidgetUpdateData = true;
    uiTemplate.guiWidgets.values().forEach(Widget::detectAndSendChanges);
    container.accumulateWidgetUpdateData = false;
    ArrayList<PacketUIWidgetUpdate> updateData = new ArrayList<>(container.accumulatedUpdates);
    container.accumulatedUpdates.clear();
    PacketUIOpen packet = new PacketUIOpen(uiFactoryId, serializedHolder, currentWindowId, updateData);
    NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(packet), player);
    container.addListener(player);
    player.openContainer = container;
    // and fire forge event only in the end
    MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container));
}
Also used : PacketUIWidgetUpdate(gregtech.api.net.PacketUIWidgetUpdate) ModularUIContainer(gregtech.api.gui.impl.ModularUIContainer) ArrayList(java.util.ArrayList) PacketUIOpen(gregtech.api.net.PacketUIOpen) PlayerContainerEvent(net.minecraftforge.event.entity.player.PlayerContainerEvent) PacketBuffer(net.minecraft.network.PacketBuffer) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 53 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.

the class ToolUtility method applyTimberAxe.

public static boolean applyTimberAxe(ItemStack itemStack, World world, BlockPos blockPos, EntityPlayer player) {
    if (player instanceof FakePlayer) {
        return false;
    }
    IBlockState blockState = world.getBlockState(blockPos);
    if (TreeChopTask.isLogBlock(blockState) == 1) {
        if (!world.isRemote) {
            EntityPlayerMP playerMP = (EntityPlayerMP) player;
            TreeChopTask treeChopTask = new TreeChopTask(blockPos, world, playerMP, itemStack);
            TaskScheduler.scheduleTask(world, treeChopTask);
        }
        return true;
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 54 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.

the class ToolUtility method applyHammerDrops.

public static void applyHammerDrops(Random random, IBlockState blockState, List<ItemStack> drops, int fortuneLevel, EntityPlayer player) {
    ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().getMetaFromState(blockState));
    Recipe recipe = RecipeMaps.FORGE_HAMMER_RECIPES.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList(), 0);
    if (recipe != null && !recipe.getOutputs().isEmpty()) {
        drops.clear();
        for (ItemStack outputStack : recipe.getResultItemOutputs(Integer.MAX_VALUE, random, 0)) {
            outputStack = outputStack.copy();
            if (!(player instanceof FakePlayer) && OreDictUnifier.getPrefix(outputStack) == OrePrefix.crushed) {
                int growAmount = Math.round(outputStack.getCount() * random.nextFloat());
                if (fortuneLevel > 0) {
                    int i = Math.max(0, random.nextInt(fortuneLevel + 2) - 1);
                    growAmount += outputStack.getCount() * i;
                }
                outputStack.grow(growAmount);
            }
            drops.add(outputStack);
        }
    }
}
Also used : Recipe(gregtech.api.recipes.Recipe) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 55 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.

the class ToolJackHammer method onBlockDestroyed.

@Override
public void onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entity) {
    if (entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) {
        EntityPlayer entityPlayer = (EntityPlayer) entity;
        EnumFacing sideHit = ToolUtility.getSideHit(world, pos, entityPlayer);
        int damagePerBlockBreak = getToolDamagePerBlockBreak(stack);
        JackHammerMode jackHammerMode = MODE_SWITCH_BEHAVIOR.getModeFromItemStack(stack);
        EnumFacing horizontalFacing = entity.getHorizontalFacing();
        int xSizeExtend = (jackHammerMode.getHorizontalSize() - 1) / 2;
        int ySizeExtend = (jackHammerMode.getVerticalSize() - 1) / 2;
        for (int x = -xSizeExtend; x <= xSizeExtend; x++) {
            for (int y = -ySizeExtend; y <= ySizeExtend; y++) {
                // do not check center block - it's handled now
                if (x == 0 && y == 0)
                    continue;
                BlockPos offsetPos = rotate(pos, x, y, sideHit, horizontalFacing);
                IBlockState blockState = world.getBlockState(offsetPos);
                if (world.isBlockModifiable(entityPlayer, offsetPos) && blockState.getBlock().canHarvestBlock(world, offsetPos, entityPlayer) && blockState.getPlayerRelativeBlockHardness(entityPlayer, world, offsetPos) > 0.0f && stack.canHarvestBlock(blockState)) {
                    GTUtility.harvestBlock(world, offsetPos, entityPlayer);
                    ((ToolMetaItem) stack.getItem()).damageItem(stack, damagePerBlockBreak, false);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ToolMetaItem(gregtech.api.items.toolitem.ToolMetaItem) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) 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