当前位置: 首页>>代码示例>>Java>>正文


Java FakePlayerFactory类代码示例

本文整理汇总了Java中net.minecraftforge.common.util.FakePlayerFactory的典型用法代码示例。如果您正苦于以下问题:Java FakePlayerFactory类的具体用法?Java FakePlayerFactory怎么用?Java FakePlayerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FakePlayerFactory类属于net.minecraftforge.common.util包,在下文中一共展示了FakePlayerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
@Override
public void update() {
    super.update();
    if (!world.isRemote) {
        TileEntityMobSpawner te = getTileEntity();
        if(te != null){
            MobSpawnerBaseLogic spawnerLogic = te.getSpawnerBaseLogic();
            
            //Only tick the logic if it wasn't ticked already by the TE itself, to prevent double ticking.
            if(!Reflections.isActivated(spawnerLogic)){
                
                //Temporarily add a fake player to the world to trick the spawner into thinking there's a player nearby
                EntityPlayer fakePlayer = FakePlayerFactory.get((WorldServer)world, FAKE_PLAYER_PROFILE);
                fakePlayer.posX = getPos().getX();
                fakePlayer.posY = getPos().getY();
                fakePlayer.posZ = getPos().getZ();
                
                world.playerEntities.add(fakePlayer);
                spawnerLogic.updateSpawner();
                world.playerEntities.remove(fakePlayer);
            }                
        }
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:25,代码来源:SemiBlockSpawnerAgitator.java

示例2: PlantSapling

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
private void PlantSapling(World world, BlockPos blockPos, BlockPos originPos) {

        Set<ItemStack> leafDrop = new HashSet<>();
        BlockPos plantPos1 = new BlockPos(originPos.getX() - 1, originPos.getY(), originPos.getZ() - 1);
        int counter = 0;

        while (leafDrop.isEmpty() && counter <= 100) {
            NonNullList<ItemStack> tmpList = NonNullList.create();
            world.getBlockState(blockPos).getBlock().getDrops(tmpList, world, blockPos, world.getBlockState(blockPos), 3);
            leafDrop.addAll(tmpList);

            counter++;
        }

        if (leafDrop.isEmpty()) {
            return;
        }

        FakePlayer fakePlayer = FakePlayerFactory.getMinecraft((WorldServer) world);
        fakePlayer.setHeldItem(EnumHand.MAIN_HAND, leafDrop.iterator().next());

        for (ItemStack itemStack : leafDrop) {
            itemStack.onItemUse(fakePlayer, world, plantPos1, EnumHand.MAIN_HAND, EnumFacing.NORTH, 0, 0, 0);
        }
    }
 
开发者ID:DuchLord,项目名称:TreeChopper,代码行数:26,代码来源:TreeHandler.java

示例3: doPlayerLastHit

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
public boolean doPlayerLastHit(final World world, final Entity target, final TileEntity tile) {
    final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft((WorldServer)world);
    try {
        final ItemStack stack = this.swordStack.copy();
        if (tile instanceof TileEntityEnchantedSpike) {
            stack.setTagCompound(((TileEntityEnchantedSpike)tile).getEnchantmentTagList());
        }
        fakePlayer.setCurrentItemOrArmor(0, stack);
        boolean b = target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer)fakePlayer), 400.0f);
        fakePlayer.setCurrentItemOrArmor(0, (ItemStack)null);
        b |= target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer)fakePlayer), 400.0f);
        b |= target.attackEntityFrom(DamageSource.cactus, 400.0f);
        return b;
    }
    finally {
        fakePlayer.setCurrentItemOrArmor(0, (ItemStack)null);
    }
}
 
开发者ID:sameer,项目名称:ExtraUtilities,代码行数:19,代码来源:BlockSpike.java

示例4: BreakBlock

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
public static boolean BreakBlock(World worldObj, BlockPos pos, Entity player) {
	IBlockState state = worldObj.getBlockState(pos);

	EntityPlayer passedPlayer;

	if (player instanceof EntityPlayer) {
		passedPlayer = (EntityPlayer) player;
	} else {
		passedPlayer = FakePlayerFactory.get((WorldServer) worldObj, Reference.gameProfile);
	}

	BlockEvent.BreakEvent breakEvent = new BlockEvent.BreakEvent(worldObj, pos, state, passedPlayer);
	MinecraftForge.EVENT_BUS.post(breakEvent);

	if (breakEvent.isCanceled()) {
		return false;
	}

	worldObj.getBlockState(pos).getBlock().dropBlockAsItem(worldObj, pos, state, 0);
	// TODO add block break sound
	worldObj.setBlockToAir(pos);

	return true;
}
 
