本文整理汇总了Java中net.minecraftforge.common.IPlantable类的典型用法代码示例。如果您正苦于以下问题:Java IPlantable类的具体用法?Java IPlantable怎么用?Java IPlantable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPlantable类属于net.minecraftforge.common包,在下文中一共展示了IPlantable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: plantAll
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
private void plantAll(List<EntityItem> items, World world, BlockPos pos, int amplifier) {
int box = 1 + (int) ((float) amplifier / 2F);
BlockPos posI = pos.add(box, 1, box);
BlockPos posF = pos.add(-box, -1, -box);
Iterable<BlockPos> spots = BlockPos.getAllInBox(posI, posF);
for (EntityItem item : items) {
ItemStack stack = item.getItem();
for (BlockPos spot : spots) {
if (stack.isEmpty()) {
item.setDead();
break;
}
IBlockState state = world.getBlockState(spot);
IPlantable seed = (IPlantable) stack.getItem();
if (world.isAirBlock(spot.up()) && state.getBlock().canSustainPlant(state, world, spot, EnumFacing.UP, seed)) {
world.setBlockState(spot.up(), seed.getPlant(world, spot.up()));
stack.shrink(1);
}
}
}
}
示例2: replant
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
private void replant(BlockPos pos) {
IMeeCreep entity = helper.getMeeCreep();
World world = entity.getWorld();
Block block = needToReplant.get(pos);
needToReplant.remove(pos);
for (ItemStack stack : entity.getInventory()) {
if (stack.getItem() instanceof IPlantable) {
IBlockState plant = ((IPlantable) stack.getItem()).getPlant(world, pos);
if (plant.getBlock() == block) {
// This is a valid seed
stack.splitStack(1);
world.setBlockState(pos, plant);
break;
}
}
}
}
示例3: hasSuitableSeed
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
private BlockPos hasSuitableSeed() {
IMeeCreep entity = helper.getMeeCreep();
World world = entity.getWorld();
for (Map.Entry<BlockPos, Block> entry : needToReplant.entrySet()) {
BlockPos pos = entry.getKey();
Block block = entry.getValue();
for (ItemStack stack : entity.getInventory()) {
if (stack.getItem() instanceof IPlantable) {
IBlockState plant = ((IPlantable) stack.getItem()).getPlant(world, pos);
if (plant.getBlock() == block) {
// This is a valid seed
return pos;
}
}
}
}
return null;
}
示例4: onItemUse
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.isEmpty()) {
return super.onItemUse(playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
System.out.println(this.getSaplingState());
if (facing == EnumFacing.UP && playerIn.canPlayerEdit(pos.offset(facing), facing, heldItem) && worldIn.isAirBlock(pos.up()) && worldIn.getBlockState(pos).getBlock().canSustainPlant(worldIn.getBlockState(pos), worldIn, pos, facing, (IPlantable) this.getSaplingState().getBlock())) {
worldIn.setBlockState(pos.up(), this.getSaplingState());
worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 1F, 1F);
heldItem.shrink(1);
return EnumActionResult.SUCCESS;
} else {
if (playerIn.canPlayerEdit(pos.offset(facing), facing, heldItem) && worldIn.isAirBlock(pos.up()) && worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos)) {
worldIn.setBlockState(pos, this.getSaplingState());
worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 1F, 1F);
heldItem.shrink(1);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}
}
示例5: tryBlockClient
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
private boolean tryBlockClient(int x, int y, int z)
{
BlockVec3 bv = new BlockVec3(x, y, z);
if (this.laserBlocks.contains(bv)) return false;
//Add minable blocks to the laser fx list
Block b = this.worldObj.getBlock(x, y, z);
if (b.getMaterial() == Material.air) return false;
if (noMineList.contains(b)) return true;
if (b instanceof BlockLiquid) return false;
if (b instanceof IFluidBlock) return false;
if (b instanceof IPlantable) return true;
int meta = this.worldObj.getBlockMetadata(x, y, z);
if (b.hasTileEntity(meta) || b.getBlockHardness(this.worldObj, x, y, z) < 0) return true;
if (this.tryBlockLimit == 0) return false;
this.tryBlockLimit--;
this.laserBlocks.add(bv);
this.laserTimes.add(this.ticksExisted);
return false;
}
示例6: isSeed
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
public static boolean isSeed(ItemStack stack, boolean ignoreCrops){
if(ItemStackTools.isNullStack(stack))return false;
if(!ignoreCrops){
Block bi = Block.getBlockFromItem(stack.getItem());
if(bi !=null){
if ((getCrops(CropType.NORMAL).contains(bi.getUnlocalizedName() + stack.getItemDamage())) || (getCrops(CropType.CLICKABLE).contains(bi.getUnlocalizedName() + stack.getItemDamage())) || (getCrops(CropType.STACKED).contains(bi.getUnlocalizedName() + stack.getItemDamage())))
{
return true;
}
}
}
boolean found = false;
for (int a = 0; a < 16; a++) {
if ((seeds.contains(stack.getItem().getRegistryName().toString() + "|" + a)))
{
found = true;
break;
}
}
if((stack.getItem() instanceof IPlantable) || found || (seeds.contains(stack.getItem().getRegistryName().toString() + "|" + stack.getItemDamage()))){
return true;
}
return false;
}
示例7: run
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@Override
public boolean run(@Nonnull SpellData spell) {
World world = spell.world;
BlockPos targetPos = spell.getData(BLOCK_HIT);
Entity targetEntity = spell.getData(ENTITY_HIT);
Entity caster = spell.getData(CASTER);
Vec3d pos = spell.getData(TARGET_HIT);
if (pos != null)
spell.world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1);
if (targetEntity instanceof EntityLivingBase) {
double strength = getModifier(spell, Attributes.POTENCY, 3, 20) / 10.0;
if (!tax(this, spell)) return false;
((EntityLivingBase) targetEntity).heal((float) strength);
}
if (targetPos != null) {
if (world.getBlockState(targetPos).getBlock() instanceof IGrowable) {
if (!tax(this, spell)) return false;
if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster)))
ItemDye.applyBonemeal(new ItemStack(Items.DYE), world, targetPos);
} else if (world.getBlockState(targetPos).getBlock() instanceof IPlantable) {
IBlockState state = world.getBlockState(targetPos);
Block block = state.getBlock();
if (!tax(this, spell)) return false;
if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster))) {
while (world.getBlockState(targetPos.up()).getBlock() == block) {
targetPos = targetPos.up();
state = world.getBlockState(targetPos);
block = state.getBlock();
}
world.immediateBlockTick(targetPos, state, RandUtil.random);
}
}
}
return true;
}
示例8: canPlant
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@Override
public boolean canPlant(World world, BlockPos pos) {
if (ItemStackUtil.isEmpty(this.stack)) {
return false;
}
Item item = this.stack.getItem();
Object rawPlantable = (item instanceof ItemBlock) ? ((ItemBlock) item).getBlock() : item;
IPlantable plantable = (rawPlantable instanceof IPlantable) ? (IPlantable)rawPlantable : null;
if (plantable == null) {
return false;
}
IBlockState down = world.getBlockState(pos.down());
return down.getBlock().canSustainPlant(down, world, pos.down(), EnumFacing.UP, plantable);
}
示例9: poisonousPotatoRightClick
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@SubscribeEvent
public void poisonousPotatoRightClick(RightClickBlock event)
{
EntityPlayer player = event.getEntityPlayer();
World world = event.getWorld();
if((event.getEntityPlayer().getHeldItemMainhand()!=null)
&&(player.getHeldItemMainhand().getItem()==Items.POISONOUS_POTATO)
&&(event.getFace()==EnumFacing.UP)
&&world.getBlockState(event.getPos()).getBlock().canSustainPlant(world.getBlockState(event.getPos()), world, event.getPos(), EnumFacing.UP, (IPlantable) Items.POTATO))
{
if(!world.isRemote)
{
if(!player.capabilities.isCreativeMode)
{
player.inventory.clearMatchingItems(Items.POISONOUS_POTATO, -1, 1, null);
}
if(world.getBlockState(event.getPos().up(+1)).getBlock()==Blocks.AIR)
{
world.setBlockState(event.getPos().up(+1),Blocks.POTATOES.getDefaultState());
}
}
}
}
示例10: canSustainPlant
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) {
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
switch (plantType) {
case Crop:
case Plains:
return true;
case Desert:
case Nether:
case Cave:
case Water:
case Beach:
default:
return false;
}
}
示例11: updateTick
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
/*******************************************************************************
* 1. Content
*******************************************************************************/
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
{
if(world.isRemote)
return;
if(!(world.getBlockState(pos.up()).getBlock() instanceof IPlantable))
{
if(!isFertile(world, pos) && rand.nextInt(100) == 0)
{
world.setBlockState(pos, TFCBlocks.Dirt.getDefaultState().withProperty(META_PROPERTY, state.getValue(META_PROPERTY)));
}
}
}
示例12: canSustainPlant
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
if(plantType == EnumPlantType.Crop)
return true;
if(plantType == EnumPlantType.Plains)
return true;
if(plantable == TFCBlocks.Sapling)
return true;
return false;
}
示例13: canSustainPlant
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
VegType veg = (VegType)state.getValue(META_PROPERTY);
if(plant.getBlock() == this)
{
if(veg == VegType.DoubleGrassBottom && plant.getValue(META_PROPERTY) == VegType.DoubleGrassTop)
return true;
if(veg == VegType.DoubleGrassBottomLush && plant.getValue(META_PROPERTY) == VegType.DoubleGrassTopLush)
return true;
}
return false;
}
示例14: canSustainPlant
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
if(plant.getBlock() == Blocks.SAPLING)
return false;//This may break some cross mod compatability but for now its needed to prevent vanilla and some pam trees from generating
if(plantType == EnumPlantType.Plains)
return true;
if(plant.getBlock() == TFCBlocks.VegDesert)
return true;
return false;
}
示例15: useSeedBag
import net.minecraftforge.common.IPlantable; //导入依赖的package包/类
static EnumActionResult useSeedBag(EntityPlayer player, World world, BlockPos pos, EnumHand hand, @Nonnull ItemStack heldStack, EnumFacing facing) {
if (player.isSneaking()) return EnumActionResult.PASS;
SeedBagInventory seedBagInventory = new SeedBagInventory(heldStack);
ItemStack seedStack = seedBagInventory.getStackInSlot(0);
if (!seedStack.isEmpty() && seedStack.getItem() instanceof IPlantable) {
IPlantable plantable = (IPlantable) seedStack.getItem();
IBlockState state = world.getBlockState(pos);
if (state.getBlock().canSustainPlant(state, world, pos, EnumFacing.UP, plantable) && world.isAirBlock(pos.up())) {
seedBagInventory.decrStackSize(0, 1);
ItemStack before = heldStack.copy();
player.setHeldItem(hand, seedStack);
seedStack.onItemUse(player, world, pos, hand, facing, 0, 0, 0);
player.setHeldItem(hand, before);
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}