Search in sources :

Example 56 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.

the class BuilderTileEntity method getBlockInformation.

public static BuilderSetup.BlockInformation getBlockInformation(World world, BlockPos pos, Block block, TileEntity tileEntity) {
    IBlockState state = world.getBlockState(pos);
    if (isEmpty(state, block)) {
        return BuilderSetup.BlockInformation.FREE;
    }
    FakePlayer fakePlayer = getHarvester();
    if (!allowedToBreak(state, world, pos, fakePlayer)) {
        return BuilderSetup.BlockInformation.INVALID;
    }
    BuilderSetup.BlockInformation blockInformation = BuilderSetup.getBlockInformation(block);
    if (tileEntity != null) {
        switch(BuilderConfiguration.teMode) {
            case MOVE_FORBIDDEN:
                return BuilderSetup.BlockInformation.INVALID;
            case MOVE_WHITELIST:
                if (blockInformation == null || blockInformation.getBlockLevel() == SupportBlock.STATUS_ERROR) {
                    return BuilderSetup.BlockInformation.INVALID;
                }
                break;
            case MOVE_BLACKLIST:
                if (blockInformation != null && blockInformation.getBlockLevel() == SupportBlock.STATUS_ERROR) {
                    return BuilderSetup.BlockInformation.INVALID;
                }
                break;
            case MOVE_ALLOWED:
                break;
        }
    }
    if (blockInformation != null) {
        return blockInformation;
    }
    return BuilderSetup.BlockInformation.OK;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 57 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.

the class BuilderTileEntity method placeLiquidBlock.

public boolean placeLiquidBlock(int rfNeeded, BlockPos srcPos, IBlockState srcState, IBlockState pickState) {
    if (isEmptyOrReplacable(getWorld(), srcPos)) {
        FluidStack stack = consumeLiquid(getWorld(), srcPos);
        if (stack == null) {
            // We could not find a block. Wait
            return waitOrSkip("Cannot find liquid!\nor no usable tank\nabove or below");
        }
        Fluid fluid = stack.getFluid();
        if (fluid.doesVaporize(stack) && getWorld().provider.doesWaterVaporize()) {
            fluid.vaporize(null, getWorld(), srcPos, stack);
        } else {
            // We assume here the liquid is placable.
            Block block = fluid.getBlock();
            FakePlayer fakePlayer = getHarvester();
            getWorld().setBlockState(srcPos, block.getDefaultState(), 11);
            if (!silent) {
                SoundTools.playSound(getWorld(), block.getSoundType(block.getDefaultState(), getWorld(), srcPos, fakePlayer).getPlaceSound(), srcPos.getX(), srcPos.getY(), srcPos.getZ(), 1.0f, 1.0f);
            }
        }
        consumeEnergy(rfNeeded);
    }
    return skip();
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) BaseBlock(mcjty.lib.container.BaseBlock) Block(net.minecraft.block.Block) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 58 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.

the class BuilderTileEntity method voidBlock.

public boolean voidBlock(int rfNeeded, BlockPos srcPos, IBlockState srcState, IBlockState pickState) {
    Block block = srcState.getBlock();
    int xCoord = getPos().getX();
    int yCoord = getPos().getY();
    int zCoord = getPos().getZ();
    int sx = srcPos.getX();
    int sy = srcPos.getY();
    int sz = srcPos.getZ();
    if (sx >= xCoord - 1 && sx <= xCoord + 1 && sy >= yCoord - 1 && sy <= yCoord + 1 && sz >= zCoord - 1 && sz <= zCoord + 1) {
        // Skip a 3x3x3 block around the builder.
        return skip();
    }
    FakePlayer fakePlayer = getHarvester();
    if (allowedToBreak(srcState, getWorld(), srcPos, fakePlayer)) {
        if (block.getBlockHardness(srcState, getWorld(), srcPos) >= 0) {
            ItemStack filter = getStackInSlot(BuilderContainer.SLOT_FILTER);
            if (!filter.isEmpty()) {
                getFilterCache();
                if (filterCache != null) {
                    boolean match = filterCache.match(block.getItem(getWorld(), srcPos, srcState));
                    if (!match) {
                        consumeEnergy(Math.min(rfNeeded, BuilderConfiguration.builderRfPerSkipped));
                        // Skip this
                        return skip();
                    }
                }
            }
            if (!silent) {
                SoundTools.playSound(getWorld(), block.getSoundType(srcState, getWorld(), srcPos, fakePlayer).getBreakSound(), sx, sy, sz, 1.0f, 1.0f);
            }
            getWorld().setBlockToAir(srcPos);
            consumeEnergy(rfNeeded);
        }
    }
    return skip();
}
Also used : BaseBlock(mcjty.lib.container.BaseBlock) Block(net.minecraft.block.Block) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 59 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.

the class ShieldTEBase method applyDamageToEntity.

public void applyDamageToEntity(Entity entity) {
    DamageSource source;
    int rf;
    if (DamageTypeMode.DAMAGETYPE_GENERIC.equals(damageMode)) {
        rf = ShieldConfiguration.rfDamage;
        source = DamageSource.GENERIC;
    } else {
        rf = ShieldConfiguration.rfDamagePlayer;
        if (killer == null) {
            killer = FakePlayerFactory.get(DimensionManager.getWorld(0), new GameProfile(new UUID(111, 222), "rftools_shield"));
        }
        FakePlayer fakePlayer = killer;
        ItemStack shards = getStackInSlot(ShieldContainer.SLOT_SHARD);
        if (!shards.isEmpty() && shards.getCount() >= ShieldConfiguration.shardsPerLootingKill) {
            decrStackSize(ShieldContainer.SLOT_SHARD, ShieldConfiguration.shardsPerLootingKill);
            if (lootingSword.isEmpty()) {
                lootingSword = EnvironmentalSetup.createEnchantedItem(Items.DIAMOND_SWORD, Enchantments.LOOTING, ShieldConfiguration.lootingKillBonus);
            }
            lootingSword.setItemDamage(0);
            fakePlayer.setHeldItem(EnumHand.MAIN_HAND, lootingSword);
        } else {
            fakePlayer.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
        }
        source = DamageSource.causePlayerDamage(fakePlayer);
    }
    rf = (int) (rf * costFactor * (4.0f - getInfusedFactor()) / 4.0f);
    if (getEnergyStored() < rf) {
        // Not enough RF to do damage.
        return;
    }
    consumeEnergy(rf);
    float damage = ShieldConfiguration.damage;
    damage *= damageFactor;
    damage = damage * (1.0f + getInfusedFactor() / 2.0f);
    entity.attackEntityFrom(source, damage);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 60 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project OpenModularTurrets by OpenModularTurretsTeam.

the class OMTEventHandler method entityAttackedEvent.

@SubscribeEvent
public void entityAttackedEvent(LivingAttackEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    int fakeDrops = OMTUtil.getFakeDropsLevel(entity);
    if (fakeDrops >= 0) {
        FakePlayer player = OMTFakePlayer.getFakePlayer((WorldServer) event.getEntityLiving().getEntityWorld());
        player.setHeldItem(EnumHand.MAIN_HAND, OMTFakePlayer.getSword(fakeDrops));
        entity.setLastAttackedEntity(player);
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) OMTFakePlayer(omtteam.openmodularturrets.util.OMTFakePlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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