开发者ID:TechStack,项目名称:TechStack-s-HeavyMachineryMod,代码行数:25,代码来源:BlockUtil.java

示例5: initFakePlayer

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
public static WeakReference<FakePlayer> initFakePlayer(WorldServer ws, UUID uname, String blockName) {
  GameProfile breakerProfile = new GameProfile(uname, Const.MODID + ".fake_player." + blockName);
  WeakReference<FakePlayer> fakePlayer;
  try {
    fakePlayer = new WeakReference<FakePlayer>(FakePlayerFactory.get(ws, breakerProfile));
  }
  catch (Exception e) {
    ModCyclic.logger.error("Exception thrown trying to create fake player : " + e.getMessage());
    fakePlayer = null;
  }
  if (fakePlayer == null || fakePlayer.get() == null) {
    fakePlayer = null;
    return null; // trying to get around https://github.com/PrinceOfAmber/Cyclic/issues/113
  }
  fakePlayer.get().onGround = true;
  fakePlayer.get().connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer.get()) {
    @SuppressWarnings("rawtypes")
    @Override
    public void sendPacket(Packet packetIn) {}
  };
  fakePlayer.get().setSilent(true);
  return fakePlayer;
}
 
开发者ID:PrinceOfAmber,项目名称:Cyclic,代码行数:24,代码来源:UtilFakePlayer.java

示例6: placeCart

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
/**
 * Spawns a new cart entity using the provided item.
 * <p/>
 * The backing item must implement <code>IMinecartItem</code> and/or extend
 * <code>ItemMinecart</code>.
 * <p/>
 * Generally Forge requires all cart items to extend ItemMinecart.
 *
 * @param owner The player name that should used as the owner
 * @param cart  An ItemStack containing a cart item, will not be changed by
 *              the function
 * @param world The World object
 * @param x     x-Coord
 * @param y     y-Coord
 * @param z     z-Coord
 * @return the cart placed or null if failed
 * @see IMinecartItem, ItemMinecart
 */
public static EntityMinecart placeCart(GameProfile owner, ItemStack cart, WorldServer world, int x, int y, int z) {
    if (cart == null)
        return null;
    cart = cart.copy();
    if (cart.getItem() instanceof IMinecartItem) {
        IMinecartItem mi = (IMinecartItem) cart.getItem();
        return mi.placeCart(owner, cart, world, x, y, z);
    } else if (cart.getItem() instanceof ItemMinecart)
        try {
            boolean placed = cart.getItem().onItemUse(cart, FakePlayerFactory.get(world, railcraftProfile), world, x, y, z
                    , 0, 0, 0, 0);
            if (placed) {
                List<EntityMinecart> carts = getMinecartsAt(world, x, y, z, 0.3f);
                if (carts.size() > 0) {
                    setCartOwner(carts.get(0), owner);
                    return carts.get(0);
                }
            }
        } catch (Exception e) {
            return null;
        }

    return null;
}
 
开发者ID:Tonius,项目名称:NEI-Integration,代码行数:43,代码来源:CartTools.java

示例7: getHarvester

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
public static FakePlayer getHarvester() {
    if (harvester == null) {
        harvester = FakePlayerFactory.get(DimensionManager.getWorld(0), new GameProfile(new UUID(656, 123), "meecreps"));
    }
    // @todo config, make it possible to specify lesser pickaxe in config
    harvester.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.DIAMOND_PICKAXE));
    return harvester;
}
 
开发者ID:McJty,项目名称:MeeCreeps,代码行数:9,代码来源:GeneralTools.java

