Search in sources :

Example 16 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project MyPet by xXKeyleXx.

the class EntityMyEnderDragon method onLivingUpdate.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void onLivingUpdate() {
    super.onLivingUpdate();
    if (Configuration.MyPet.EnderDragon.CAN_GLIDE) {
        if (!this.onGround && this.getDeltaMovement().y() < 0.0D) {
            this.setDeltaMovement(getDeltaMovement().multiply(1, 0.6D, 1));
        }
    }
    if (!registered && this.valid) {
        // I HATE ALL OF THIS - Thank you Spigot vs Paper
        if (this.getCommandSenderWorld() instanceof ServerLevel) {
            ServerLevel world = (ServerLevel) this.getCommandSenderWorld();
            // The next part used to be prettier but... whilst it is listed everywhere I looked, world.dragonParts is just not... available?
            // Mojang Field: dragonParts
            Field dragonPartsField = ReflectionUtil.getField(ServerLevel.class, "R");
            var dragonParts = ReflectionUtil.getFieldValue(dragonPartsField, world);
            try {
                Method putMethod = leClass.getDeclaredMethod("put", Integer.class, Object.class);
                Arrays.stream(this.children).forEach(entityMyPetPart -> {
                    try {
                        putMethod.invoke(leClass.cast(dragonParts), entityMyPetPart.getId(), entityMyPetPart);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
                ReflectionUtil.setFieldValue(dragonPartsField, world, leClass.cast(dragonParts));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        this.registered = true;
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Field(java.lang.reflect.Field) Method(java.lang.reflect.Method)

Example 17 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project MyPet by xXKeyleXx.

the class PlatformHelper method strikeLightning.

@Override
public void strikeLightning(Location loc, float distance) {
    ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle();
    LightningBolt lightning = new LightningBolt(EntityType.LIGHTNING_BOLT, world);
    lightning.setVisualOnly(true);
    lightning.moveTo(loc.getX(), loc.getY(), loc.getZ(), 0.0F, 0.0F);
    /*world.getCraftServer()
                .getServer()
                .getPlayerList()
                .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(),
                        new ClientboundAddEntityPacket(lightning));
        world.getCraftServer()
                .getServer()
                .getPlayerList()
                .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(),
                        new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F));
        */
    // Thank you wrong mappings for this workaround
    DedicatedServer server = world.getCraftServer().getServer();
    Method getPlayerListReflect = ReflectionUtil.getMethod(DedicatedServer.class, "getPlayerList");
    try {
        DedicatedPlayerList playerList = (DedicatedPlayerList) getPlayerListReflect.invoke(server, null);
        playerList.broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundAddEntityPacket(lightning));
        playerList.broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LightningBolt(net.minecraft.world.entity.LightningBolt) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) DedicatedPlayerList(net.minecraft.server.dedicated.DedicatedPlayerList) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) Method(java.lang.reflect.Method) ClientboundSoundPacket(net.minecraft.network.protocol.game.ClientboundSoundPacket) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) InvocationTargetException(java.lang.reflect.InvocationTargetException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 18 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class SpongeCommand method getChunksInfo.

// --
protected Component getChunksInfo(final ServerWorld serverWorld) {
    if (((LevelBridge) serverWorld).bridge$isFake()) {
        return Component.text().append(Component.newline(), Component.text(serverWorld.key().asString() + " is a fake world")).build();
    }
    final ServerLevel serverLevel = (ServerLevel) serverWorld;
    final int entitiesToRemove = (int) serverWorld.entities().stream().filter(x -> ((Entity) x).removed).count();
    return LinearComponents.linear(this.key("Loaded chunks: "), this.value(serverLevel.getChunkSource().chunkMap.size()), Component.newline(), this.key("Entities: "), this.value(serverWorld.entities().size()), Component.newline(), this.key("Block Entities: "), this.value(serverWorld.blockEntities().size()), Component.newline(), this.key("Removed Entities:"), this.value(entitiesToRemove), Component.newline(), this.key("Removed Block Entities: "), this.value(((LevelBridge) serverLevel).bridge$blockEntitiesToUnload().size()));
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge)

Example 19 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class MinecraftServerMixin_API method serverScoreboard.

@Override
public Optional<Scoreboard> serverScoreboard() {
    if (this.api$scoreboard == null) {
        final ServerLevel world = SpongeCommon.server().overworld();
        if (world == null) {
            return Optional.empty();
        }
        this.api$scoreboard = world.getScoreboard();
    }
    return Optional.of((Scoreboard) this.api$scoreboard);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel)

Example 20 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class EntityMixin method bridge$setPosition.

@Override
public boolean bridge$setPosition(final Vector3d position) {
    if (this.removed) {
        return false;
    }
    try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
        frame.addContext(EventContextKeys.MOVEMENT_TYPE, MovementTypes.PLUGIN);
        final Vector3d destinationPosition = this.impl$fireMoveEvent(PhaseTracker.SERVER, position);
        if (destinationPosition == null) {
            return false;
        }
        final ServerLevel level = (ServerLevel) this.level;
        return this.impl$setLocation(false, level, level, destinationPosition);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Vector3d(org.spongepowered.math.vector.Vector3d) CauseStackManager(org.spongepowered.api.event.CauseStackManager)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)115 BlockPos (net.minecraft.core.BlockPos)30 Nullable (org.checkerframework.checker.nullness.qual.Nullable)21 Level (net.minecraft.world.level.Level)20 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)16 Entity (net.minecraft.world.entity.Entity)14 ServerPlayer (net.minecraft.server.level.ServerPlayer)11 ItemStack (net.minecraft.world.item.ItemStack)10 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)10 IOException (java.io.IOException)9 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)9 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)9 ArrayList (java.util.ArrayList)8 BlockState (net.minecraft.world.level.block.state.BlockState)8 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Vec3 (net.minecraft.world.phys.Vec3)7 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)7 Cause (org.spongepowered.api.event.Cause)7