Java Code Examples for net.minecraft.world.WorldServer

The following are top voted examples for showing how to use net.minecraft.world.WorldServer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: BaseClient   File: EntityThrowable.java   Source Code and License 6 votes vote down vote up
public EntityLivingBase getThrower()
{
    if (this.thrower == null && this.throwerName != null && this.throwerName.length() > 0)
    {
        this.thrower = this.worldObj.getPlayerEntityByName(this.throwerName);

        if (this.thrower == null && this.worldObj instanceof WorldServer)
        {
            try
            {
                Entity entity = ((WorldServer)this.worldObj).getEntityFromUuid(UUID.fromString(this.throwerName));

                if (entity instanceof EntityLivingBase)
                {
                    this.thrower = (EntityLivingBase)entity;
                }
            }
            catch (Throwable var2)
            {
                this.thrower = null;
            }
        }
    }

    return this.thrower;
}
 
Example 2
Project: HardVox   File: SelectionListener.java   Source Code and License 6 votes vote down vote up
private void dueProcess(PlayerInteractEvent event, BiFunction<RegionSelector<?, ?>, Vector3i, String> selector) {
    if (event.getWorld().isRemote) {
        // don't process on client
        // perhaps we can cancel on client if we do config sync
        return;
    }

    if (event.getItemStack().getItem() == HardVoxConfig.getSelectionWand()) {
        // cancel event, fire selection
        event.setCanceled(true);

        WorldServer ws = (WorldServer) event.getWorld();
        SessionManager.getInstance()
                .getSession(ws.getMinecraftServer(), event.getEntityPlayer())
                .performRegionCommand(sel -> selector.apply(sel, VecBridge.toFlow(event.getPos())));
        // send an update to the player so the block re-appears?
        ws.getPlayerChunkMap().markBlockForUpdate(event.getPos());
    }
}
 
Example 3
Project: BaseClient   File: MinecraftServer.java   Source Code and License 6 votes vote down vote up
public Entity getEntityFromUuid(UUID uuid)
{
    for (WorldServer worldserver : this.worldServers)
    {
        if (worldserver != null)
        {
            Entity entity = worldserver.getEntityFromUuid(uuid);

            if (entity != null)
            {
                return entity;
            }
        }
    }

    return null;
}
 
Example 4
Project: Uranium   File: CraftPlayer.java   Source Code and License 6 votes vote down vote up
public void showPlayer(Player player) {
    Validate.notNull(player, "shown player cannot be null");
    if (getHandle().playerNetServerHandler == null) return;
    if (equals(player)) return;
    if (!hiddenPlayers.contains(player.getUniqueId())) return;
    hiddenPlayers.remove(player.getUniqueId());

    EntityTracker tracker = ((WorldServer) entity.worldObj).theEntityTracker;
    EntityPlayerMP other = ((CraftPlayer) player).getHandle();
    EntityTrackerEntry entry = (EntityTrackerEntry) tracker.trackedEntityIDs.lookup(other.getEntityId());
    if (entry != null) {
        entry.removePlayerFromTracker(getHandle());
    }

    getHandle().playerNetServerHandler.sendPacket(new S38PacketPlayerListItem(player.getPlayerListName(), false, 9999));
}
 
Example 5
Project: Backmemed   File: TileEntityStructure.java   Source Code and License 6 votes vote down vote up
public boolean save(boolean p_189712_1_)
{
    if (this.mode == TileEntityStructure.Mode.SAVE && !this.world.isRemote && !StringUtils.isNullOrEmpty(this.name))
    {
        BlockPos blockpos = this.getPos().add(this.position);
        WorldServer worldserver = (WorldServer)this.world;
        MinecraftServer minecraftserver = this.world.getMinecraftServer();
        TemplateManager templatemanager = worldserver.getStructureTemplateManager();
        Template template = templatemanager.getTemplate(minecraftserver, new ResourceLocation(this.name));
        template.takeBlocksFromWorld(this.world, blockpos, this.size, !this.ignoreEntities, Blocks.STRUCTURE_VOID);
        template.setAuthor(this.author);
        return !p_189712_1_ || templatemanager.writeTemplate(minecraftserver, new ResourceLocation(this.name));
    }
    else
    {
        return false;
    }
}
 
