Search in sources :

Example 1 with BlockGrass

use of net.minecraft.block.BlockGrass in project SpongeCommon by SpongePowered.

the class MixinBlock method onConstruction.

@Inject(method = "<init>*", at = @At("RETURN"))
public void onConstruction(CallbackInfo ci) {
    // Determine which blocks can avoid executing un-needed event logic
    // This will allow us to avoid running event logic for blocks that do nothing such as grass collisions
    // -- blood
    this.hasCollideLogic = true;
    this.hasCollideWithStateLogic = true;
    // onEntityCollidedWithBlock
    try {
        String mapping = SpongeImplHooks.isDeobfuscatedEnvironment() ? "onEntityWalk" : "func_176199_a";
        Class<?>[] argTypes = { net.minecraft.world.World.class, BlockPos.class, Entity.class };
        Class<?> clazz = this.getClass().getMethod(mapping, argTypes).getDeclaringClass();
        if (clazz.equals(Block.class)) {
            this.hasCollideLogic = false;
        }
    } catch (Throwable ex) {
    // ignore
    }
    // onEntityCollidedWithBlock (IBlockState)
    try {
        String mapping = SpongeImplHooks.isDeobfuscatedEnvironment() ? "onEntityCollidedWithBlock" : "func_180634_a";
        Class<?>[] argTypes = { net.minecraft.world.World.class, BlockPos.class, IBlockState.class, Entity.class };
        Class<?> clazz = this.getClass().getMethod(mapping, argTypes).getDeclaringClass();
        if (clazz.equals(Block.class)) {
            this.hasCollideWithStateLogic = false;
        }
    } catch (Throwable ex) {
    // ignore
    }
    Block block = (Block) (Object) this;
    if (block instanceof BlockLeaves || block instanceof BlockLog || block instanceof BlockGrass || block instanceof BlockLiquid) {
        this.requiresBlockCapture = false;
    }
}
Also used : BlockLeaves(net.minecraft.block.BlockLeaves) BlockLiquid(net.minecraft.block.BlockLiquid) BlockGrass(net.minecraft.block.BlockGrass) Block(net.minecraft.block.Block) IMixinBlock(org.spongepowered.common.interfaces.block.IMixinBlock) BlockLog(net.minecraft.block.BlockLog) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with BlockGrass

use of net.minecraft.block.BlockGrass in project BiomesOPlenty by Glitchfiend.

the class EntityAIEatBOPGrass method shouldExecute.

@Override
public boolean shouldExecute() {
    if (this.sheep.getRNG().nextInt(this.sheep.isChild() ? 50 : 1000) != 0) {
        return false;
    } else {
        BlockPos pos = new BlockPos(this.sheep.posX, this.sheep.posY, this.sheep.posZ);
        IBlockState state = this.world.getBlockState(pos);
        return IS_TALL_GRASS.apply(state) || IS_SHORT_GRASS.apply(state) || IS_MEDIUM_GRASS.apply(state) || IS_WHEAT_GRASS.apply(state) || IS_DAMP_GRASS.apply(state) || this.world.getBlockState(pos.down()).getBlock() instanceof BlockGrass;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockGrass(net.minecraft.block.BlockGrass) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with BlockGrass

use of net.minecraft.block.BlockGrass in project harvestcraft by MatrexsVigil.

the class TileEntityGroundTrap method countFlowers.

public int countFlowers() {
    byte radius = 2;
    int count = 0;
    // final World world = world;
    final int varX = pos.getX();
    final int varY = pos.getY();
    final int varZ = pos.getZ();
    for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
        for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
            if (offsetX * offsetX + offsetZ * offsetZ <= radius * radius && (offsetX != -(radius - 1) || offsetZ != -(radius - 1)) && (offsetX != radius - 1 || offsetZ != radius - 1) && (offsetX != radius - 1 || offsetZ != -(radius - 1)) && (offsetX != -(radius - 1) || offsetZ != radius - 1)) {
                final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
                if (!world.isBlockLoaded(pos))
                    continue;
                final Block blockAtCoords = world.getBlockState(pos).getBlock();
                if (blockAtCoords instanceof BlockDirt || blockAtCoords instanceof BlockGrass) {
                    count++;
                }
            }
        }
    }
    return count;
}
Also used : BlockGrass(net.minecraft.block.BlockGrass) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockDirt(net.minecraft.block.BlockDirt)

Example 4 with BlockGrass

use of net.minecraft.block.BlockGrass in project harvestcraft by MatrexsVigil.

the class TileEntityGroundTrap method getRunTime.

private int getRunTime() {
    final int radius = 2;
    // final World world = world;
    final int varX = pos.getX();
    final int varY = pos.getY();
    final int varZ = pos.getZ();
    int speed = 3500;
    for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
        for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
            if (offsetX * offsetX + offsetZ * offsetZ > radius * radius || offsetX == -radius - 1 && offsetZ == -radius - 1 || offsetX == radius - 1 && offsetZ == radius - 1 || offsetX == radius - 1 && offsetZ == -radius - 1 || offsetX == -radius - 1 && offsetZ == radius - 1)
                continue;
            final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
            if (!world.isBlockLoaded(pos))
                continue;
            final Block blockAtCoords = world.getBlockState(pos).getBlock();
            if (blockAtCoords instanceof BlockDirt || blockAtCoords instanceof BlockGrass) {
                speed = (int) (speed * 0.95);
            }
            if (blockAtCoords != BlockRegistry.groundtrap)
                continue;
            speed = (int) (speed / 0.85);
        }
    }
    return speed;
}
Also used : BlockGrass(net.minecraft.block.BlockGrass) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockDirt(net.minecraft.block.BlockDirt)

Aggregations

BlockGrass (net.minecraft.block.BlockGrass)4 Block (net.minecraft.block.Block)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockDirt (net.minecraft.block.BlockDirt)2 BlockLeaves (net.minecraft.block.BlockLeaves)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 BlockLog (net.minecraft.block.BlockLog)1 IBlockState (net.minecraft.block.state.IBlockState)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 IMixinBlock (org.spongepowered.common.interfaces.block.IMixinBlock)1