本文整理汇总了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);
}
}
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
}
}
示例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) {}
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}