Example 6
Project: PurificatiMagicae   File: SifStorageServer.java   Source Code and License 6 votes vote down vote up
@Override
public void set(GlobalChunkPos pos, float value)
{
    if (loaded.containsKey(pos))
        if (loaded.get(pos).equals(value))
            return;
    loaded.put(pos, value);
    WorldServer wrld = DimensionManager.getWorld(pos.getDimension());
    wrld.getChunkFromChunkCoords(pos.getX(), pos.getZ()).markDirty();
    PlayerChunkMapEntry map = wrld.getPlayerChunkMap().getEntry(pos.getX(), pos.getZ());
    if (map != null)
    {
        for (EntityPlayerMP p : map.players)
        {
            NetworkManager.sendTo(new CPacketSyncSif(pos, value), p);
        }
    }
}
 
Example 7
Project: Proyecto-DASI   File: ObservationFromServer.java   Source Code and License 6 votes vote down vote up
/** IMPORTANT: Call this from the onMessage method in the subclass. */
public IMessage processMessage(final ObservationRequestMessage message, final MessageContext ctx)
{
	IThreadListener mainThread = (WorldServer)ctx.getServerHandler().playerEntity.worldObj;
	mainThread.addScheduledTask(new Runnable() {
		@Override
		public void run() {
			EntityPlayerMP player = ctx.getServerHandler().playerEntity;
			JsonObject json = new JsonObject();
			buildJson(json, player, message, ctx);
			// Send this message back again now we've filled in the json stats.
			Map<String, String> returnData = new HashMap<String, String>();
			returnData.put("json", json.toString());
			message.addReturnData(returnData);
			MalmoMod.network.sendTo(new MalmoMod.MalmoMessage(MalmoMessageType.SERVER_OBSERVATIONSREADY, message.id, returnData), player);
		}
	});
	return null; // no response in this case
}
 
Example 8
Project: Infernum   File: InfernalMonumentGenerator.java   Source Code and License 6 votes vote down vote up
@Override
public boolean generate(World worldIn, Random rand, BlockPos posIn) {
	
	if (!(worldIn instanceof WorldServer)) {
		return false;
	}

	WorldServer world = (WorldServer) worldIn;

	if (world.provider.getDimension() != -1) {
		return false;
	}

	if (world.rand.nextInt(rarity) == 0) {
		int y = findPosY(world, posIn);
		if (y > 0) {
			BlockPos pos = new BlockPos(posIn.getX(), findPosY(world, posIn), posIn.getZ());
			generateMonument(world, pos, rand);
		}
		return true;
	}

	return false;

}
 
Example 9
Project: Infernum   File: SpellSoulDrain.java   Source Code and License 6 votes vote down vote up
@Override
public void onCastTick(World world, EntityPlayer player, ItemStack stack) {
	if (!world.isRemote) {
		BlockPos centerPos = player.getPosition();
		AxisAlignedBB area = new AxisAlignedBB(centerPos).expandXyz(3F);
		for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(player, area)) {
			if (entity instanceof EntityLivingBase) {
				WorldServer worldServer = (WorldServer) world;
				if (player.getItemInUseCount() % 10 == 0 && consumePower(player)) {
					MessageSoulDrainFX message = new MessageSoulDrainFX(entity.posX,
							entity.posY + (entity.height / 2.0F), entity.posZ, player.posX,
							player.posY + (player.height / 2.0F), player.posZ);
					PacketHandler.INSTANCE.sendToAllAround(message, new NetworkRegistry.TargetPoint(
							player.dimension, player.posX, player.posY, player.posZ, 128));
					entity.attackEntityFrom(DamageSource.magic, 1);
					world.spawnEntity(new EntityXPOrb(world, entity.posX, entity.posY + 0.5, entity.posZ, 1));
				}
			}
		}
	}
}
 
Example 10
Project: Backmemed   File: EntityShulkerBullet.java   Source Code and License 6 votes vote down vote up
protected void bulletHit(RayTraceResult result)
{
    if (result.entityHit == null)
    {
        ((WorldServer)this.world).spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.posX, this.posY, this.posZ, 2, 0.2D, 0.2D, 0.2D, 0.0D, new int[0]);
        this.playSound(SoundEvents.ENTITY_SHULKER_BULLET_HIT, 1.0F, 1.0F);
    }
    else
    {
        boolean flag = result.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.owner).setProjectile(), 4.0F);

        if (flag)
        {
            this.applyEnchantments(this.owner, result.entityHit);

            if (result.entityHit instanceof EntityLivingBase)
            {
                ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.LEVITATION, 200));
            }
        }
    }

    this.setDead();
}
 
