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;
}
}
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();
}
}
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()));
}
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);
}
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);
}
}
Aggregations