Search in sources :

Example 6 with SpongeTicks

use of org.spongepowered.common.util.SpongeTicks in project SpongeCommon by SpongePowered.

the class PaintingData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(Painting.class).create(Keys.ART_TYPE).get(h -> (ArtType) h.motive).setAnd((h, v) -> {
        if (!h.level.isClientSide) {
            final Motive oldArt = h.motive;
            h.motive = (Motive) v;
            ((HangingEntityAccessor) h).invoker$setDirection(h.getDirection());
            if (!h.survives()) {
                h.motive = oldArt;
                ((HangingEntityAccessor) h).invoker$setDirection(h.getDirection());
                return false;
            }
            final ChunkMapAccessor chunkManager = (ChunkMapAccessor) ((ServerLevel) h.level).getChunkSource().chunkMap;
            final ChunkMap_TrackedEntityAccessor paintingTracker = chunkManager.accessor$entityMap().get(h.getId());
            if (paintingTracker == null) {
                return true;
            }
            final List<ServerPlayer> players = new ArrayList<>();
            for (final ServerPlayer player : paintingTracker.accessor$seenBy()) {
                final ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(h.getId());
                player.connection.send(packet);
                players.add(player);
            }
            for (final ServerPlayer player : players) {
                SpongeCommon.serverScheduler().submit(Task.builder().plugin(Launch.instance().commonPlugin()).delay(new SpongeTicks(SpongeGameConfigs.getForWorld(h.level).get().entity.painting.respawnDelay)).execute(() -> {
                    final ClientboundAddPaintingPacket packet = new ClientboundAddPaintingPacket(h);
                    player.connection.send(packet);
                }).build());
            }
            return true;
        }
        return true;
    });
}
Also used : ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) Painting(net.minecraft.world.entity.decoration.Painting) Launch(org.spongepowered.common.launch.Launch) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) SpongeGameConfigs(org.spongepowered.common.config.SpongeGameConfigs) SpongeCommon(org.spongepowered.common.SpongeCommon) ArtType(org.spongepowered.api.data.type.ArtType) ServerLevel(net.minecraft.server.level.ServerLevel) ArrayList(java.util.ArrayList) HangingEntityAccessor(org.spongepowered.common.accessor.world.entity.decoration.HangingEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) Keys(org.spongepowered.api.data.Keys) List(java.util.List) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) Task(org.spongepowered.api.scheduler.Task) SpongeTicks(org.spongepowered.common.util.SpongeTicks) Motive(net.minecraft.world.entity.decoration.Motive) ClientboundAddPaintingPacket(net.minecraft.network.protocol.game.ClientboundAddPaintingPacket) ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ClientboundAddPaintingPacket(net.minecraft.network.protocol.game.ClientboundAddPaintingPacket) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) ArrayList(java.util.ArrayList) Painting(net.minecraft.world.entity.decoration.Painting) HangingEntityAccessor(org.spongepowered.common.accessor.world.entity.decoration.HangingEntityAccessor) Motive(net.minecraft.world.entity.decoration.Motive) ArtType(org.spongepowered.api.data.type.ArtType) ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) SpongeTicks(org.spongepowered.common.util.SpongeTicks)

Example 7 with SpongeTicks

use of org.spongepowered.common.util.SpongeTicks in project SpongeCommon by SpongePowered.

the class EndermiteData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(Endermite.class).create(Keys.DESPAWN_DELAY).get(h -> {
        if (h.isPersistenceRequired()) {
            return null;
        }
        return new SpongeTicks(((EndermiteAccessor) h).accessor$life());
    }).setAnd((h, v) -> {
        if (h.isPersistenceRequired()) {
            return false;
        }
        final int ticks = (int) v.ticks();
        if (ticks < 0 || ticks > EndermiteData.DESPAWN_DELAY_MAX) {
            return false;
        }
        ((EndermiteAccessor) h).accessor$life(ticks);
        return true;
    });
}
Also used : Endermite(net.minecraft.world.entity.monster.Endermite) Endermite(net.minecraft.world.entity.monster.Endermite) Keys(org.spongepowered.api.data.Keys) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) SpongeTicks(org.spongepowered.common.util.SpongeTicks) EndermiteAccessor(org.spongepowered.common.accessor.world.entity.monster.EndermiteAccessor) EndermiteAccessor(org.spongepowered.common.accessor.world.entity.monster.EndermiteAccessor) SpongeTicks(org.spongepowered.common.util.SpongeTicks)

Example 8 with SpongeTicks

use of org.spongepowered.common.util.SpongeTicks in project SpongeCommon by SpongePowered.

the class SpongeRangedAttackAgainstAgentGoalBuilder method reset.

@Override
public RangedAttackAgainstAgentGoal.Builder reset() {
    // I'ma use Snowmen defaults. I like Snowmen.
    this.maxSpeed = 1.25D;
    this.delayBetweenAttacks = new SpongeTicks(20);
    this.attackRadius = 10.0f;
    return this;
}
Also used : SpongeTicks(org.spongepowered.common.util.SpongeTicks)

Aggregations

SpongeTicks (org.spongepowered.common.util.SpongeTicks)8 Keys (org.spongepowered.api.data.Keys)7 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)7 Constants (org.spongepowered.common.util.Constants)5 ResourceKey (org.spongepowered.api.ResourceKey)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 Value (org.spongepowered.api.data.value.Value)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 GsonComponentSerializer (net.kyori.adventure.text.serializer.gson.GsonComponentSerializer)1 Registry (net.minecraft.core.Registry)1 ClientboundAddPaintingPacket (net.minecraft.network.protocol.game.ClientboundAddPaintingPacket)1 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 AgableMob (net.minecraft.world.entity.AgableMob)1 Entity (net.minecraft.world.entity.Entity)1