Example 11
Project: CustomWorldGen   File: PlayerList.java   Source Code and License 6 votes vote down vote up
public void setViewDistance(int distance)
{
    this.viewDistance = distance;

    if (this.mcServer.worldServers != null)
    {
        for (WorldServer worldserver : this.mcServer.worldServers)
        {
            if (worldserver != null)
            {
                worldserver.getPlayerChunkMap().setPlayerViewRadius(distance);
                worldserver.getEntityTracker().setViewDistance(distance);
            }
        }
    }
}
 
Example 12
Project: CraftingParadiseMod   File: HandlerWorldCraft.java   Source Code and License 6 votes vote down vote up
@Override
public IMessage onMessage(final MessageWorldCraft message, final MessageContext ctx)
{
    if(ctx.side != Side.SERVER)
    {
        System.err.println("MessageWorldCraft received on wrong side:" + ctx.side);
        return null;
    }

    final EntityPlayerMP sendingPlayer = ctx.getServerHandler().player;
    if(sendingPlayer == null)
    {
        System.err.println("MessageWorldCraft received with null player.");
        return null;
    }

    final WorldServer playerWorldServer = sendingPlayer.getServerWorld();
    playerWorldServer.addScheduledTask(() -> processMessage(message, ctx, playerWorldServer));
    return null;
}
 
Example 13
Project: CustomWorldGen   File: EntityLivingBase.java   Source Code and License 6 votes vote down vote up
/**
 * Called when the entity picks up an item.
 */
public void onItemPickup(Entity entityIn, int quantity)
{
    if (!entityIn.isDead && !this.worldObj.isRemote)
    {
        EntityTracker entitytracker = ((WorldServer)this.worldObj).getEntityTracker();

        if (entityIn instanceof EntityItem)
        {
            entitytracker.sendToAllTrackingEntity(entityIn, new SPacketCollectItem(entityIn.getEntityId(), this.getEntityId()));
        }

        if (entityIn instanceof EntityArrow)
        {
            entitytracker.sendToAllTrackingEntity(entityIn, new SPacketCollectItem(entityIn.getEntityId(), this.getEntityId()));
        }

        if (entityIn instanceof EntityXPOrb)
        {
            entitytracker.sendToAllTrackingEntity(entityIn, new SPacketCollectItem(entityIn.getEntityId(), this.getEntityId()));
        }
    }
}
 
Example 14
Project: DecompiledMinecraft   File: MinecraftServer.java   Source Code and License 6 votes vote down vote up
public Entity getEntityFromUuid(UUID uuid)
{
    for (WorldServer worldserver : this.worldServers)
    {
        if (worldserver != null)
        {
            Entity entity = worldserver.getEntityFromUuid(uuid);

            if (entity != null)
            {
                return entity;
            }
        }
    }

    return null;
}
 
Example 15
Project: Backmemed   File: PlayerList.java   Source Code and License 6 votes vote down vote up
/**
 * Updates the time and weather for the given player to those of the given world
 */
public void updateTimeAndWeatherForPlayer(EntityPlayerMP playerIn, WorldServer worldIn)
{
    WorldBorder worldborder = this.mcServer.worldServers[0].getWorldBorder();
    playerIn.connection.sendPacket(new SPacketWorldBorder(worldborder, SPacketWorldBorder.Action.INITIALIZE));
    playerIn.connection.sendPacket(new SPacketTimeUpdate(worldIn.getTotalWorldTime(), worldIn.getWorldTime(), worldIn.getGameRules().getBoolean("doDaylightCycle")));
    BlockPos blockpos = worldIn.getSpawnPoint();
    playerIn.connection.sendPacket(new SPacketSpawnPosition(blockpos));

    if (worldIn.isRaining())
    {
        playerIn.connection.sendPacket(new SPacketChangeGameState(1, 0.0F));
        playerIn.connection.sendPacket(new SPacketChangeGameState(7, worldIn.getRainStrength(1.0F)));
        playerIn.connection.sendPacket(new SPacketChangeGameState(8, worldIn.getThunderStrength(1.0F)));
    }
}
 
Example 16
Project: DecompiledMinecraft   File: MinecraftServer.java   Source Code and License 6 votes vote down vote up
/**
 * par1 indicates if a log message should be output.
 */
