Search in sources :

Example 1 with FakePlayer

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

the class FMLNetworkHandler method openGui.

public static void openGui(EntityPlayer entityPlayer, Object mod, int modGuiId, World world, int x, int y, int z) {
    ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
    if (entityPlayer instanceof EntityPlayerMP && !(entityPlayer instanceof FakePlayer)) {
        EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
        Container remoteGuiContainer = NetworkRegistry.INSTANCE.getRemoteGuiContainer(mc, entityPlayerMP, modGuiId, world, x, y, z);
        if (remoteGuiContainer != null) {
            entityPlayerMP.getNextWindowId();
            entityPlayerMP.closeContainer();
            int windowId = entityPlayerMP.currentWindowId;
            FMLMessage.OpenGui openGui = new FMLMessage.OpenGui(windowId, mc.getModId(), modGuiId, x, y, z);
            EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
            embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER);
            embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityPlayerMP);
            embeddedChannel.writeOutbound(openGui);
            entityPlayerMP.openContainer = remoteGuiContainer;
            entityPlayerMP.openContainer.windowId = windowId;
            entityPlayerMP.openContainer.addListener(entityPlayerMP);
            net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(entityPlayer, entityPlayer.openContainer));
        }
    } else if (entityPlayer instanceof FakePlayer) {
    // NO OP - I won't even log a message!
    } else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT)) {
        Object guiContainer = NetworkRegistry.INSTANCE.getLocalGuiContainer(mc, entityPlayer, modGuiId, world, x, y, z);
        FMLCommonHandler.instance().showGuiScreen(guiContainer);
    } else {
        FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUI ID: %s,%d", mc.getModId(), modGuiId);
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) FMLEmbeddedChannel(net.minecraftforge.fml.common.network.FMLEmbeddedChannel) FakePlayer(net.minecraftforge.common.util.FakePlayer) ModContainer(net.minecraftforge.fml.common.ModContainer) FMLContainer(net.minecraftforge.fml.common.FMLContainer) Container(net.minecraft.inventory.Container) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) JsonObject(com.google.gson.JsonObject)

Example 2 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project NetherEx by LogicTechCorp.

the class EventHandler method onBlockBreak.

@SubscribeEvent
public static void onBlockBreak(BlockEvent.BreakEvent event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = event.getState();
    if (!(event.getPlayer() instanceof FakePlayer)) {
        EntityPlayer player = event.getPlayer();
        if (state.getBlock() == Blocks.MAGMA) {
            if (ConfigHandler.block.magma.turnIntoLava) {
                if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) == 0) {
                    world.setBlockState(pos, Blocks.LAVA.getDefaultState(), 3);
                    player.getHeldItemMainhand().damageItem(1, player);
                    event.setCanceled(true);
                }
            }
        }
        if (player.dimension == -1) {
            boolean canSpawn = Arrays.asList(ConfigHandler.entity.nethermite.whitelist).contains(state.getBlock().getRegistryName().toString());
            if (canSpawn && world.rand.nextInt(ConfigHandler.entity.nethermite.chanceOfSpawning) == 0) {
                EntityNethermite nethermite = new EntityNethermite(world);
                nethermite.setPosition((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D);
                world.spawnEntity(nethermite);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityNethermite(nex.entity.monster.EntityNethermite) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with FakePlayer

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

the class BreedingTracker method synchToPlayer.

@Override
public void synchToPlayer(EntityPlayer player) {
    if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
        IBreedingTracker breedingTracker = getBreedingTracker(player);
        String modeName = breedingTracker.getModeName();
        setModeName(modeName);
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        encodeToNBT(nbttagcompound);
        PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbttagcompound);
        NetworkUtil.sendToPlayer(packet, player);
    }
}
Also used : IBreedingTracker(forestry.api.genetics.IBreedingTracker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketGenomeTrackerSync(forestry.core.network.packets.PacketGenomeTrackerSync) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 4 with FakePlayer

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

the class ItemDarkSteelSword method handleBeheadingWeapons.

private boolean handleBeheadingWeapons(EntityPlayer player, LivingDropsEvent evt) {
    if (player == null) {
        return false;
    }
    ItemStack equipped = player.getHeldItemMainhand();
    NBTTagCompound tagCompound = equipped.getTagCompound();
    if (tagCompound == null) {
        return false;
    }
    int beheading = TicUtil.getModifier(tagCompound, TicUtil.BEHEADING);
    int cleaver = TicUtil.getModifier(tagCompound, TicUtil.CLEAVER);
    if (beheading == 0 && cleaver == 0) {
        // Use default behavior if it is not a cleaver and doesn't have beheading
        return false;
    }
    if (!(evt.getEntityLiving() instanceof EntityEnderman)) {
        // We wont modify head drops at all
        return true;
    }
    float chance = Math.max(Config.vanillaSwordSkullChance, cleaver * Config.ticCleaverSkullDropChance) + (Config.ticBeheadingSkullModifier * beheading);
    if (player instanceof FakePlayer) {
        chance *= Config.fakePlayerSkullChance;
    }
    while (chance >= 1) {
        dropSkull(evt, player);
        chance--;
    }
    if (chance > 0 && Math.random() <= chance) {
        dropSkull(evt, player);
    }
    return true;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 5 with FakePlayer

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

the class HandlerSoulBound method onPlayerDeathLate.

/*
   * Do a second (late) pass. If any mod has added items to the list in the meantime, this gives us a chance to save them, too. If some gravestone mod has
   * removed drops, we'll get nothing here.
   */
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onPlayerDeathLate(PlayerDropsEvent evt) {
    if (evt.getEntityPlayer() == null || evt.getEntityPlayer() instanceof FakePlayer || evt.isCanceled()) {
        return;
    }
    if (evt.getEntityPlayer().world.getGameRules().getBoolean("keepInventory")) {
        return;
    }
    Log.debug("Running onPlayerDeathLate 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();
            }
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) FakePlayer(net.minecraftforge.common.util.FakePlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

FakePlayer (net.minecraftforge.common.util.FakePlayer)68 ItemStack (net.minecraft.item.ItemStack)25 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)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 TileEntity (net.minecraft.tileentity.TileEntity)6 World (net.minecraft.world.World)6 Block (net.minecraft.block.Block)5 BaseBlock (mcjty.lib.container.BaseBlock)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 EnumFacing (net.minecraft.util.EnumFacing)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 IMinerStats (cavern.api.IMinerStats)2