Search in sources :

Example 26 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project Carpet-TIS-Addition by TISUnion.

the class ServerWorldMixin method beforeExecuteTileTickEvent.

@Inject(method = { "tickBlock", "tickFluid" }, at = @At("HEAD"))
private void beforeExecuteTileTickEvent(ScheduledTick<?> event, CallbackInfo ci) {
    MicroTimingLoggerManager.setTickStageDetail((ServerWorld) (Object) this, String.valueOf(event.priority.getIndex()));
    MicroTimingLoggerManager.setSubTickStage((ServerWorld) (Object) this, new TileTickSubStage((ServerWorld) (Object) this, event, this.tileTickOrderCounter++));
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) TileTickSubStage(carpettisaddition.logging.loggers.microtiming.tickphase.substages.TileTickSubStage) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 27 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project Carpet-TIS-Addition by TISUnion.

the class EntityMixin method onConstructLifeTimeTracker.

@Inject(method = "<init>", at = @At("TAIL"))
private void onConstructLifeTimeTracker(CallbackInfo ci) {
    this.recordedSpawning = false;
    this.recordedRemoval = false;
    if (this.world instanceof ServerWorld) {
        // In case the entity is loaded when the world is being constructed
        // Not sure if it's possible in vanilla, at least it happens in #29
        LifeTimeWorldTracker tracker = ((ServerWorldWithLifeTimeTracker) this.world).getLifeTimeWorldTracker();
        if (tracker != null) {
            // do track
            this.spawnTime = tracker.getSpawnStageCounter();
            this.trackId = LifeTimeTracker.getInstance().getCurrentTrackId();
            this.doLifeTimeTracking = LifeTimeTracker.getInstance().willTrackEntity((Entity) (Object) this);
            return;
        }
    }
    // dont track
    this.trackId = -1;
    this.doLifeTimeTracking = false;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Entity(net.minecraft.entity.Entity) MobEntity(net.minecraft.entity.mob.MobEntity) LifeTimeWorldTracker(carpettisaddition.commands.lifetime.LifeTimeWorldTracker) ServerWorldWithLifeTimeTracker(carpettisaddition.commands.lifetime.interfaces.ServerWorldWithLifeTimeTracker) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 28 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project Carpet-TIS-Addition by TISUnion.

the class InfoCommand method showMoreBlockInfo.

public Collection<BaseText> showMoreBlockInfo(BlockPos pos, World world) {
    if (!(world instanceof ServerWorld)) {
        return Collections.emptyList();
    }
    List<BaseText> result = Lists.newArrayList();
    BlockBox bound = new BlockBox(pos, pos.add(1, 1, 1));
    List<ScheduledTick<Block>> blockTileTicks = ((ServerTickScheduler<Block>) world.getBlockTickScheduler()).getScheduledTicks(bound, false, false);
    List<ScheduledTick<Fluid>> liquidTileTicks = ((ServerTickScheduler<Fluid>) world.getFluidTickScheduler()).getScheduledTicks(bound, false, false);
    this.appendTileTickInfo(result, blockTileTicks, "Block Tile ticks", world.getTime(), Messenger::block);
    this.appendTileTickInfo(result, liquidTileTicks, "Fluid Tile ticks", world.getTime(), Messenger::fluid);
    List<BlockAction> blockEvents = ((ServerWorldAccessor) world).getPendingBlockActions().stream().filter(be -> be.getPos().equals(pos)).collect(Collectors.toList());
    this.appendBlockEventInfo(result, blockEvents);
    return result;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) BaseText(net.minecraft.text.BaseText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ServerWorld(net.minecraft.server.world.ServerWorld) ServerTickScheduler(net.minecraft.server.world.ServerTickScheduler) Function(java.util.function.Function) CommandExtender(carpettisaddition.commands.CommandExtender) DimensionWrapper(carpettisaddition.utils.compat.DimensionWrapper) BaseText(net.minecraft.text.BaseText) Lists(com.google.common.collect.Lists) Block(net.minecraft.block.Block) CarpetTISAdditionServer(carpettisaddition.CarpetTISAdditionServer) AbstractCommand(carpettisaddition.commands.AbstractCommand) Messenger(carpettisaddition.utils.Messenger) World(net.minecraft.world.World) Collection(java.util.Collection) BlockPos(net.minecraft.util.math.BlockPos) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) Collectors(java.util.stream.Collectors) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) ScheduledTick(net.minecraft.world.ScheduledTick) BlockAction(net.minecraft.server.world.BlockAction) List(java.util.List) BlockBox(net.minecraft.util.math.BlockBox) ServerWorldAccessor(carpettisaddition.mixins.command.info.ServerWorldAccessor) Fluid(net.minecraft.fluid.Fluid) Collections(java.util.Collections) ScheduledTick(net.minecraft.world.ScheduledTick) BlockAction(net.minecraft.server.world.BlockAction) BlockBox(net.minecraft.util.math.BlockBox) ServerTickScheduler(net.minecraft.server.world.ServerTickScheduler) Messenger(carpettisaddition.utils.Messenger)