protected void saveAllWorlds(boolean dontLog)
{
    if (!this.worldIsBeingDeleted)
    {
        for (WorldServer worldserver : this.worldServers)
        {
            if (worldserver != null)
            {
                if (!dontLog)
                {
                    logger.info("Saving chunks for level \'" + worldserver.getWorldInfo().getWorldName() + "\'/" + worldserver.provider.getDimensionName());
                }

                try
                {
                    worldserver.saveAllChunks(true, (IProgressUpdate)null);
                }
                catch (MinecraftException minecraftexception)
                {
                    logger.warn(minecraftexception.getMessage());
                }
            }
        }
    }
}
 
Example 17
Project: TheOink   File: OinkWorldGenerator.java   Source Code and License 6 votes vote down vote up
private void generateOverworldStructures(World world, Random random, int posX, int posZ) {

        if(OinkConfig.piggyActive) {
            WorldServer server = (WorldServer) world;
            TemplateManager manager = server.getStructureTemplateManager();

            Template piggy = manager.getTemplate(world.getMinecraftServer(), new ResourceLocation(TheOink.MODID, "pigstructure"));

            if ((int) (Math.random() * OinkConfig.piggyStructChance) == 0) {
                int randX = posX + (int) (Math.random() * 16);
                int randZ = posZ + (int) (Math.random() * 16);
                int groundY = getGroundFromAbove(world, randX, randZ);
                BlockPos pos = new BlockPos(randX, groundY, randZ);

                if (canSpawnHere(piggy, world, pos)) {
                    TheOink.LOGGER.info("Generating Pig at " + pos);
                    piggy.addBlocksToWorld(world, pos, new PlacementSettings());
                    handleDataBlocks(piggy, world, pos, new PlacementSettings());
                }
            }
        }
    }
 
Example 18
Project: DecompiledMinecraft   File: ServerConfigurationManager.java   Source Code and License 6 votes vote down vote up
/**
 * moves provided player from overworld to nether or vice versa
 */
public void transferPlayerToDimension(EntityPlayerMP playerIn, int dimension)
{
    int i = playerIn.dimension;
    WorldServer worldserver = this.mcServer.worldServerForDimension(playerIn.dimension);
    playerIn.dimension = dimension;
    WorldServer worldserver1 = this.mcServer.worldServerForDimension(playerIn.dimension);
    playerIn.playerNetServerHandler.sendPacket(new S07PacketRespawn(playerIn.dimension, playerIn.worldObj.getDifficulty(), playerIn.worldObj.getWorldInfo().getTerrainType(), playerIn.theItemInWorldManager.getGameType()));
    worldserver.removePlayerEntityDangerously(playerIn);
    playerIn.isDead = false;
    this.transferEntityToWorld(playerIn, i, worldserver, worldserver1);
    this.preparePlayer(playerIn, worldserver);
    playerIn.playerNetServerHandler.setPlayerLocation(playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
    playerIn.theItemInWorldManager.setWorld(worldserver1);
    this.updateTimeAndWeatherForPlayer(playerIn, worldserver1);
    this.syncPlayerInventory(playerIn);

    for (PotionEffect potioneffect : playerIn.getActivePotionEffects())
    {
        playerIn.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(playerIn.getEntityId(), potioneffect));
    }
}
 
Example 19
Project: DecompiledMinecraft   File: MinecraftServer.java   Source Code and License 6 votes vote down vote up
public Entity getEntityFromUuid(UUID uuid)
{
    for (WorldServer worldserver : this.worldServers)
    {
        if (worldserver != null)
        {
            Entity entity = worldserver.getEntityFromUuid(uuid);

            if (entity != null)
            {
                return entity;
            }
        }
    }

    return null;
}
 
Example 20
Project: Loot-Slash-Conquer   File: CustomLootTable.java   Source Code and License 5 votes vote down vote up
@Override
public void fillInventory(IInventory inventory, Random rand, LootContext context)
{
	TileEntityChest chest = (TileEntityChest) inventory;
    CustomLootContext.Builder context$builder = new CustomLootContext.Builder((WorldServer) chest.getWorld());
    context$builder.withChestPos(chest.getPos());
    CustomLootContext customContext = context$builder.build();
	
    List<ItemStack> list = this.generateLootForPools(rand, customContext);
    List<Integer> list1 = this.getEmptySlotsRandomized(inventory, rand);
    this.shuffleItems(list, list1.size(), rand);

    for (ItemStack itemstack : list)
    {
        if (list1.isEmpty())
        {
        	LootSlashConquer.LOGGER.warn("Tried to over-fill a container");
            return;
        }
        
        if (itemstack.isEmpty())
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), ItemStack.EMPTY);
        }
        else
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), itemstack);
        }
    }
}
 
