use of net.minecraft.client.multiplayer.ClientLevel in project MinecraftForge by MinecraftForge.
the class GravityAttributeTest method worldTick.
@SubscribeEvent
public void worldTick(TickEvent.WorldTickEvent event) {
if (!event.world.isClientSide) {
if (ticks++ > 60) {
ticks = 0;
Level w = event.world;
List<LivingEntity> list;
if (w.isClientSide) {
ClientLevel cw = (ClientLevel) w;
list = new ArrayList<>(100);
for (Entity e : cw.entitiesForRendering()) {
if (e.isAlive() && e instanceof LivingEntity)
list.add((LivingEntity) e);
}
} else {
ServerLevel sw = (ServerLevel) w;
Stream<LivingEntity> s = StreamSupport.stream(sw.getEntities().getAll().spliterator(), false).filter(Entity::isAlive).filter(e -> e instanceof LivingEntity).map(e -> (LivingEntity) e);
list = s.collect(Collectors.toList());
}
for (LivingEntity liv : list) {
AttributeInstance grav = liv.getAttribute(ForgeMod.ENTITY_GRAVITY.get());
boolean inPlains = liv.level.getBiome(liv.blockPosition()).getBiomeCategory() == BiomeCategory.PLAINS;
if (inPlains && !grav.hasModifier(REDUCED_GRAVITY)) {
logger.info("Granted low gravity to Entity: {}", liv);
grav.addTransientModifier(REDUCED_GRAVITY);
} else if (!inPlains && grav.hasModifier(REDUCED_GRAVITY)) {
logger.info("Removed low gravity from Entity: {}", liv);
grav.removeModifier(REDUCED_GRAVITY);
}
}
}
}
}
use of net.minecraft.client.multiplayer.ClientLevel in project SpongeCommon by SpongePowered.
the class SpongePacketHandler method init.
public static void init(final SpongeChannelManager registry) {
SpongePacketHandler.channel = registry.createChannel(ResourceKey.sponge("default"), PacketChannel.class);
SpongePacketHandler.channel.registerTransactional(RequestBlockTrackerDataPacket.class, TrackerDataResponsePacket.class, 0).setRequestHandler(EngineConnectionTypes.SERVER_PLAYER, (requestPacket, connection, response) -> {
final ServerPlayer player = connection.player();
if (!player.hasPermission("sponge.debug.block-tracking")) {
return;
}
final net.minecraft.server.level.ServerPlayer sender = (net.minecraft.server.level.ServerPlayer) player;
final BlockPos pos = new BlockPos(requestPacket.x, requestPacket.y, requestPacket.z);
if (!sender.level.hasChunkAt(pos)) {
return;
}
final LevelChunkBridge levelChunkBridge = (LevelChunkBridge) sender.level.getChunkAt(pos);
final Optional<UUID> owner = levelChunkBridge.bridge$getBlockCreatorUUID(pos);
final Optional<UUID> notifier = levelChunkBridge.bridge$getBlockNotifierUUID(pos);
response.success(SpongePacketHandler.createTrackerDataResponse(owner, notifier));
});
SpongePacketHandler.channel.registerTransactional(RequestEntityTrackerDataPacket.class, TrackerDataResponsePacket.class, 1).setRequestHandler(EngineConnectionTypes.SERVER_PLAYER, (requestPacket, connection, response) -> {
final ServerPlayer player = connection.player();
if (!player.hasPermission("sponge.debug.entity-tracking")) {
return;
}
final net.minecraft.server.level.ServerPlayer sender = (net.minecraft.server.level.ServerPlayer) player;
final Entity entity = sender.level.getEntity(requestPacket.entityId);
if (!(entity instanceof CreatorTrackedBridge)) {
return;
}
final CreatorTrackedBridge creatorTrackedBridge = (CreatorTrackedBridge) entity;
final Optional<UUID> owner = creatorTrackedBridge.tracker$getCreatorUUID();
final Optional<UUID> notifier = creatorTrackedBridge.tracker$getNotifierUUID();
response.success(SpongePacketHandler.createTrackerDataResponse(owner, notifier));
});
SpongePacketHandler.channel.register(ChangeViewerEnvironmentPacket.class, 3).addHandler(ClientSideConnection.class, (packet, connection) -> {
final ClientLevel world = Minecraft.getInstance().level;
if (world == null) {
return;
}
final DimensionType dimensionType = SpongeCommon.server().registryAccess().dimensionTypes().get(packet.dimensionLogic);
((LevelBridge) world).bridge$adjustDimensionLogic(dimensionType);
});
}
Aggregations