Example 29 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project Carpet-TIS-Addition by TISUnion.

the class TileEntityListController method showStatistic.

private int showStatistic(ServerCommandSource source) {
    ServerWorld world = source.getWorld();
    Messenger.tell(source, Messenger.format("===== %1$s =====", tr("statistic.title", Messenger.dimension(DimensionWrapper.of(world)))));
    this.showTopNInCollection(source, tr("statistic.all"), world.blockEntities);
    this.showTopNInCollection(source, tr("statistic.ticking"), world.tickingBlockEntities);
    return 1;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld)

Example 30 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project Carpet-TIS-Addition by TISUnion.

the class RaidCommand method listRaid.

public int listRaid(ServerCommandSource source, boolean fullMode) {
    if (CarpetTISAdditionServer.minecraft_server == null) {
        return 0;
    }
    boolean hasRaid = false;
    for (ServerWorld world : CarpetTISAdditionServer.minecraft_server.getWorlds()) {
        Map<Integer, Raid> raids = ((RaidManagerAccessor) world.getRaidManager()).getRaids();
        if (raids.isEmpty()) {
            continue;
        }
        List<BaseText> result = new ArrayList<>();
        result.add(Messenger.c(Messenger.dimension(DimensionWrapper.of(world)), "w  ", tr("raid_count", raids.size())));
        hasRaid |= raids.size() > 0;
        for (Map.Entry<Integer, Raid> entry : raids.entrySet()) {
            Raid raid = entry.getValue();
            RaidAccessor raidAccessor = (RaidAccessor) raid;
            int currentWave = raidAccessor.getWavesSpawned();
            String status = raidAccessor.getStatus().getName();
            result.add(Messenger.c("g - ", Messenger.tr("event.minecraft.raid"), String.format("w  #%d", raid.getRaidId())));
            result.add(Messenger.c("g   ", tr("status"), "w : ", tr("status." + status)));
            result.add(Messenger.c("g   ", tr("center"), "w : ", Messenger.coord("w", raid.getCenter(), DimensionWrapper.of(world))));
            result.add(Messenger.c("g   ", tr("bad_omen_level"), "w : ", Messenger.s(raid.getBadOmenLevel())));
            result.add(Messenger.c("g   ", tr("waves"), "w : ", String.format("w %d/%d", raidAccessor.getWavesSpawned(), raidAccessor.getWaveCount())));
            Set<RaiderEntity> raiders = raidAccessor.getWaveToRaiders().get(currentWave);
            boolean hasRaiders = raiders != null && !raiders.isEmpty();
            result.add(Messenger.c("g   ", tr("raiders"), "w : ", hasRaiders ? Messenger.s(String.format("x%d", raiders.size())) : tr("none")));
            if (hasRaiders) {
                int counter = 0;
                List<Object> line = Lists.newArrayList();
                for (Iterator<RaiderEntity> iter = raiders.iterator(); iter.hasNext(); ) {
                    RaiderEntity raider = iter.next();
                    BaseText raiderName = Messenger.entity(raider.equals(raidAccessor.getWaveToCaptain().get(currentWave)) ? "r" : "w", raider);
                    BaseText raiderMessage = Messenger.c(raiderName, "g  @ ", Messenger.coord("w", raider.getPos(), DimensionWrapper.of(raider.world)));
                    if (fullMode) {
                        result.add(Messenger.c("g   - ", raiderMessage));
                    } else {
                        BaseText x = Messenger.s(String.format("[%s] ", IdentifierUtil.id(raider.getType()).getPath().substring(0, 1).toUpperCase()));
                        x.setStyle(raiderName.getStyle().copy());
                        Messenger.hover(x, raiderMessage);
                        Messenger.click(x, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, TextUtil.tp(raider)));
                        line.add(x);
                        counter++;
                        if (counter == 10 || !iter.hasNext()) {
                            line.add(0, "w     ");
                            result.add(Messenger.c(line.toArray(new Object[0])));
                            line.clear();
                            counter = 0;
                        }
                    }
                }
            }
        }
        Messenger.tell(source, result);
    }
    if (!hasRaid) {
        Messenger.tell(source, tr("no_raid"));
    }
    return 1;
}
Also used : BaseText(net.minecraft.text.BaseText) RaidAccessor(carpettisaddition.mixins.command.raid.RaidAccessor) ClickEvent(net.minecraft.text.ClickEvent) Raid(net.minecraft.entity.raid.Raid) RaidManagerAccessor(carpettisaddition.mixins.command.raid.RaidManagerAccessor) ServerWorld(net.minecraft.server.world.ServerWorld) RaiderEntity(net.minecraft.entity.raid.RaiderEntity)

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