Example 21
Project: BaseClient   File: MinecraftServer.java   Source Code and License 5 votes vote down vote up
/**
 * Saves all necessary data as preparation for stopping the server.
 */
public void stopServer()
{
    if (!this.worldIsBeingDeleted)
    {
        logger.info("Stopping server");

        if (this.getNetworkSystem() != null)
        {
            this.getNetworkSystem().terminateEndpoints();
        }

        if (this.serverConfigManager != null)
        {
            logger.info("Saving players");
            this.serverConfigManager.saveAllPlayerData();
            this.serverConfigManager.removeAllPlayers();
        }

        if (this.worldServers != null)
        {
            logger.info("Saving worlds");
            this.saveAllWorlds(false);

            for (int i = 0; i < this.worldServers.length; ++i)
            {
                WorldServer worldserver = this.worldServers[i];
                worldserver.flush();
            }
        }

        if (this.usageSnooper.isSnooperRunning())
        {
            this.usageSnooper.stopSnooper();
        }
    }
}
 
Example 22
Project: BaseClient   File: ServerConfigurationManager.java   Source Code and License 5 votes vote down vote up
public void preparePlayer(EntityPlayerMP playerIn, WorldServer worldIn)
{
    WorldServer worldserver = playerIn.getServerForPlayer();

    if (worldIn != null)
    {
        worldIn.getPlayerManager().removePlayer(playerIn);
    }

    worldserver.getPlayerManager().addPlayer(playerIn);
    worldserver.theChunkProviderServer.loadChunk((int)playerIn.posX >> 4, (int)playerIn.posZ >> 4);
}
 
Example 23
Project: BaseClient   File: CommandSaveOff.java   Source Code and License 5 votes vote down vote up
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    MinecraftServer minecraftserver = MinecraftServer.getServer();
    boolean flag = false;

    for (int i = 0; i < minecraftserver.worldServers.length; ++i)
    {
        if (minecraftserver.worldServers[i] != null)
        {
            WorldServer worldserver = minecraftserver.worldServers[i];

            if (!worldserver.disableLevelSaving)
            {
                worldserver.disableLevelSaving = true;
                flag = true;
            }
        }
    }

    if (flag)
    {
        notifyOperators(sender, this, "commands.save.disabled", new Object[0]);
    }
    else
    {
        throw new CommandException("commands.save-off.alreadyOff", new Object[0]);
    }
}
 
Example 24
Project: Backmemed   File: LootContext.java   Source Code and License 5 votes vote down vote up
public LootContext(float luckIn, WorldServer worldIn, LootTableManager lootTableManagerIn, @Nullable Entity lootedEntityIn, @Nullable EntityPlayer playerIn, @Nullable DamageSource damageSourceIn)
{
    this.luck = luckIn;
    this.worldObj = worldIn;
    this.lootTableManager = lootTableManagerIn;
    this.lootedEntity = lootedEntityIn;
    this.player = playerIn;
    this.damageSource = damageSourceIn;
}
 
Example 25
Project: pnc-repressurized   File: TileEntityProgrammableController.java   Source Code and License 5 votes vote down vote up
private void initializeFakePlayer() {
    String playerName = "Drone";
    fakePlayer = new DroneFakePlayer((WorldServer) getWorld(), new GameProfile(null, playerName), this);
    fakePlayer.connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer);
    fakePlayer.inventory = new InventoryPlayer(fakePlayer) {
        private ItemStack oldStack;

        @Override
        public int getSizeInventory() {
            return getDroneSlots();
        }

        @Override
        public void setInventorySlotContents(int slot, ItemStack stack) {
            super.setInventorySlotContents(slot, stack);
            if (slot == 0) {
                for (EntityEquipmentSlot ee : EntityEquipmentSlot.values()) {
                    if (!oldStack.isEmpty()) {
                        getFakePlayer().getAttributeMap().removeAttributeModifiers(oldStack.getAttributeModifiers(ee));
                    }
                    if (!stack.isEmpty()) {
                        getFakePlayer().getAttributeMap().applyAttributeModifiers(stack.getAttributeModifiers(ee));
                    }
                }
                oldStack = stack;
            }
        }
    };
}
 
