use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundSelectedTitlePacketHandler method handleMessage.
@Override
public void handleMessage(final ServerboundSelectedTitlePacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
final Player player = ((PlayerConnection) connection).getPlayer();
this.titleManager.setSelectedTitleFor(player, message.titleId);
}
}
use of net.minecraft.server.MinecraftServer in project MorePlanets by SteveKunG.
the class WorldGenGravityHarvester method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
Random random = world.getChunk(pos).getRandomWithSeed(987234911L);
MinecraftServer server = world.getMinecraftServer();
Rotation[] arotation = CachedEnum.rotationValues;
Rotation rotation = arotation[random.nextInt(arotation.length)];
int i = random.nextInt(GRAVITY_HARVESTERS.length);
TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
Template template = manager.getTemplate(server, GRAVITY_HARVESTERS[i]);
ChunkPos chunkpos = new ChunkPos(pos);
StructureBoundingBox box = new StructureBoundingBox(chunkpos.getXStart(), 0, chunkpos.getZStart(), chunkpos.getXEnd(), 256, chunkpos.getZEnd());
PlacementSettings settings = new PlacementSettings().setRotation(rotation).setBoundingBox(box).setRandom(random);
BlockPos blockpos = template.transformedSize(rotation);
int x = random.nextInt(16 - blockpos.getX());
int z = random.nextInt(16 - blockpos.getZ());
BlockPos blockpos1 = template.getZeroPositionWithTransform(pos.add(x, 0, z), Mirror.NONE, rotation);
Map<BlockPos, String> dataList = template.getDataBlocks(blockpos1, settings);
for (Map.Entry<BlockPos, String> entry : dataList.entrySet()) {
if ("extractor".equals(entry.getValue())) {
BlockPos pos2 = entry.getKey();
world.setBlockState(pos2, MPBlocks.GRAVITY_CREEP_EXTRACTOR.getDefaultState(), 3);
TileEntity tile = world.getTileEntity(pos2);
if (tile instanceof TileEntityGravityExtractor) {
((TileEntityGravityExtractor) tile).setLifeTime(6000 + rand.nextInt(6000));
}
} else if ("extractor_with_vines".equals(entry.getValue())) {
BlockPos pos2 = entry.getKey();
world.setBlockState(pos2, MPBlocks.GRAVITY_CREEP_EXTRACTOR.getDefaultState(), 3);
world.setBlockState(pos2.down(), MPBlocks.GRAVITY_CREEP_VINES.getDefaultState(), 3);
TileEntity tile = world.getTileEntity(pos2);
if (tile instanceof TileEntityGravityExtractor) {
((TileEntityGravityExtractor) tile).setLifeTime(6000 + rand.nextInt(6000));
}
}
}
template.addBlocksToWorld(world, blockpos1, settings, 20);
return true;
}
use of net.minecraft.server.MinecraftServer in project MorePlanets by SteveKunG.
the class StructureNibiruIglooPieces method addComponentParts.
@Override
public boolean addComponentParts(World world, Random rand, StructureBoundingBox structureBoundingBox) {
if (!this.offsetToAverageGroundLevel(world, structureBoundingBox, -1)) {
return false;
} else {
StructureBoundingBox box = this.getBoundingBox();
BlockPos pos = new BlockPos(box.minX, box.minY, box.minZ);
Rotation[] arotation = CachedEnum.rotationValues;
MinecraftServer server = world.getMinecraftServer();
TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
PlacementSettings settings = new PlacementSettings().setRotation(arotation[rand.nextInt(arotation.length)]).setReplacedBlock(Blocks.STRUCTURE_VOID).setBoundingBox(box);
Template template = manager.getTemplate(server, IGLOO_TOP_ID);
template.addBlocksToWorldChunk(world, pos, settings);
if (rand.nextDouble() < 0.5D) {
Template template1 = manager.getTemplate(server, IGLOO_MIDDLE_ID);
Template template2 = manager.getTemplate(server, IGLOO_BOTTOM_ID);
int i = rand.nextInt(8) + 4;
for (int j = 0; j < i; ++j) {
BlockPos blockpos1 = template.calculateConnectedPos(settings, new BlockPos(3, -1 - j * 3, 5), settings, new BlockPos(1, 2, 1));
template1.addBlocksToWorldChunk(world, pos.add(blockpos1), settings);
}
BlockPos blockpos4 = pos.add(template.calculateConnectedPos(settings, new BlockPos(3, -1 - i * 3, 5), settings, new BlockPos(3, 5, 7)));
template2.addBlocksToWorldChunk(world, blockpos4, settings);
Map<BlockPos, String> map = template2.getDataBlocks(blockpos4, settings);
for (Entry<BlockPos, String> entry : map.entrySet()) {
if ("chest".equals(entry.getValue())) {
BlockPos blockpos2 = entry.getKey();
world.setBlockState(blockpos2, Blocks.AIR.getDefaultState(), 3);
TileEntity tile = world.getTileEntity(blockpos2.down());
if (tile instanceof TileEntityChestMP) {
((TileEntityChestMP) tile).setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
}
}
}
} else {
BlockPos blockpos3 = Template.transformedBlockPos(settings, new BlockPos(3, 0, 5));
world.setBlockState(pos.add(blockpos3), MPBlocks.INFECTED_SNOW.getDefaultState(), 3);
}
return true;
}
}
use of net.minecraft.server.MinecraftServer in project SpongeCommon by SpongePowered.
the class PrimaryLevelDataMixin method impl$updateWorldForDifficultyChange.
void impl$updateWorldForDifficultyChange(final ServerLevel world, final boolean isLocked) {
if (world == null) {
return;
}
final MinecraftServer server = world.getServer();
final Difficulty difficulty = ((LevelData) this).getDifficulty();
if (difficulty == Difficulty.HARD) {
world.setSpawnSettings(true, true);
} else if (server.isSingleplayer()) {
world.setSpawnSettings(difficulty != Difficulty.PEACEFUL, true);
} else {
world.setSpawnSettings(((MinecraftServerAccessor) server).invoker$isSpawningMonsters(), server.isSpawningAnimals());
}
world.players().forEach(player -> player.connection.send(new ClientboundChangeDifficultyPacket(difficulty, isLocked)));
}
use of net.minecraft.server.MinecraftServer in project SpongeCommon by SpongePowered.
the class PacketPhase method setupPacketToStateMapping.
private void setupPacketToStateMapping() {
this.packetTranslationMap.put(ServerboundKeepAlivePacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundChatPacket.class, packet -> PacketPhase.General.CHAT_COMMAND);
this.packetTranslationMap.put(ServerboundInteractPacket.class, packet -> {
final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
final ServerboundInteractPacket.Action action = useEntityPacket.getAction();
if (action == ServerboundInteractPacket.Action.INTERACT) {
return PacketPhase.General.INTERACT_ENTITY;
} else if (action == ServerboundInteractPacket.Action.ATTACK) {
return PacketPhase.General.ATTACK_ENTITY;
} else if (action == ServerboundInteractPacket.Action.INTERACT_AT) {
return PacketPhase.General.INTERACT_AT_ENTITY;
} else {
return PacketPhase.General.INVALID;
}
});
this.packetTranslationMap.put(ServerboundMovePlayerPacket.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.Pos.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.Rot.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.PosRot.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundPlayerActionPacket.class, packet -> {
final ServerboundPlayerActionPacket playerDigging = (ServerboundPlayerActionPacket) packet;
final ServerboundPlayerActionPacket.Action action = playerDigging.getAction();
final IPhaseState<? extends PacketContext<?>> state = PacketPhase.INTERACTION_ACTION_MAPPINGS.get(action);
return state == null ? PacketPhase.General.UNKNOWN : state;
});
this.packetTranslationMap.put(ServerboundUseItemOnPacket.class, packet -> {
// Note that CPacketPlayerTryUseItem is swapped with CPacketPlayerBlockPlacement
final ServerboundUseItemOnPacket blockPlace = (ServerboundUseItemOnPacket) packet;
final BlockPos blockPos = blockPlace.getHitResult().getBlockPos();
final Direction front = blockPlace.getHitResult().getDirection();
final MinecraftServer server = SpongeCommon.server();
if (blockPos.getY() < server.getMaxBuildHeight() - 1 || front != Direction.UP && blockPos.getY() < server.getMaxBuildHeight()) {
return PacketPhase.General.PLACE_BLOCK;
}
return PacketPhase.General.INVALID;
});
this.packetTranslationMap.put(ServerboundUseItemPacket.class, packet -> PacketPhase.General.USE_ITEM);
this.packetTranslationMap.put(ServerboundSetCarriedItemPacket.class, packet -> PacketPhase.Inventory.SET_CARRIED_ITEM);
this.packetTranslationMap.put(ServerboundSwingPacket.class, packet -> PacketPhase.General.ANIMATION);
this.packetTranslationMap.put(ServerboundPlayerCommandPacket.class, packet -> {
final ServerboundPlayerCommandPacket playerAction = (ServerboundPlayerCommandPacket) packet;
final ServerboundPlayerCommandPacket.Action action = playerAction.getAction();
return PacketPhase.PLAYER_ACTION_MAPPINGS.get(action);
});
this.packetTranslationMap.put(ServerboundPlayerInputPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
this.packetTranslationMap.put(ServerboundContainerClosePacket.class, packet -> PacketPhase.General.CLOSE_WINDOW);
this.packetTranslationMap.put(ServerboundContainerClickPacket.class, packet -> PacketPhase.fromWindowPacket((ServerboundContainerClickPacket) packet));
this.packetTranslationMap.put(ServerboundContainerAckPacket.class, packet -> PacketPhase.General.UNKNOWN);
this.packetTranslationMap.put(ServerboundSetCreativeModeSlotPacket.class, packet -> PacketPhase.General.CREATIVE_INVENTORY);
this.packetTranslationMap.put(ServerboundContainerButtonClickPacket.class, packet -> PacketPhase.Inventory.ENCHANT_ITEM);
this.packetTranslationMap.put(ServerboundSignUpdatePacket.class, packet -> PacketPhase.General.UPDATE_SIGN);
this.packetTranslationMap.put(ServerboundPlayerAbilitiesPacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundCommandSuggestionPacket.class, packet -> PacketPhase.General.TAB_COMPLETE);
this.packetTranslationMap.put(ServerboundClientCommandPacket.class, packet -> {
final ServerboundClientCommandPacket clientStatus = (ServerboundClientCommandPacket) packet;
final ServerboundClientCommandPacket.Action status = clientStatus.getAction();
if (status == ServerboundClientCommandPacket.Action.PERFORM_RESPAWN) {
return PacketPhase.General.REQUEST_RESPAWN;
}
return PacketPhase.General.IGNORED;
});
this.packetTranslationMap.put(ServerboundCustomPayloadPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
this.packetTranslationMap.put(ServerboundTeleportToEntityPacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundResourcePackPacket.class, packet -> PacketPhase.General.RESOURCE_PACK);
this.packetTranslationMap.put(ServerboundPlaceRecipePacket.class, packet -> PacketPhase.Inventory.PLACE_RECIPE);
}
Aggregations