示例8: onDimensionUnload

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onDimensionUnload(WorldEvent.Unload event)
{
    ForgeChunkManager.unloadWorld(event.getWorld());
    if (event.getWorld() instanceof WorldServer)
        FakePlayerFactory.unloadWorld((WorldServer) event.getWorld());
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:8,代码来源:ForgeInternalHandler.java

示例9: getFakePlayer

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
public static final FakePlayer getFakePlayer() {
	if (player == null) {
		player = FakePlayerFactory.get(DimensionManager.getWorld(0), new GameProfile(UUID.randomUUID(), "RoyTheMiner"));
		LogUtils.info("Created fake player: " + player.getUniqueID() + " - " + player.getName());
	}
	return player;
}
 
开发者ID:cjburkey01,项目名称:MiningWells,代码行数:8,代码来源:FakePlayerHandler.java

示例10: onEntityCollidedWithBlock

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
@Override
public void onEntityCollidedWithBlock(final World world, final int x, final int y, final int z, final Entity target) {
    if (world.isRemote || !(world instanceof WorldServer)) {
        return;
    }
    final FakePlayer fakeplayer = FakePlayerFactory.getMinecraft((WorldServer)world);
    if (target instanceof EntityLivingBase) {
        final TileEntity tile = world.getTileEntity(x, y, z);
        final float damage = this.getDamageMultipliers(4.0f, tile, (EntityLivingBase)target);
        final float h = ((EntityLivingBase)target).getHealth();
        boolean flag = false;
        if (h > damage || target instanceof EntityPlayer) {
            flag = target.attackEntityFrom(DamageSource.cactus, damage);
        }
        else if (h > 0.5f) {
            flag = target.attackEntityFrom(DamageSource.generic, h - 0.001f);
        }
        else if (world.rand.nextInt(3) == 0) {
            flag = this.doPlayerLastHit(world, target, tile);
        }
        else {
            flag = target.attackEntityFrom(DamageSource.cactus, 40.0f);
        }
        if (flag) {
            this.doPostAttack(world, target, tile, x, y, z);
        }
    }
}
 
开发者ID:sameer,项目名称:ExtraUtilities,代码行数:29,代码来源:BlockSpikeGold.java

示例11: onEntityCollidedWithBlock

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
public void onEntityCollidedWithBlock(final World world, final int x, final int y, final int z, final Entity target) {
    if (world.isRemote || !(world instanceof WorldServer)) {
        return;
    }
    final FakePlayer fakeplayer = FakePlayerFactory.getMinecraft((WorldServer)world);
    if (!(target instanceof EntityLivingBase)) {
        return;
    }
    final TileEntity tile = world.getTileEntity(x, y, z);
    final float damage = this.getDamageMultipliers(4.0f, tile, (EntityLivingBase)target);
    final float h = ((EntityLivingBase)target).getHealth();
    boolean flag;
    if (h > damage || target instanceof EntityPlayer) {
        flag = target.attackEntityFrom(DamageSource.cactus, damage - 0.001f);
    }
    else if (world.rand.nextInt(5) == 0) {
        flag = this.doPlayerLastHit(world, target, tile);
    }
    else {
        flag = target.attackEntityFrom(DamageSource.cactus, 400.0f);
    }
    if (flag) {
        this.doPostAttack(world, target, tile, x, y, z);
        if (target instanceof EntityLiving) {
            try {
                BlockSpike.experienceField.setInt(target, 0);
            }
            catch (IllegalAccessException ex) {}
        }
    }
}
 
开发者ID:sameer,项目名称:ExtraUtilities,代码行数:32,代码来源:BlockSpike.java

示例12: getCrystalMod

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
private static FakePlayer getCrystalMod(WorldServer world)
{
    FakePlayer ret = CRYSTALMOD_PLAYER != null ? CRYSTALMOD_PLAYER.get() : null;
    if (ret == null)
    {
        ret = FakePlayerFactory.get(world, CRYSTALMOD);
        CRYSTALMOD_PLAYER = new WeakReference<FakePlayer>(ret);
    }
    return ret;
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:11,代码来源:FakePlayerUtil.java

示例13: onDimensionUnload

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onDimensionUnload(WorldEvent.Unload event)
{
    ForgeChunkManager.unloadWorld(event.world);
    if (event.world instanceof WorldServer)
        FakePlayerFactory.unloadWorld((WorldServer)event.world);
}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:8,代码来源:ForgeInternalHandler.java

示例14: getFakePlayer

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
@Nonnull
public FakePlayer getFakePlayer(@Nonnull WorldServer world) {
	FakePlayer player = fakePlayer.get();
	if (player == null) {
		player = FakePlayerFactory.get(world, fakePlayerProfile);
		fakePlayer = new WeakReference<>(player);
	}
	return player;
}
 
开发者ID:hea3ven,项目名称:CommonUtils,代码行数:10,代码来源:ProxyModBase.java

示例15: createNewPlayer

import net.minecraftforge.common.util.FakePlayerFactory; //导入依赖的package包/类
private static WeakReference<EntityPlayer> createNewPlayer(
		final WorldServer world, final int x, final int y, final int z) {
	final EntityPlayer player = FakePlayerFactory.get(world, profile);
	player.posX = x;
	player.posY = y;
	player.posZ = z;
	return new WeakReference<EntityPlayer>(player);
}
 
开发者ID:OreCruncher,项目名称:ThermalRecycling,代码行数:9,代码来源:FakePlayerHelper.java


注:本文中的net.minecraftforge.common.util.FakePlayerFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。