Example 26
Project: BaseClient   File: ServerConfigurationManager.java   Source Code and License 5 votes vote down vote up
public void preparePlayer(EntityPlayerMP playerIn, WorldServer worldIn)
{
    WorldServer worldserver = playerIn.getServerForPlayer();

    if (worldIn != null)
    {
        worldIn.getPlayerManager().removePlayer(playerIn);
    }

    worldserver.getPlayerManager().addPlayer(playerIn);
    worldserver.theChunkProviderServer.loadChunk((int)playerIn.posX >> 4, (int)playerIn.posZ >> 4);
}
 
Example 27
Project: Genesis   File: GenesisTeleporter.java   Source Code and License 5 votes vote down vote up
public GenesisTeleporter(WorldServer world) {
    super(world);

    if (!world.customTeleporters.contains(this)) {
        world.customTeleporters.add(this);
    }
}
 
Example 28
Project: HardVox   File: OpSendChunks.java   Source Code and License 5 votes vote down vote up
@Override
public int performOperation(Region region, PositionIterator chunk, World world, Chunk c, VectorMap<BlockData> blockMap,
        MutableVectorMap<IBlockState> hitStore) {
    // send the whole chunk again
    PlayerChunkMapEntry entry = ((WorldServer) world).getPlayerChunkMap().getEntry(c.x, c.z);
    if (entry != null) {
        entry.sendPacket(new SPacketChunkData(c, SPCD_SEND_ALL));
    }
    return 1;
}
 
Example 29
Project: DecompiledMinecraft   File: EntityLivingBase.java   Source Code and License 5 votes vote down vote up
/**
 * Swings the item the player is holding.
 */
public void swingItem()
{
    if (!this.isSwingInProgress || this.swingProgressInt >= this.getArmSwingAnimationEnd() / 2 || this.swingProgressInt < 0)
    {
        this.swingProgressInt = -1;
        this.isSwingInProgress = true;

        if (this.worldObj instanceof WorldServer)
        {
            ((WorldServer)this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new S0BPacketAnimation(this, 0));
        }
    }
}
 
Example 30
Project: World-Border   File: CmdSetcorners.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(ICommandSender sender, EntityPlayerMP player, List<String> params, String worldName)
{
    if (worldName == null)
        worldName = Worlds.getWorldName(player.worldObj);
    else
    {
        WorldServer worldTest = Worlds.getWorld(worldName);
        if (worldTest == null)
            Util.chat(sender, "The world you specified (\"" + worldName + "\") could not be found on the server, but data for it will be stored anyway.");
    }

    try
    {
        double x1 = Double.parseDouble(params.get(0));
        double z1 = Double.parseDouble(params.get(1));
        double x2 = Double.parseDouble(params.get(2));
        double z2 = Double.parseDouble(params.get(3));
        Config.setBorderCorners(worldName, x1, z1, x2, z2);
    }
    catch(NumberFormatException ex)
    {
        sendErrorAndHelp(sender, "The x1, z1, x2, and z2 coordinate values must be numerical.");
        return;
    }

    if(player != null)
        Util.chat(sender, "Border has been set. " + Config.BorderDescription(worldName));
}
 
Example 31
Project: CustomWorldGen   File: CommandTime.java   Source Code and License 5 votes vote down vote up
protected void incrementAllWorldTimes(MinecraftServer server, int amount)
{
    for (int i = 0; i < server.worldServers.length; ++i)
    {
        WorldServer worldserver = server.worldServers[i];
        worldserver.setWorldTime(worldserver.getWorldTime() + (long)amount);
    }
}
 
