本文整理汇总了Java中net.minecraftforge.common.util.FakePlayerFactory.getMinecraft方法的典型用法代码示例。如果您正苦于以下问题:Java FakePlayerFactory.getMinecraft方法的具体用法?Java FakePlayerFactory.getMinecraft怎么用?Java FakePlayerFactory.getMinecraft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.common.util.FakePlayerFactory
的用法示例。
在下文中一共展示了FakePlayerFactory.getMinecraft方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
}
示例4: 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) {}
}
}
}
示例5: getFakePlayer
import net.minecraftforge.common.util.FakePlayerFactory; //导入方法依赖的package包/类
@SuppressWarnings("null")
private @Nonnull EntityLivingBase getFakePlayer() {
if (fakePlayer == null) {
fakePlayer = FakePlayerFactory
.getMinecraft(FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(world.provider.getDimension()));
}
return fakePlayer;
}
示例6: harvestBlock
import net.minecraftforge.common.util.FakePlayerFactory; //导入方法依赖的package包/类
public boolean harvestBlock(final Block block, final int x, final int y, final int z, final int meta, final boolean replaceWithDirt, final DigType digType) {
final boolean isOpaque = block.isOpaqueCube();
final boolean seesSky = replaceWithDirt && isOpaque && this.worldObj.canBlockSeeTheSky(x, y + 1, z);
final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft((WorldServer)this.worldObj);
fakePlayer.setCurrentItemOrArmor(0, digType.newStack(Items.diamond_pickaxe));
try {
if (BlockBreakingRegistry.isSpecial(block)) {
EventHandlerEntityItemStealer.startCapture(true);
block.onBlockHarvested(this.worldObj, x, y, z, meta, (EntityPlayer)fakePlayer);
if (!block.removedByPlayer(this.worldObj, (EntityPlayer)fakePlayer, x, y, z, true)) {
this.items.addAll(EventHandlerEntityItemStealer.getCapturedItemStacks());
return false;
}
block.harvestBlock(this.worldObj, (EntityPlayer)fakePlayer, x, y, z, meta);
block.onBlockDestroyedByPlayer(this.worldObj, x, y, z, meta);
if (replaceWithDirt && isOpaque) {
this.worldObj.setBlock(x, y, z, (Block)(seesSky ? Blocks.grass : Blocks.dirt), 0, 3);
}
this.items.addAll(EventHandlerEntityItemStealer.getCapturedItemStacks());
}
else {
EventHandlerEntityItemStealer.startCapture(true);
final boolean flag = this.worldObj.setBlock(x, y, z, (Block)((replaceWithDirt && isOpaque) ? (seesSky ? Blocks.grass : Blocks.dirt) : Blocks.air), 0, 3);
this.items.addAll(EventHandlerEntityItemStealer.getCapturedItemStacks());
if (!flag) {
return false;
}
final ArrayList<ItemStack> i = new ArrayList<ItemStack>();
if (digType.isSilkTouch() && block.canSilkHarvest(this.worldObj, (EntityPlayer)fakePlayer, x, y, z, meta)) {
int j = 0;
final Item item = Item.getItemFromBlock(block);
if (item != null) {
if (item.getHasSubtypes()) {
j = meta;
}
final ItemStack itemstack = new ItemStack(item, 1, j);
i.add(itemstack);
}
}
else {
i.addAll(block.getDrops(this.worldObj, x, y, z, meta, digType.getFortuneModifier()));
}
final float p = ForgeEventFactory.fireBlockHarvesting((ArrayList)i, this.worldObj, block, x, y, z, meta, digType.getFortuneModifier(), 1.0f, digType.isSilkTouch(), (EntityPlayer)fakePlayer);
if (p > 0.0f && !i.isEmpty() && (p == 1.0f || TileEntityEnderQuarry.rand.nextFloat() < p)) {
this.items.addAll(i);
}
}
NetworkHandler.sendParticleEvent(this.worldObj, 0, x, y, z);
if (seesSky && TileEntityEnderQuarry.rand.nextInt(16) == 0 && this.worldObj.isAirBlock(x, y + 1, z)) {
if (TileEntityEnderQuarry.rand.nextInt(5) == 0) {
this.worldObj.getBiomeGenForCoords(x, z).plantFlower(this.worldObj, TileEntityEnderQuarry.rand, x, y + 1, z);
}
else if (TileEntityEnderQuarry.rand.nextInt(2) == 0) {
this.worldObj.setBlock(x, y + 1, z, (Block)Blocks.yellow_flower, TileEntityEnderQuarry.rand.nextInt(BlockFlower.field_149858_b.length), 3);
}
else {
this.worldObj.setBlock(x, y + 1, z, (Block)Blocks.red_flower, TileEntityEnderQuarry.rand.nextInt(BlockFlower.field_149859_a.length), 3);
}
}
return true;
}
finally {
fakePlayer.setCurrentItemOrArmor(0, (ItemStack)null);
}
}
示例7: getFakePlayer
import net.minecraftforge.common.util.FakePlayerFactory; //导入方法依赖的package包/类
public static FakePlayer getFakePlayer(World w) {
if (w instanceof WorldServer) return FakePlayerFactory.getMinecraft((WorldServer) w);
return null;
}
示例8: getUsingPlayer
import net.minecraftforge.common.util.FakePlayerFactory; //导入方法依赖的package包/类
/**
* Simulates a player using a bow to fire the arrow from the container
* Necessary to build a fake, since redstone doesn't identify source of change
*
* @param world where the dispenser is located
* @return a "fake" player
*/
protected EntityPlayer getUsingPlayer(World world){
return world instanceof WorldServer ? FakePlayerFactory.getMinecraft((WorldServer)world) : null;
}