Search in sources :

Example 21 with ServerWorld

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++;
}
Also used : BounceBugVariant(com.toadstoolstudios.sprout.entities.BounceBugVariant) BounceBugEntity(com.toadstoolstudios.sprout.entities.BounceBugEntity) Goal(net.minecraft.entity.ai.goal.Goal) Vec3d(net.minecraft.util.math.Vec3d) net.minecraft.block(net.minecraft.block) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) Box(net.minecraft.util.math.Box) BlockPos(net.minecraft.util.math.BlockPos) BlockTags(net.minecraft.tag.BlockTags) BounceBugVariant(com.toadstoolstudios.sprout.entities.BounceBugVariant) Box(net.minecraft.util.math.Box) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld)

Example 22 with ServerWorld

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));
        }
    });
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) ServerWorld(net.minecraft.server.world.ServerWorld) Box(net.minecraft.util.math.Box) ElephantEntity(com.toadstoolstudios.sprout.entities.ElephantEntity) CropBlock(net.minecraft.block.CropBlock) Fertilizable(net.minecraft.block.Fertilizable) BlockPos(net.minecraft.util.math.BlockPos) Properties(net.minecraft.state.property.Properties) Goal(net.minecraft.entity.ai.goal.Goal) Vec3d(net.minecraft.util.math.Vec3d) ParticleTypes(net.minecraft.particle.ParticleTypes) FarmlandBlock(net.minecraft.block.FarmlandBlock) BlockState(net.minecraft.block.BlockState) EnumSet(java.util.EnumSet) BlockState(net.minecraft.block.BlockState) Box(net.minecraft.util.math.Box) CropBlock(net.minecraft.block.CropBlock) FarmlandBlock(net.minecraft.block.FarmlandBlock) Fertilizable(net.minecraft.block.Fertilizable)

Example 23 with ServerWorld

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);
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) MobScarecrowBlockEntity(org.cloudwarp.probablychests.blockentities.MobScarecrowBlockEntity)

Example 24 with ServerWorld

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();
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) ICommandBlockExecutor(carpettisaddition.helpers.rule.instantCommandBlock.ICommandBlockExecutor) CommandBlock(net.minecraft.block.CommandBlock) Block(net.minecraft.block.Block) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 25 with ServerWorld

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));
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) BlockEventSubStage(carpettisaddition.logging.loggers.microtiming.tickphase.substages.BlockEventSubStage) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ServerWorld (net.minecraft.server.world.ServerWorld)210 BlockPos (net.minecraft.util.math.BlockPos)102 ItemStack (net.minecraft.item.ItemStack)47 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)38 Vec3d (net.minecraft.util.math.Vec3d)33 World (net.minecraft.world.World)33 BlockState (net.minecraft.block.BlockState)28 Direction (net.minecraft.util.math.Direction)23 Entity (net.minecraft.entity.Entity)21 Random (java.util.Random)20 Block (net.minecraft.block.Block)20 PlayerEntity (net.minecraft.entity.player.PlayerEntity)19 Inject (org.spongepowered.asm.mixin.injection.Inject)18 List (java.util.List)16 DispenserBlock (net.minecraft.block.DispenserBlock)16 Box (net.minecraft.util.math.Box)16 ChunkPos (net.minecraft.util.math.ChunkPos)16 LivingEntity (net.minecraft.entity.LivingEntity)13 BlockEntity (net.minecraft.block.entity.BlockEntity)11 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)11