Example 32
Project: VoidApi   File: HandlerTileData.java   Source Code and License 5 votes vote down vote up
@Override
public void handleData(NBTTagCompound data) 
{
	DimBlockPos dbp = new DimBlockPos();
	dbp.deserializeNBT(data.getCompoundTag("blockPosData"));
	NBTTagCompound tileData = data.getCompoundTag("tileData");
	if (MC.getSide() == Side.CLIENT)
	{
		VoidApi.proxy.getClientListener().addScheduledTask(() -> {
				if (VoidApi.proxy.getClientWorld().isBlockLoaded(dbp.pos) && VoidApi.proxy.getClientWorld().getTileEntity(dbp.pos) != null)
                   {
                       Optional.ofNullable(VoidApi.proxy.getClientWorld().getTileEntity(dbp.pos)).ifPresent(t -> t.deserializeNBT(tileData));
                   }

				VoidApi.proxy.getClientWorld().markBlockRangeForRenderUpdate(dbp.pos.down().north().west(), dbp.pos.up().west().south());
		});
	}
	else
	{
		// Server deserializing a tile from client data?..
		WorldServer ws = DimensionManager.getWorld(dbp.dim);
		ws.addScheduledTask(() -> {
				if (ws.isBlockLoaded(dbp.pos) && ws.getTileEntity(dbp.pos) != null)
                   {
                       Optional.ofNullable(ws.getTileEntity(dbp.pos)).ifPresent(t -> t.deserializeNBT(tileData));
                   }
		});
	}
}
 
Example 33
Project: CustomWorldGen   File: NetHandlerPlayServer.java   Source Code and License 5 votes vote down vote up
public void processRightClickBlock(CPacketPlayerTryUseItemOnBlock packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());
    WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
    EnumHand enumhand = packetIn.getHand();
    ItemStack itemstack = this.playerEntity.getHeldItem(enumhand);
    BlockPos blockpos = packetIn.getPos();
    EnumFacing enumfacing = packetIn.getDirection();
    this.playerEntity.markPlayerActive();

    if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit())
    {
        double dist = playerEntity.interactionManager.getBlockReachDistance() + 3;
        dist *= dist;
        if (this.targetPos == null && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < dist && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos))
        {
            this.playerEntity.interactionManager.processRightClickBlock(this.playerEntity, worldserver, itemstack, enumhand, blockpos, enumfacing, packetIn.getFacingX(), packetIn.getFacingY(), packetIn.getFacingZ());
        }
    }
    else
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())});
        textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
        this.playerEntity.connection.sendPacket(new SPacketChat(textcomponenttranslation));
    }

    this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos));
    this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing)));
    itemstack = this.playerEntity.getHeldItem(enumhand);

    if (itemstack != null && itemstack.stackSize == 0)
    {
        this.playerEntity.setHeldItem(enumhand, (ItemStack)null);
        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.playerEntity, itemstack, enumhand);
    }
}
 
Example 34
Project: harshencastle   File: HarshenSoulOre.java   Source Code and License 5 votes vote down vote up
@Override
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
	if(world != null && pos != null)
	if (world instanceof WorldServer)
		((WorldServer)world).spawnParticle(EnumParticleTypes.CLOUD, false, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 4,  0.7, 0.8, 0.6, 0, new int[EnumParticleTypes.CLOUD.getArgumentCount()]);
	return super.addHitEffects(state, worldObj, target, manager);
}
 
Example 35
Project: Backmemed   File: NetHandlerPlayServer.java   Source Code and License 5 votes vote down vote up
public void processRightClickBlock(CPacketPlayerTryUseItemOnBlock packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());
    WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
    EnumHand enumhand = packetIn.getHand();
    ItemStack itemstack = this.playerEntity.getHeldItem(enumhand);
    BlockPos blockpos = packetIn.getPos();
    EnumFacing enumfacing = packetIn.getDirection();
    this.playerEntity.markPlayerActive();

    if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit())
    {
        if (this.targetPos == null && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < 64.0D && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos))
        {
            this.playerEntity.interactionManager.processRightClickBlock(this.playerEntity, worldserver, itemstack, enumhand, blockpos, enumfacing, packetIn.getFacingX(), packetIn.getFacingY(), packetIn.getFacingZ());
        }
    }
    else
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())});
        textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
        this.playerEntity.connection.sendPacket(new SPacketChat(textcomponenttranslation, (byte)2));
    }

    this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos));
    this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing)));
}
 
Example 36
Project: BaseClient   File: CommandSaveOn.java   Source Code and License 5 votes vote down vote up
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    MinecraftServer minecraftserver = MinecraftServer.getServer();
    boolean flag = false;

    for (int i = 0; i < minecraftserver.worldServers.length; ++i)
    {
        if (minecraftserver.worldServers[i] != null)
        {
            WorldServer worldserver = minecraftserver.worldServers[i];

            if (worldserver.disableLevelSaving)
            {
                worldserver.disableLevelSaving = false;
                flag = true;
            }
        }
    }

    if (flag)
    {
        notifyOperators(sender, this, "commands.save.enabled", new Object[0]);
    }
    else
    {
        throw new CommandException("commands.save-on.alreadyOn", new Object[0]);
    }
}
 
