use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class ForgeEventFactory method onMultiBlockPlace.
public static boolean onMultiBlockPlace(@Nullable Entity entity, List<BlockSnapshot> blockSnapshots, Direction direction) {
BlockSnapshot snap = blockSnapshots.get(0);
BlockState placedAgainst = snap.getLevel().getBlockState(snap.getPos().relative(direction.getOpposite()));
EntityMultiPlaceEvent event = new EntityMultiPlaceEvent(blockSnapshots, placedAgainst, entity);
return MinecraftForge.EVENT_BUS.post(event);
}
use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class ForgeEventFactory method fireSleepingLocationCheck.
public static boolean fireSleepingLocationCheck(LivingEntity player, BlockPos sleepingLocation) {
SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
MinecraftForge.EVENT_BUS.post(evt);
Result canContinueSleep = evt.getResult();
if (canContinueSleep == Result.DEFAULT) {
return player.getSleepingPos().map(pos -> {
BlockState state = player.level.getBlockState(pos);
return state.getBlock().isBed(state, player.level, pos, player);
}).orElse(false);
} else
return canContinueSleep == Result.ALLOW;
}
use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class FluidUtil method getFluidHandler.
/**
* Helper method to get an IFluidHandler for at a block position.
*/
public static LazyOptional<IFluidHandler> getFluidHandler(Level world, BlockPos blockPos, @Nullable Direction side) {
BlockState state = world.getBlockState(blockPos);
Block block = state.getBlock();
if (state.hasBlockEntity()) {
BlockEntity blockEntity = world.getBlockEntity(blockPos);
if (blockEntity != null) {
return blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
}
}
return LazyOptional.empty();
}
use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class FluidUtil method destroyBlockOnFluidPlacement.
/**
* Destroys a block when a fluid is placed in the same position.
* Modeled after {@link BucketItem#emptyContents(Player, Level, BlockPos, BlockHitResult)}
*
* This is a helper method for implementing {@link IFluidBlock#place(Level, BlockPos, FluidStack, IFluidHandler.FluidAction)}.
*
* @param world the world that the fluid will be placed in
* @param pos the location that the fluid will be placed
*/
public static void destroyBlockOnFluidPlacement(Level world, BlockPos pos) {
if (!world.isClientSide) {
BlockState destBlockState = world.getBlockState(pos);
Material destMaterial = destBlockState.getMaterial();
boolean isDestNonSolid = !destMaterial.isSolid();
// TODO: Needs BlockItemUseContext destBlockState.getBlock().isReplaceable(world, pos);
boolean isDestReplaceable = false;
if ((isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid()) {
world.destroyBlock(pos, true);
}
}
}
use of net.minecraft.world.level.block.state.BlockState in project MyPet by xXKeyleXx.
the class EntityMyZombieHorse method playStepSound.
@Override
public void playStepSound(BlockPos blockposition, BlockState blockdata) {
if (!blockdata.getMaterial().isLiquid()) {
BlockState blockdataUp = this.level.getBlockState(blockposition.up());
SoundType soundeffecttype = blockdata.getSoundType();
if (blockdataUp.getBlock() == Blocks.SNOW) {
soundeffecttype = blockdata.getSoundType();
}
if (this.isVehicle()) {
++this.soundCounter;
if (this.soundCounter > 5 && this.soundCounter % 3 == 0) {
this.playSound(SoundEvents.HORSE_GALLOP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
} else if (this.soundCounter <= 5) {
this.playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
}
} else if (!blockdata.getMaterial().isLiquid()) {
this.soundCounter += 1;
playSound(SoundEvents.HORSE_STEP_WOOD, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
} else {
playSound(SoundEvents.HORSE_STEP, soundeffecttype.getVolume() * 0.15F, soundeffecttype.getPitch());
}
}
}
Aggregations