use of net.minecraft.server.world.ServerWorld in project Sprout by ThatGravyBoat.
the class SpreadShroomOrGrowWartGoal method tick.
@Override
public void tick() {
World world = bug.getWorld();
BounceBugVariant variant = bug.getBounceBugVariant();
if (!world.isClient)
((ServerWorld) world).spawnParticles(variant.particleEffect, bug.getX(), bug.getY(), bug.getZ(), 1, 0.1, 0.1, 0.1, 0);
// noinspection ConstantConditions
bug.lookAt(bug.getCommandSource().getEntityAnchor(), Vec3d.ofCenter(bug.getTargetPlant()));
if (isShroom && growTimer % 15 == 1) {
Box blocks = Box.from(Vec3d.ofCenter(shroomPos)).expand(2, 1, 2);
BlockPos.stream(blocks).filter(blockPos -> world.getBlockState(blockPos).isAir()).filter(blockPos -> mushroomPredicate(world.getBlockState(shroomPos), world.getBlockState(blockPos.down()), world, blockPos)).forEach(blockPos -> {
if (world.random.nextInt(30) == 1) {
if (!world.isClient)
((ServerWorld) world).spawnParticles(variant.particleEffect, blockPos.getX(), blockPos.getY(), blockPos.getZ(), 2, 0.1, 0.1, 0.1, 0.2);
world.setBlockState(blockPos, world.getBlockState(shroomPos).getBlock().getDefaultState());
}
});
} else if (!isShroom) {
Box blocks = Box.from(Vec3d.ofCenter(shroomPos)).expand(1, 1, 1);
BlockPos.stream(blocks).filter(blockPos -> world.getBlockState(blockPos).isOf(Blocks.NETHER_WART)).forEach(blockPos -> {
BlockState state = world.getBlockState(blockPos);
if (world.getRandom().nextInt(150) == 1) {
int age = state.get(NetherWartBlock.AGE);
if (age < NetherWartBlock.field_31199)
world.setBlockState(blockPos, state.with(NetherWartBlock.AGE, age + 1));
}
});
}
growTimer++;
}
use of net.minecraft.server.world.ServerWorld in project Sprout by ThatGravyBoat.
the class SprayWaterGoal method tick.
@Override
public void tick() {
super.tick();
if (sprayTimer < 10)
return;
// noinspection ConstantConditions
elephant.lookAt(elephant.getCommandSource().getEntityAnchor(), Vec3d.ofCenter(elephant.getTargetPlant()));
Box blockBox = new Box(plantPos.offset(elephant.getHorizontalFacing())).expand(1, 1, 1);
ServerWorld sWorld = (ServerWorld) elephant.world;
sWorld.spawnParticles(ParticleTypes.SPLASH, plantPos.getX(), plantPos.getY(), plantPos.getZ(), 10, 1, 1, 1, 1.4);
BlockPos.stream(blockBox).filter(blockPos -> elephant.world.getBlockState(blockPos).getBlock() instanceof CropBlock).forEach(blockPos -> {
if (elephant.world.getRandom().nextInt(150) == 1) {
BlockState crop = elephant.world.getBlockState(blockPos);
Fertilizable fertilizable = ((Fertilizable) crop.getBlock());
fertilizable.grow(sWorld, elephant.world.random, blockPos, crop);
}
});
BlockPos.stream(blockBox).filter(blockPos -> elephant.world.getBlockState(blockPos).getBlock() instanceof FarmlandBlock).forEach(blockPos -> {
BlockState blockState = sWorld.getBlockState(blockPos);
int moisture = blockState.get(Properties.MOISTURE);
if (elephant.world.getRandom().nextInt(15) == 1 && moisture < 7) {
elephant.world.setBlockState(blockPos, blockState.with(Properties.MOISTURE, 7));
}
});
}
use of net.minecraft.server.world.ServerWorld in project ProbablyChests by ReillyGregorio.
the class MobScarecrowBlock method onBreak.
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
BlockPos topPos;
BlockPos botPos;
// Get block position of both halves.
if (state.get(HALF) == DoubleBlockHalf.UPPER) {
topPos = pos;
botPos = pos.down();
} else {
topPos = pos.up();
botPos = pos;
}
// If block entity is of type mobscarecrow then spawn items at break position.
if (world.getBlockEntity(botPos) instanceof MobScarecrowBlockEntity) {
if (!player.isCreative() && player.canHarvest(world.getBlockState(botPos)) && world instanceof ServerWorld) {
if (!world.isClient) {
ItemStack itemStack = new ItemStack(state.getBlock().asItem());
ItemScatterer.spawn(world, (double) topPos.getX() + 0.5D, (double) topPos.getY() + 0.5D, (double) topPos.getZ() + 0.5D, itemStack);
}
}
world.removeBlockEntity(botPos);
}
// If block entity is of type mobscarecrow then remove top half.
if (world.getBlockEntity(topPos) instanceof MobScarecrowBlockEntity) {
world.removeBlockEntity(topPos);
}
// Remove blocks halves.
world.removeBlock(topPos, false);
world.removeBlock(botPos, false);
world.updateNeighbors(topPos, Blocks.AIR);
super.onBreak(world, pos, state, player);
}
use of net.minecraft.server.world.ServerWorld in project Carpet-TIS-Addition by TISUnion.
the class CommandBlockMixin method justExecuteRightNow.
@Inject(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/TickScheduler;schedule(Lnet/minecraft/util/math/BlockPos;Ljava/lang/Object;I)V"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void justExecuteRightNow(BlockState state, World world, BlockPos pos, Block block, BlockPos neighborPos, boolean moved, CallbackInfo ci, BlockEntity blockEntity, CommandBlockBlockEntity commandBlockBlockEntity) {
if (CarpetTISAdditionSettings.instantCommandBlock) {
if (world instanceof ServerWorld && commandBlockBlockEntity.getCommandBlockType() == CommandBlockBlockEntity.Type.REDSTONE) {
ServerWorld serverWorld = (ServerWorld) world;
Block blockBelow = world.getBlockState(pos.down()).getBlock();
if (blockBelow == Blocks.REDSTONE_ORE) {
ICommandBlockExecutor icbe = (ICommandBlockExecutor) commandBlockBlockEntity.getCommandExecutor();
icbe.setIgnoreWorldTimeCheck(true);
this.scheduledTick(state, serverWorld, pos, serverWorld.getRandom());
icbe.setIgnoreWorldTimeCheck(false);
ci.cancel();
}
}
}
}
use of net.minecraft.server.world.ServerWorld in project Carpet-TIS-Addition by TISUnion.
the class ServerWorldMixin method beforeBlockEventExecuted.
@Inject(method = "method_14174", at = @At("HEAD"))
private void beforeBlockEventExecuted(BlockAction blockAction, CallbackInfoReturnable<Boolean> cir) {
MicroTimingLoggerManager.setTickStageDetail((ServerWorld) (Object) this, String.valueOf(this.blockEventDepth));
MicroTimingLoggerManager.setSubTickStage((ServerWorld) (Object) this, new BlockEventSubStage((ServerWorld) (Object) this, blockAction, this.blockEventOrderCounter++, this.blockEventDepth));
}
Aggregations