Example 37
Project: DecompiledMinecraft   File: ServerConfigurationManager.java   Source Code and License 5 votes vote down vote up
/**
 * Called when a player disconnects from the game. Writes player data to disk and removes them from the world.
 */
public void playerLoggedOut(EntityPlayerMP playerIn)
{
    playerIn.triggerAchievement(StatList.leaveGameStat);
    this.writePlayerData(playerIn);
    WorldServer worldserver = playerIn.getServerForPlayer();

    if (playerIn.ridingEntity != null)
    {
        worldserver.removePlayerEntityDangerously(playerIn.ridingEntity);
        logger.debug("removing player mount");
    }

    worldserver.removeEntity(playerIn);
    worldserver.getPlayerManager().removePlayer(playerIn);
    this.playerEntityList.remove(playerIn);
    UUID uuid = playerIn.getUniqueID();
    EntityPlayerMP entityplayermp = (EntityPlayerMP)this.uuidToPlayerMap.get(uuid);

    if (entityplayermp == playerIn)
    {
        this.uuidToPlayerMap.remove(uuid);
        this.playerStatFiles.remove(uuid);
    }

    this.sendPacketToAllPlayers(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.REMOVE_PLAYER, new EntityPlayerMP[] {playerIn}));
}
 
Example 38
Project: InControl   File: LostCitySupport.java   Source Code and License 5 votes vote down vote up
public static <T> boolean isBuilding(IEventQuery<T> query, T event) {
    World world = query.getWorld(event);
    WorldServer ws = (WorldServer) world;
    if (ws.getChunkProvider().chunkGenerator instanceof ILostChunkGenerator) {
        ILostChunkGenerator gen = (ILostChunkGenerator) ws.getChunkProvider().chunkGenerator;
        BlockPos pos = query.getPos(event);
        ILostChunkInfo chunkInfo = gen.getChunkInfo(pos.getX() >> 4, pos.getZ() >> 4);
        return chunkInfo.isCity() && chunkInfo.getBuildingType() != null;
    }
    return false;
}
 
Example 39
Project: InControl   File: CmdKillMobs.java   Source Code and License 5 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length <= 0) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Use 'all', 'passive', 'hostile' or name of the mob followed by optional dimension id"));
        InControl.logger.error("Use 'all', 'passive', 'hostile', 'entity' or name of the mob followed by optional dimension id");
        return;
    }
    int dimension = (sender instanceof EntityPlayer) ? sender.getEntityWorld().provider.getDimension() : 0;
    if (args.length > 1) {
        dimension = Integer.parseInt(args[1]);
    }
    String arg0 = args[0].toLowerCase();
    boolean all = "all".equals(arg0);
    boolean passive = "passive".equals(arg0);
    boolean hostile = "hostile".equals(arg0);
    boolean entity = "entity".equals(arg0);

    WorldServer worldServer = server.worldServerForDimension(dimension);
    List<Entity> entities = worldServer.getEntities(Entity.class, input -> {
        if (all) {
            return !(input instanceof EntityPlayer);
        } else if (passive) {
            return input instanceof IAnimals && !(input instanceof IMob);
        } else if (hostile) {
            return input instanceof IMob;
        } else if (entity) {
            return !(input instanceof IAnimals) && !(input instanceof EntityPlayer);
        } else {
            String id = EntityTools.findEntityIdByClass(input.getClass());
            return arg0.equals(id);
        }
    });
    for (Entity e : entities) {
        worldServer.removeEntity(e);
    }
    ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.YELLOW + "Removed " + entities.size() + " entities!"));
}
 
Example 40
Project: Backmemed   File: EntityShulkerBullet.java   Source Code and License 5 votes vote down vote up
/**
 * Called when the entity is attacked.
 */
public boolean attackEntityFrom(DamageSource source, float amount)
{
    if (!this.world.isRemote)
    {
        this.playSound(SoundEvents.ENTITY_SHULKER_BULLET_HURT, 1.0F, 1.0F);
        ((WorldServer)this.world).spawnParticle(EnumParticleTypes.CRIT, this.posX, this.posY, this.posZ, 15, 0.2D, 0.2D, 0.2D, 0.0D, new int[0]);
        this.setDead();
    }

    return true;
}